3
0
mirror of https://github.com/triqs/dft_tools synced 2024-06-02 03:15:33 +02:00
dft_tools/test/plovasp/_inpconf/arraytest.py
Oleg E. Peil 30dc760dcb Moved PLOVasp tests to root 'test' directory
Appropriate modifications to CMakeLists have also been made.
2016-03-10 11:45:53 +01: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)