3
0
mirror of https://github.com/triqs/dft_tools synced 2024-06-02 11:25:29 +02:00

Fixed a bug in 'inpconf.py', added a corresponding test

This commit is contained in:
Oleg E. Peil 2015-02-19 15:04:43 +01:00 committed by Michel Ferrero
parent b05d176f39
commit 90c93c4693
3 changed files with 33 additions and 2 deletions

View File

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

View File

@ -0,0 +1,7 @@
[Shell 1]
LSHELL = 2
IONS = 5..8
EMIN = -7.6
EMAX = 3.0

View File

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