3
0
mirror of https://github.com/triqs/dft_tools synced 2024-07-27 21:27:40 +02:00
dft_tools/python/converters/vasp/test/inpconf/arraytest.py
Oleg E. Peil 9d4fb22572 Rearranged test cases for 'inpconf.py'.
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.
2015-10-11 13:55:04 +02:00

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)