mirror of
https://github.com/triqs/dft_tools
synced 2024-09-01 16:53:43 +02:00
![Oleg E. Peil](/assets/img/avatar_default.png)
A single-file test suite for 'inpconf.py' is split into several files, each containing a separate TestCase class. In addition, all test cases are derived from class ArrayTestCase (in turn derived from TestCase) which contains a numpy-array equality method.
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
r"""
|
|
Tests of 'parse_parameter_set()' defined in ConfigParameters class
|
|
"""
|
|
import arraytest
|
|
import numpy as np
|
|
from inpconf import ConfigParameters
|
|
|
|
################################################################################
|
|
#
|
|
# TestParseParameterSet
|
|
#
|
|
################################################################################
|
|
class TestParseParameterSet(arraytest.ArrayTestCase):
|
|
"""
|
|
Function:
|
|
|
|
def parse_parameter_set(self, section, param_set, excpetion=False)
|
|
|
|
Scenarios:
|
|
|
|
- **if** config-file section [Shell 1] contains 'LSHELL = 2' **and**
|
|
'lshell' and 'ions' are in `param_set` **return** a dictionary {'lshell': 2}
|
|
|
|
- **if** config-file section [Shell 1] contains 'LSHELL = 2' **and**
|
|
'lshell' and 'ions' are in `param_set` and
|
|
exception=True **raise** Exception
|
|
"""
|
|
def setUp(self):
|
|
"""
|
|
"""
|
|
# Dummy ConfigParameters object
|
|
self.cpars = ConfigParameters('test1.cfg')
|
|
|
|
# Scenario 1
|
|
def test_sh_required(self):
|
|
param_set = self.cpars.sh_required # contains 'lshell' and 'ions'
|
|
res = self.cpars.parse_parameter_set('Shell 1', param_set)
|
|
expected = {'lshell': 2}
|
|
self.assertDictEqual(res, expected)
|
|
|
|
# Scenario 2
|
|
def test_sh_required_exception(self):
|
|
section = 'Shell 1'
|
|
param_set = self.cpars.sh_required # contains 'lshell' and 'ions'
|
|
err_mess = "Required parameter" # .* in section [%s]"%(section)
|
|
with self.assertRaisesRegexp(Exception, err_mess):
|
|
self.cpars.parse_parameter_set(section, param_set, exception=True)
|
|
|