From b01ad0b136186ed5a890c2acc0820c17b070f902 Mon Sep 17 00:00:00 2001 From: Jared Lewis Date: Tue, 6 Mar 2018 19:02:06 +1300 Subject: [PATCH] Fixed failing tests --- tests/conf/test_parse_namelist.py | 5 +++-- wrfconf/conf/parse_namelist.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/conf/test_parse_namelist.py b/tests/conf/test_parse_namelist.py index 4b58eab..6bb7104 100644 --- a/tests/conf/test_parse_namelist.py +++ b/tests/conf/test_parse_namelist.py @@ -61,12 +61,13 @@ def test_advanced(self): auxinput11_end_h = 6 ; end of observation time in hours""") self.assertEqual(get_next_item(lines), """output_diagnostics = 1 ; adds 36 surface diagnostic arrays (max/min/mean/std)""") + class TestConfigItem(TestCase): def test_basic_parse(self): i = ConfigItem(' time_step_fract_num = 0, ; numerator for fractional time step\n') self.assertFalse(i.is_section) self.assertEqual(i.name, 'time_step_fract_num') - self.assertEqual(i.default, '0,') + self.assertEqual(i.default, '0') self.assertEqual(i.description, 'numerator for fractional time step') def test_multiline(self): @@ -74,5 +75,5 @@ def test_multiline(self): self.assertFalse(i.is_section) self.assertEqual(i.name, 'e_vert') self.assertTrue(i.is_multi_dim) - self.assertEqual(i.default, '30,') + self.assertEqual(i.default, '30') self.assertEqual(i.description, 'end index in z (vertical) direction (staggered dimension)\nNote: this refers to full levels including surface and top\nvertical dimensions need to be the same for all nests\nNote: most variables are unstaggered (= staggered dim - 1)') \ No newline at end of file diff --git a/wrfconf/conf/parse_namelist.py b/wrfconf/conf/parse_namelist.py index 2927f08..f9521c2 100644 --- a/wrfconf/conf/parse_namelist.py +++ b/wrfconf/conf/parse_namelist.py @@ -3,7 +3,7 @@ import yaml -default_parser = re.compile('^[a-z0-9 _()\t]*?=(.+?)[;\(\|]?(.*)$', re.DOTALL) +default_parser = re.compile('^[a-z0-9 _()\t]*?=.s*?([0-9\w,<>\'\s]+)[;\(\|]?(.*)$', re.DOTALL) def is_command(l): @@ -48,7 +48,7 @@ def process(self, l): res = default_parser.search(l, ) if res: - self.default = res.group(1).strip() + self.default = res.group(1).strip().strip(',') self.description = res.group(2).strip() self.description = '\n'.join([a.strip() for a in self.description.split('\n')]) pass