Salome HOME
Updating tests to raise exceptions on differences
[modules/adao.git] / test / test6702 / utExtend.py
1 #-*-coding:iso-8859-1-*-
2 #
3 # Copyright (C) 2008-2017 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 """
24     Unittest extensions for Numpy objects
25 """
26 __author__ = "Jean-Philippe ARGAUD"
27 __all__ = ["assertAlmostEqualVector"]
28
29 import numpy
30
31 # ==============================================================================
32 def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None):
33     "Compare two vectors, like unittest.assertAlmostEqual"
34     if msg is not None:
35         print msg
36     if delta is not None:
37         if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any():
38             raise AssertionError("%s != %s within %s places"%(first,second,delta))
39     else:
40         if ( (numpy.asarray(first) - numpy.asarray(second)) > 10**(-int(places)) ).any():
41             raise AssertionError("%s != %s within %i places"%(first,second,places))
42     return max(abs(numpy.asarray(first) - numpy.asarray(second)))