3
0
mirror of https://github.com/triqs/dft_tools synced 2024-08-29 07:22:01 +02:00

* Added Scenario 2 to 'test_input()' (test8.cfg)

* Removed group parameter 'shells' from a dict of required parameters
   for a single [Shell] section
This commit is contained in:
Oleg E. Peil 2015-02-16 11:54:54 +01:00 committed by Michel Ferrero
parent 8b60a91e49
commit 8928fa3118
3 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
[Shell 1]
LSHELL = 2
IONS = 1..4

View File

@ -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__':