From db4e0f068b6fe122ba7a01a528f6854264101f6a Mon Sep 17 00:00:00 2001
From: Karl-Hermann Wieners <karl-hermann.wieners@mpimet.mpg.de>
Date: Thu, 16 Jan 2025 18:19:17 +0100
Subject: [PATCH] Config: fix whitespace handling in job namelists

---
 expconfig.py | 18 +++++++++++-------
 test.py      |  6 ++++++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/expconfig.py b/expconfig.py
index 40928aa..05a33d6 100644
--- a/expconfig.py
+++ b/expconfig.py
@@ -285,14 +285,18 @@ class ExpConfig(ConfigObj):
                             current.rename(subkey_orig, subkey)
 
             if 'namelists' in config.sections:
-                for group in config['namelists'].sections:
-                    unify_key(config['namelists'][group])
+                namelists = config['namelists']
+                for group in namelists.sections:
+                    unify_key(namelists[group])
             if 'jobs' in config.sections:
-                unify_key(config['jobs'])
-                for job in config['jobs'].sections:
-                    if 'namelists' in config['jobs'][job].sections:
-                        for group in config['namelists'].sections:
-                            unify_key(config['jobs'][job]['namelists'][group])
+                jobs = config['jobs']
+                unify_key(jobs)
+                for name in jobs.sections:
+                    job = jobs[name]
+                    if 'namelists' in job.sections:
+                        namelists = job['namelists']
+                        for group in namelists.sections:
+                            unify_key(namelists[group])
 
         # Helper functions for value definitions
 
diff --git a/test.py b/test.py
index f798d3a..8300049 100644
--- a/test.py
+++ b/test.py
@@ -644,12 +644,18 @@ class NamelistTestCase(MkexpSimpleTestCase):
             /
             &group ! 'i i i'
             /
+            &group ! '3 a'
+            /
         """, u"""
             [namelists]
               [[namelist]]
                 [[[group 1]]]
                 [[[group  2]]]
                 [[[group i  i i]]]
+        """, u"""
+                [[[namelists]]]
+                  [[[[namelist]]]]
+                    [[[[[         group               3       a\t ]]]]] 
         """)
 
     def test_namelist_case_twist(self):
-- 
GitLab