From 90c93c4693ff8b668e20a057bdc6629c2bbce651 Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Thu, 19 Feb 2015 15:04:43 +0100 Subject: [PATCH] Fixed a bug in 'inpconf.py', added a corresponding test --- python/converters/vasp/python/inpconf.py | 5 ++-- .../vasp/test/inpconf/example_nogroup.cfg | 7 ++++++ .../vasp/test/inpconf/test_input.py | 23 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 python/converters/vasp/test/inpconf/example_nogroup.cfg diff --git a/python/converters/vasp/python/inpconf.py b/python/converters/vasp/python/inpconf.py index 7713d18b..b0680048 100644 --- a/python/converters/vasp/python/inpconf.py +++ b/python/converters/vasp/python/inpconf.py @@ -342,6 +342,7 @@ class ConfigParameters: # Otherwise create a single group taking group information from [Shell] section self.groups.append({}) + self.groups[0]['index'] = '1' # Check that the single '[Shell]' section contains enough information # (required group parameters except 'shells') # and move it to the `groups` dictionary @@ -362,12 +363,12 @@ class ConfigParameters: for par in self.gr_optional.keys(): try: key = self.gr_optional[par][0] - value = self.shells[ind].pop(key) + value = self.shells[0].pop(key) self.groups[0][key] = value except KeyError: continue # Add the index of the single shell into the group - self.groups.update({'shells': 0}) + self.groups[0].update({'shells': [1]}) # # Consistency checks diff --git a/python/converters/vasp/test/inpconf/example_nogroup.cfg b/python/converters/vasp/test/inpconf/example_nogroup.cfg new file mode 100644 index 00000000..fa4905c5 --- /dev/null +++ b/python/converters/vasp/test/inpconf/example_nogroup.cfg @@ -0,0 +1,7 @@ +[Shell 1] +LSHELL = 2 +IONS = 5..8 +EMIN = -7.6 +EMAX = 3.0 + + diff --git a/python/converters/vasp/test/inpconf/test_input.py b/python/converters/vasp/test/inpconf/test_input.py index 46b5507f..59de1523 100644 --- a/python/converters/vasp/test/inpconf/test_input.py +++ b/python/converters/vasp/test/inpconf/test_input.py @@ -28,6 +28,7 @@ class TestParseInput(arraytest.ArrayTestCase): **raise** Exception - **if** all sections are parsed error-free check that the output is correct + - correct example with a single shell and no explicit groups """ # Scenario 1 def test_no_group(self): @@ -81,5 +82,27 @@ Groups: self.assertEqual(res, expected) +# Scenario 6 + def test_example_no_groups(self): + conf_pars = ConfigParameters('example_nogroup.cfg') + conf_pars.parse_input() +# with open('parse_input.output.test', 'wt') as f: +# f.write("Shells:\n") +# f.write(conf_pars.shells.__repr__() + '\n\n') +# f.write("Groups:\n") +# f.write(conf_pars.groups.__repr__() + '\n') + res = "Shells:\n" + res += conf_pars.shells.__repr__() + '\n\n' + res += "Groups:\n" + res += conf_pars.groups.__repr__() + print res + + expected = r"""Shells: +[{'ion_list': array([4, 5, 6, 7]), 'user_index': 1, 'lshell': 2}] + +Groups: +[{'index': '1', 'emin': -7.6, 'shells': [0], 'emax': 3.0}]""" + + self.assertEqual(res, expected)