mirror of
https://github.com/triqs/dft_tools
synced 2024-11-12 17:13:48 +01:00
9d4fb22572
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.
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)
|
|
|
|
|