3
0
mirror of https://github.com/triqs/dft_tools synced 2024-06-02 11:25:29 +02:00

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.
This commit is contained in:
Oleg E. Peil 2015-10-16 11:16:48 +02:00
parent f96e4dfe9e
commit c8badb39ff
9 changed files with 45 additions and 19 deletions

View File

@ -0,0 +1,2 @@
pass

View File

@ -1 +1 @@
PYTHONPATH=../../python:../../c:$PYTHONPATH python $1
PYTHONPATH=../..:../../../../c:$PYTHONPATH python $1

View File

@ -1,6 +1,10 @@
r"""
Tests of 'parse_general()' defined in ConfigParameters class
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import arraytest
import numpy as np
from inpconf import ConfigParameters
@ -22,7 +26,7 @@ class TestParseGeneral(arraytest.ArrayTestCase):
"""
# Scenario 1
def test_example(self):
conf_pars = ConfigParameters('example.cfg')
conf_pars = ConfigParameters(_rpath + 'example.cfg')
conf_pars.parse_general()
res = conf_pars.general
expected = {'basename': 'test_base', 'efermi': 0.1}

View File

@ -1,6 +1,10 @@
r"""
Tests of 'parse_groups()' defined in ConfigParameters class
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import arraytest
import numpy as np
from inpconf import ConfigParameters
@ -24,14 +28,14 @@ class TestParseGroups(arraytest.ArrayTestCase):
"""
# Scenario 1
def test_gr_required(self):
conf_pars = ConfigParameters('parse_groups_1.cfg')
conf_pars = ConfigParameters(_rpath + 'parse_groups_1.cfg')
err_mess = "Required parameter"
with self.assertRaisesRegexp(Exception, err_mess):
conf_pars.parse_groups()
# Scenario 2
def test_example(self):
conf_pars = ConfigParameters('example.cfg')
conf_pars = ConfigParameters(_rpath + 'example.cfg')
conf_pars.parse_groups()
res = conf_pars.groups
expected = [{'index': 1, 'shells': [1, 2], 'emin': -7.6, 'emax': 3.0,

View File

@ -1,6 +1,10 @@
r"""
Tests of 'parse_input()' defined in ConfigParameters class
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import arraytest
import numpy as np
from inpconf import ConfigParameters
@ -32,35 +36,35 @@ class TestParseInput(arraytest.ArrayTestCase):
"""
# Scenario 1
def test_no_group(self):
conf_pars = ConfigParameters('input_test_1.cfg')
conf_pars = ConfigParameters(_rpath + 'input_test_1.cfg')
err_mess = "At least one group"
with self.assertRaisesRegexp(AssertionError, err_mess):
conf_pars.parse_input()
# Scenario 2
def test_gr_required(self):
conf_pars = ConfigParameters('input_test_2.cfg')
conf_pars = ConfigParameters(_rpath + 'input_test_2.cfg')
err_mess = "One \[Shell\] section is"
with self.assertRaisesRegexp(KeyError, err_mess):
conf_pars.parse_input()
# Scenario 3
def test_no_shell(self):
conf_pars = ConfigParameters('input_test_3.cfg')
conf_pars = ConfigParameters(_rpath + 'input_test_3.cfg')
err_mess = "Shell 3 referenced in"
with self.assertRaisesRegexp(Exception, err_mess):
conf_pars.parse_input()
# Scenario 4
def test_shell_outside_groups(self):
conf_pars = ConfigParameters('input_test_4.cfg')
conf_pars = ConfigParameters(_rpath + 'input_test_4.cfg')
err_mess = "Some shells are not inside"
with self.assertRaisesRegexp(AssertionError, err_mess):
conf_pars.parse_input()
# Scenario 5
def test_example(self):
conf_pars = ConfigParameters('example.cfg')
conf_pars = ConfigParameters(_rpath + 'example.cfg')
conf_pars.parse_input()
# with open('parse_input.output.test', 'wt') as f:
# f.write("Shells:\n")
@ -84,7 +88,7 @@ Groups:
# Scenario 6
def test_example_no_groups(self):
conf_pars = ConfigParameters('example_nogroup.cfg')
conf_pars = ConfigParameters(_rpath + 'example_nogroup.cfg')
conf_pars.parse_input()
# with open('parse_input.output.test', 'wt') as f:
# f.write("Shells:\n")

View File

@ -1,6 +1,10 @@
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
@ -29,7 +33,7 @@ class TestParseParameterSet(arraytest.ArrayTestCase):
"""
"""
# Dummy ConfigParameters object
self.cpars = ConfigParameters('test1.cfg')
self.cpars = ConfigParameters(_rpath + 'test1.cfg')
# Scenario 1
def test_sh_required(self):

View File

@ -1,6 +1,10 @@
r"""
Tests of 'parse_shells()' defined in ConfigParameters class
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import arraytest
import numpy as np
from inpconf import ConfigParameters
@ -29,28 +33,28 @@ class TestParseShells(arraytest.ArrayTestCase):
"""
# Scenario 1
def test_no_shell(self):
conf_pars = ConfigParameters('parse_shells_1.cfg')
conf_pars = ConfigParameters(_rpath + 'parse_shells_1.cfg')
err_mess = "No projected shells"
with self.assertRaisesRegexp(AssertionError, err_mess):
conf_pars.parse_shells()
# Scenario 2
def test_bad_indices(self):
conf_pars = ConfigParameters('parse_shells_2.cfg')
conf_pars = ConfigParameters(_rpath + 'parse_shells_2.cfg')
err_mess = "Failed to extract shell indices"
with self.assertRaisesRegexp(ValueError, err_mess):
conf_pars.parse_shells()
# Scenario 3
def test_sh_required(self):
conf_pars = ConfigParameters('parse_shells_3.cfg')
conf_pars = ConfigParameters(_rpath + 'parse_shells_3.cfg')
err_mess = "Required parameter"
with self.assertRaisesRegexp(Exception, err_mess):
conf_pars.parse_shells()
# Scenario 4
def test_two_shells(self):
conf_pars = ConfigParameters('parse_shells_4.cfg')
conf_pars = ConfigParameters(_rpath + 'parse_shells_4.cfg')
conf_pars.parse_shells()
res = conf_pars.shells
expected = [{'user_index': 1, 'lshell': 2, 'ion_list': np.array([4, 5, 6, 7])},

View File

@ -1,6 +1,10 @@
r"""
Tests of special parseres defined in ConfigParameters class
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import arraytest
import numpy as np
from inpconf import ConfigParameters
@ -26,7 +30,7 @@ class TestParseStringLogical(arraytest.ArrayTestCase):
"""
"""
# Dummy ConfigParameters object
self.cpars = ConfigParameters('test1.cfg')
self.cpars = ConfigParameters(_rpath + 'test1.cfg')
# Scenario 1
def test_true(self):
@ -66,7 +70,7 @@ class TestParseStringIonList(arraytest.ArrayTestCase):
"""
"""
# Dummy ConfigParameters object
self.cpars = ConfigParameters('test1.cfg')
self.cpars = ConfigParameters(_rpath + 'test1.cfg')
# Scenario 1
def test_simple_list(self):
@ -123,7 +127,7 @@ class TestParseStringTmatrix(arraytest.ArrayTestCase):
"""
"""
# Dummy ConfigParameters object
self.cpars = ConfigParameters('test1.cfg')
self.cpars = ConfigParameters(_rpath + 'test1.cfg')
# Scenario 1
def test_number_of_columns(self):

View File

@ -1 +1 @@
PYTHONPATH=$HOME/Codes/vasp/vasp5.3/plo_vasp/plovasp/python:$HOME/Codes/vasp/vasp5.3/plo_vasp/plovasp/c:$PYTHONPATH python test_all.py
PYTHONPATH=../:../../../c:$PYTHONPATH python test_all.py