From bcc20a03993e20e946f4533d5b2fee4c48344b20 Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Mon, 16 Feb 2015 12:02:11 +0100 Subject: [PATCH] * Added Scenario 3 to 'test_parse_input()' (test9.cfg) * Fixed 'parse_input()' to pass the test --- python/converters/vasp/python/inpconf.py | 4 +-- python/converters/vasp/test/inpconf/test9.cfg | 25 +++++++++++++++++++ .../vasp/test/inpconf/test_inpconf.py | 6 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 python/converters/vasp/test/inpconf/test9.cfg diff --git a/python/converters/vasp/python/inpconf.py b/python/converters/vasp/python/inpconf.py index e9dcb978..4c91db3f 100644 --- a/python/converters/vasp/python/inpconf.py +++ b/python/converters/vasp/python/inpconf.py @@ -374,7 +374,7 @@ class ConfigParameters: def find_shell_by_user_index(uindex): for ind, shell in enumerate(self.shells): if shell['user_index'] == uindex: - return shell + return ind, shell raise KeyError sh_inds = [] @@ -384,7 +384,7 @@ class ConfigParameters: try: ind, shell = find_shell_by_user_index(user_ind) except KeyError: - raise Exception("Shell %i reference in group '%s' does not exist"%(user_ind, group['index'])) + raise Exception("Shell %i referenced in group '%s' does not exist"%(user_ind, group['index'])) sh_inds.append(ind) # If [Shell] section contains (potentiall conflicting) group parameters diff --git a/python/converters/vasp/test/inpconf/test9.cfg b/python/converters/vasp/test/inpconf/test9.cfg new file mode 100644 index 00000000..d2883160 --- /dev/null +++ b/python/converters/vasp/test/inpconf/test9.cfg @@ -0,0 +1,25 @@ +[General] + +[Group 1] +SHELLS = 1 2 +EMIN = -7.6 +EMAX = 3.0 + +[Group 2] +SHELLS = 3 +EMIN = -1.6 +EMAX = 2.0 + +[Shell 1] +LSHELL = 2 +IONS = 5..8 + +[Shell 2] +LSHELL = 1 +IONS = 1..4 + +RTRANSFORM = 0.0 1.0 0.0 + 1.0 0.0 0.0 + 0.0 0.0 1.0 + + diff --git a/python/converters/vasp/test/inpconf/test_inpconf.py b/python/converters/vasp/test/inpconf/test_inpconf.py index 4eb7fa40..1e8dcfd6 100644 --- a/python/converters/vasp/test/inpconf/test_inpconf.py +++ b/python/converters/vasp/test/inpconf/test_inpconf.py @@ -311,6 +311,12 @@ class TestSpecialParsers(unittest.TestCase): with self.assertRaisesRegexp(KeyError, err_mess): conf_pars.parse_input() +# Scenario 3 + conf_pars = ConfigParameters('test9.cfg') + err_mess = "Shell 3 referenced in" + with self.assertRaisesRegexp(Exception, err_mess): + conf_pars.parse_input() +