6
6
# SPDX - License - Identifier: GPL - 3.0 +
7
7
8
8
from mantid .simpleapi import CompareWorkspaces
9
+ from mantid .kernel import Property
9
10
10
11
11
- def assert_almost_equal (Workspace1 , Workspace2 , rtol = 0.0 , atol = 0.0 ):
12
+ def assert_almost_equal (Workspace1 , Workspace2 , rtol = Property . EMPTY_DBL , atol = Property . EMPTY_DBL , ** kwargs ):
12
13
"""
13
14
Raises an assertion error if two workspaces are not within specified tolerance.
14
15
@@ -26,23 +27,26 @@ def assert_almost_equal(Workspace1, Workspace2, rtol=0.0, atol=0.0):
26
27
AssertionError
27
28
If Workspace1 and Workspace2 are not equal up to specified precision
28
29
ValueError
29
- If atol and rtol are both provided
30
+ If atol and rtol are both not provided
30
31
31
32
"""
32
-
33
- if rtol != 0.0 and atol != 0.0 :
34
- raise ValueError ("Specify rtol or atol, not both" )
35
- _rel = False
36
- tolerance = 1e-10
37
- if atol :
38
- tolerance = atol
39
-
40
- if rtol :
41
- tolerance = rtol
42
- _rel = True
43
-
44
- result , message = CompareWorkspaces (Workspace1 , Workspace2 , Tolerance = tolerance , ToleranceRelErr = _rel )
45
- msg_dict = message .toDict ()
46
- if not result :
47
- msg = ", " .join (msg_dict ["Message" ]) + f", Workspaces are not within tolerance ({ tolerance } )"
48
- raise AssertionError (msg )
33
+ # check arguments
34
+ if len (set (kwargs .keys ()).intersection ({"Workspace1" , "Workspace2" , "Tolerance" , "ToleranceRelErr" })):
35
+ raise ValueError ("Workspace1, Workspace2, Tolerance, ToleranceRelErr cannot be passed as additional parameters" )
36
+
37
+ if rtol == Property .EMPTY_DBL and atol == Property .EMPTY_DBL :
38
+ raise ValueError ("Specify rtol or atol" )
39
+
40
+ if rtol > Property .EMPTY_DBL :
41
+ result , message = CompareWorkspaces (Workspace1 , Workspace2 , Tolerance = rtol , ToleranceRelErr = True , ** kwargs )
42
+ msg_dict = message .toDict ()
43
+ if not result :
44
+ msg = ", " .join (msg_dict ["Message" ]) + f", Workspaces are not within relative tolerance ({ rtol } )"
45
+ raise AssertionError (msg )
46
+
47
+ if atol > Property .EMPTY_DBL :
48
+ result , message = CompareWorkspaces (Workspace1 , Workspace2 , Tolerance = atol , ToleranceRelErr = False , ** kwargs )
49
+ msg_dict = message .toDict ()
50
+ if not result :
51
+ msg = ", " .join (msg_dict ["Message" ]) + f", Workspaces are not within absolute tolerance ({ atol } )"
52
+ raise AssertionError (msg )
0 commit comments