From 8928fa3118f345d37625a80397d28822a2236c2b Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Mon, 16 Feb 2015 11:54:54 +0100 Subject: [PATCH] * Added Scenario 2 to 'test_input()' (test8.cfg) * Removed group parameter 'shells' from a dict of required parameters for a single [Shell] section --- python/converters/vasp/python/inpconf.py | 9 ++++++--- python/converters/vasp/test/inpconf/test8.cfg | 3 +++ python/converters/vasp/test/inpconf/test_inpconf.py | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 python/converters/vasp/test/inpconf/test8.cfg diff --git a/python/converters/vasp/python/inpconf.py b/python/converters/vasp/python/inpconf.py index 934a120c..e9dcb978 100644 --- a/python/converters/vasp/python/inpconf.py +++ b/python/converters/vasp/python/inpconf.py @@ -341,16 +341,19 @@ class ConfigParameters: # Otherwise create a single group taking group information from [Shell] section self.groups.append({}) # Check that the single '[Shell]' section contains enough information +# (required group parameters except 'shells') # and move it to the `groups` dictionary + sh_gr_required = dict(self.gr_required) + sh_gr_required.pop('shells') try: - for par in self.gr_required.keys(): - key = self.gr_required[par][0] + for par in sh_gr_required.keys(): + key = sh_gr_required[par][0] value = self.shells[0].pop(key) self.groups[0][key] = value except KeyError: message = "One [Shell] section is specified but no explicit [Group] section is provided." message += " In this case the [Shell] section must contain all required group information.\n" - message += " Required parameters are: %s"%(self.gr_required.keys()) + message += " Required parameters are: %s"%(sh_gr_required.keys()) raise KeyError(message) # Do the same for optional group parameters, but do not raise an exception diff --git a/python/converters/vasp/test/inpconf/test8.cfg b/python/converters/vasp/test/inpconf/test8.cfg new file mode 100644 index 00000000..3d153421 --- /dev/null +++ b/python/converters/vasp/test/inpconf/test8.cfg @@ -0,0 +1,3 @@ +[Shell 1] +LSHELL = 2 +IONS = 1..4 diff --git a/python/converters/vasp/test/inpconf/test_inpconf.py b/python/converters/vasp/test/inpconf/test_inpconf.py index ca816514..4eb7fa40 100644 --- a/python/converters/vasp/test/inpconf/test_inpconf.py +++ b/python/converters/vasp/test/inpconf/test_inpconf.py @@ -305,6 +305,13 @@ class TestSpecialParsers(unittest.TestCase): with self.assertRaisesRegexp(AssertionError, err_mess): conf_pars.parse_input() +# Scenario 2 + conf_pars = ConfigParameters('test8.cfg') + err_mess = "One \[Shell\] section is" + with self.assertRaisesRegexp(KeyError, err_mess): + conf_pars.parse_input() + + if __name__ == '__main__':