3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-13 09:33:53 +01:00
dft_tools/python/vasp/test/_inpconf/test_parameter_set.py
Oleg E. Peil c8badb39ff Fixed 'inpconf' tests
Originally, the tests worked only when run from their respective
directory. If one tries to run them from another directory (which happens
when test discovery is used) the tests were not able to find the input files.
Now, a dummy module 'rpath' is added to all tests whose sole role is
to obtain the current path.
2015-10-16 11:16:48 +02:00

53 lines
1.6 KiB
Python

r"""
Tests of 'parse_parameter_set()' defined in ConfigParameters class
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
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(_rpath + '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)