From a12ba71294078c9d1512d926296eca70b3349725 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Fri, 21 Jun 2019 11:02:05 +0100 Subject: added testclass file to hold the CCPiTestClass definitions --- Wrappers/Python/test/testclass.py | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 Wrappers/Python/test/testclass.py (limited to 'Wrappers') diff --git a/Wrappers/Python/test/testclass.py b/Wrappers/Python/test/testclass.py new file mode 100755 index 0000000..51b9f3f --- /dev/null +++ b/Wrappers/Python/test/testclass.py @@ -0,0 +1,41 @@ +import unittest +from ccpi.framework import ImageGeometry, ImageData, BlockDataContainer, DataContainer +import numpy + +def dt(steps): + return steps[-1] - steps[-2] + +class CCPiTestClass(unittest.TestCase): + def assertBlockDataContainerEqual(self, container1, container2): + print ("assert Block Data Container Equal") + self.assertTrue(issubclass(container1.__class__, container2.__class__)) + for col in range(container1.shape[0]): + if issubclass(container1.get_item(col).__class__, DataContainer): + print ("Checking col ", col) + self.assertNumpyArrayEqual( + container1.get_item(col).as_array(), + container2.get_item(col).as_array() + ) + else: + self.assertBlockDataContainerEqual(container1.get_item(col),container2.get_item(col)) + + def assertNumpyArrayEqual(self, first, second): + res = True + try: + numpy.testing.assert_array_equal(first, second) + except AssertionError as err: + res = False + print(err) + self.assertTrue(res) + + def assertNumpyArrayAlmostEqual(self, first, second, decimal=6): + res = True + try: + numpy.testing.assert_array_almost_equal(first, second, decimal) + except AssertionError as err: + res = False + print(err) + print("expected " , second) + print("actual " , first) + + self.assertTrue(res) \ No newline at end of file -- cgit v1.2.3