# -*- coding: utf-8 -*- # CCP in Tomographic Imaging (CCPi) Core Imaging Library (CIL). # Copyright 2017 UKRI-STFC # Copyright 2017 University of Manchester # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. 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)