mirror of
https://github.com/triqs/dft_tools
synced 2024-11-07 06:33:48 +01:00
db16a8438d
The names of the test suites have been prefixed with an underscore to avoid name conflicts with corresponding modules. Also an attempt to make a scan of all tests has been made by creating a 'test_all.py' script that is supposed to discover all test cases and run them. Unfortunately, this does not work as expected because many tests use input files assumed to be found in the current directory, which is not true if the tests are run from a different (parent) directory. This can be fixed by either forcing the change of directory (but it seems that 'unittest' does not have this functionality) or prepending input file names with the current module directory.
28 lines
732 B
Python
28 lines
732 B
Python
r"""
|
|
Module defining a custom TestCase with extra functionality.
|
|
"""
|
|
|
|
import unittest
|
|
import numpy as np
|
|
|
|
class ArrayTestCase(unittest.TestCase):
|
|
"""
|
|
Custom TestCase class supporting array equality.
|
|
"""
|
|
def __init__(self, *args, **kwargs):
|
|
"""
|
|
Initializes a custom equality function for comparing numpy arrays.
|
|
"""
|
|
super(ArrayTestCase, self).__init__(*args, **kwargs)
|
|
self.addTypeEqualityFunc(np.ndarray, self.is_arrays_equal)
|
|
|
|
def is_arrays_equal(self, arr1, arr2, msg=None):
|
|
"""
|
|
Raises self.failureException is arrays arr1 and arr2
|
|
are not equal.
|
|
"""
|
|
if not np.allclose(arr1, arr2):
|
|
raise self.failureException(msg)
|
|
|
|
|