mirror of
https://github.com/triqs/dft_tools
synced 2024-12-22 04:13:47 +01:00
Added Scenario 5 to 'test_parse_input()' and fixed 'inpconf.py' to pass it
This commit is contained in:
parent
74a1ad280d
commit
a58ec59c9c
@ -377,9 +377,10 @@ class ConfigParameters:
|
|||||||
return ind, shell
|
return ind, shell
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
|
||||||
sh_inds = []
|
sh_all_inds = []
|
||||||
for group in self.groups:
|
for group in self.groups:
|
||||||
gr_shells = group['shells']
|
gr_shells = group['shells']
|
||||||
|
sh_inds = []
|
||||||
for user_ind in gr_shells:
|
for user_ind in gr_shells:
|
||||||
try:
|
try:
|
||||||
ind, shell = find_shell_by_user_index(user_ind)
|
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']))
|
raise Exception("Shell %i referenced in group '%s' does not exist"%(user_ind, group['index']))
|
||||||
sh_inds.append(ind)
|
sh_inds.append(ind)
|
||||||
|
|
||||||
# If [Shell] section contains (potentiall conflicting) group parameters
|
# If [Shell] section contains (potentially conflicting) group parameters
|
||||||
# remove them and issue a warning
|
# remove them and issue a warning.
|
||||||
|
#
|
||||||
# First, required group parameters
|
# First, required group parameters
|
||||||
for par in self.gr_required.keys():
|
for par in self.gr_required.keys():
|
||||||
try:
|
try:
|
||||||
@ -411,7 +413,11 @@ class ConfigParameters:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
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()
|
sh_refs_used.sort()
|
||||||
|
|
||||||
# Check that all shells are referenced in the groups
|
# Check that all shells are referenced in the groups
|
||||||
@ -432,8 +438,7 @@ class ConfigParameters:
|
|||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Main parser
|
# Main parser function
|
||||||
# parse_logical()
|
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
def parse_input(self):
|
def parse_input(self):
|
||||||
|
@ -298,6 +298,8 @@ class TestSpecialParsers(unittest.TestCase):
|
|||||||
**raise** Exception
|
**raise** Exception
|
||||||
- **if** not all defined shells are referenced in the groups
|
- **if** not all defined shells are referenced in the groups
|
||||||
**raise** Exception
|
**raise** Exception
|
||||||
|
- **if** all sections are parsed error-free check that the output
|
||||||
|
is correct
|
||||||
"""
|
"""
|
||||||
# Scenario 1
|
# Scenario 1
|
||||||
conf_pars = ConfigParameters('test6.cfg')
|
conf_pars = ConfigParameters('test6.cfg')
|
||||||
@ -323,6 +325,28 @@ class TestSpecialParsers(unittest.TestCase):
|
|||||||
with self.assertRaisesRegexp(AssertionError, err_mess):
|
with self.assertRaisesRegexp(AssertionError, err_mess):
|
||||||
conf_pars.parse_input()
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user