3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-07 06:33:48 +01:00

Added Scenario 5 to 'test_parse_input()' and fixed 'inpconf.py' to pass it

This commit is contained in:
Oleg E. Peil 2015-02-16 12:25:10 +01:00 committed by Michel Ferrero
parent 74a1ad280d
commit a58ec59c9c
2 changed files with 35 additions and 6 deletions

View File

@ -377,9 +377,10 @@ class ConfigParameters:
return ind, shell
raise KeyError
sh_inds = []
sh_all_inds = []
for group in self.groups:
gr_shells = group['shells']
sh_inds = []
for user_ind in gr_shells:
try:
ind, shell = find_shell_by_user_index(user_ind)
@ -387,8 +388,9 @@ class ConfigParameters:
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
# remove them and issue a warning
# If [Shell] section contains (potentially conflicting) group parameters
# remove them and issue a warning.
#
# First, required group parameters
for par in self.gr_required.keys():
try:
@ -411,7 +413,11 @@ class ConfigParameters:
except KeyError:
continue
sh_refs_used = list(set(sh_inds))
sh_all_inds += sh_inds
# Replace user shell indices with internal ones
group['shells'] = sh_inds
sh_refs_used = list(set(sh_all_inds))
sh_refs_used.sort()
# Check that all shells are referenced in the groups
@ -432,8 +438,7 @@ class ConfigParameters:
################################################################################
#
# Main parser
# parse_logical()
# Main parser function
#
################################################################################
def parse_input(self):

View File

@ -298,6 +298,8 @@ class TestSpecialParsers(unittest.TestCase):
**raise** Exception
- **if** not all defined shells are referenced in the groups
**raise** Exception
- **if** all sections are parsed error-free check that the output
is correct
"""
# Scenario 1
conf_pars = ConfigParameters('test6.cfg')
@ -323,6 +325,28 @@ class TestSpecialParsers(unittest.TestCase):
with self.assertRaisesRegexp(AssertionError, err_mess):
conf_pars.parse_input()
# Scenario 5
conf_pars = ConfigParameters('test7.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__()
expected = r"""Shells:
[{'ion_list': array([4, 5, 6, 7]), 'user_index': 1, 'lshell': 2}, {'tmatrix': array([[ 0., 1., 0.],
[ 1., 0., 0.],
[ 0., 0., 1.]]), 'ion_list': array([0, 1, 2, 3]), 'user_index': 2, 'lshell': 1}, {'ion_list': array([0, 1, 2, 3]), 'user_index': 3, 'lshell': 3}]
Groups:
[{'index': 1, 'shells': [0, 1], 'emin': -7.6, 'emax': 3.0}, {'index': 2, 'shells': [2], 'emin': -1.6, 'emax': 2.0}]"""
self.assertEqual(res, expected)