3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-22 04:13:47 +01:00

* Fixed tests for the modified version of 'parse_shells()'

* Removed redundant prints in 'parse_shells()'
This commit is contained in:
Oleg E. Peil 2015-02-16 11:30:31 +01:00 committed by Michel Ferrero
parent 76d0b4a6bb
commit d2fe6d50e8
2 changed files with 15 additions and 27 deletions

View File

@ -249,33 +249,24 @@ class ConfigParameters:
shell['user_index'] = ind
section = self.sh_sections[ind]
# Shell required parameters
if self.verbosity > 0:
print
print " Required shell parameters:"
print " Shell parameters:"
# Shell required parameters
parsed = self.parse_parameter_set(section, self.sh_required, exception=True)
shell.update(parsed)
# Shell optional parameters
if self.verbosity > 0:
print
print " Optional shell parameters:"
parsed = self.parse_parameter_set(section, self.sh_optional, exception=False)
shell.update(parsed)
# Group required parameters
# Must be given if no group is explicitly specified
# If in conflict with the [Group] section, the latter has a priority
if self.verbosity > 0:
print
print " Required group parameters:"
parsed = self.parse_parameter_set(section, self.gr_required, exception=False)
shell.update(parsed)
# Group optional parameters
if self.verbosity > 0:
print
print " Optional group parameters:"
parsed = self.parse_parameter_set(section, self.gr_optional, exception=False)
shell.update(parsed)
@ -311,17 +302,14 @@ class ConfigParameters:
raise ValueError("Failed to extract group index from a group name: %s"%(section))
group['index'] = gr_ind
# Group required parameters
if self.verbosity > 0:
print
print " Required group parameters:"
print " Group parameters:"
# Group required parameters
parsed = self.parse_parameter_set(section, self.gr_required, exception=True)
group.update(parsed)
# Group optional parameters
if self.verbosity > 0:
print
print " Optional group parameters:"
parsed = self.parse_parameter_set(section, self.gr_optional, exception=False)
group.update(parsed)

View File

@ -225,25 +225,25 @@ class TestSpecialParsers(unittest.TestCase):
conf_pars = ConfigParameters('test5.cfg')
conf_pars.parse_shells()
res = conf_pars.shells
expected = {1: {'lshell': 2, 'ion_list': np.array([4, 5, 6, 7])},
2: {'lshell': 1, 'ion_list': np.array([0, 1, 2, 3]),
'tmatrix': np.array([[ 0., 1., 0.], [ 1., 0., 0.], [ 0., 0., 1.]])}}
expected = [{'user_index': 1, 'lshell': 2, 'ion_list': np.array([4, 5, 6, 7])},
{'user_index': 2, 'lshell': 1, 'ion_list': np.array([0, 1, 2, 3]),
'tmatrix': np.array([[ 0., 1., 0.], [ 1., 0., 0.], [ 0., 0., 1.]])}]
# ...lousy way to test equality of two dictionaries containing numpy arrays
self.assertSetEqual(set(res.keys()), set(expected.keys()))
self.assertEqual(len(res), len(expected))
arr = res[0].pop('ion_list')
arr_exp = expected[0].pop('ion_list')
self.assertEqual(arr, arr_exp)
arr = res[1].pop('ion_list')
arr_exp = expected[1].pop('ion_list')
self.assertEqual(arr, arr_exp)
arr = res[2].pop('ion_list')
arr_exp = expected[2].pop('ion_list')
arr = res[1].pop('tmatrix')
arr_exp = expected[1].pop('tmatrix')
self.assertEqual(arr, arr_exp)
arr = res[2].pop('tmatrix')
arr_exp = expected[2].pop('tmatrix')
self.assertEqual(arr, arr_exp)
self.assertDictEqual(res, expected)
self.assertListEqual(res, expected)
################################################################################
#