Skip to content

Commit 30be196

Browse files
committed
NF: add np.allclose doctest modifier
This is to work round the numpy printing changes.
1 parent 3af6877 commit 30be196

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

nipy/testing/doctester.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
NumpyOutputChecker)
2020

2121
IGNORE_OUTPUT = register_optionflag('IGNORE_OUTPUT')
22+
NP_ALLCLOSE = register_optionflag('NP_ALLCLOSE')
2223
SYMPY_EQUAL = register_optionflag('SYMPY_EQUAL')
2324
STRUCTARR_EQUAL = register_optionflag('STRUCTARR_EQUAL')
2425
STRIP_ARRAY_REPR = register_optionflag('STRIP_ARRAY_REPR')
@@ -186,6 +187,10 @@ def check_output(self, want, got, optionflags):
186187
dp = 6
187188
want = round_numbers(want, dp)
188189
got = round_numbers(got, dp)
190+
# Are the arrays close when run through numpy?
191+
if NP_ALLCLOSE & optionflags:
192+
res = np.allclose(eval(want), eval(got))
193+
return res == wanted_tf
189194
# Are the strings equal when run through sympy?
190195
if SYMPY_EQUAL & optionflags:
191196
from sympy import sympify

nipy/testing/tests/test_doctesting.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ def check_ignore_output():
7575
'The answer'
7676
"""
7777

78+
79+
def check_np_allclose():
80+
""" Check NP_ALLCLOSE option
81+
82+
>>> np.array([38.0890515 , -3.45429252]) #doctest: +NP_ALLCLOSE
83+
array([ 38.0890515 , -3.45429252])
84+
>>> np.array([38.0899 , -3.45429252]) #doctest: +NP_ALLCLOSE +NOT_EQUAL
85+
array([ 38.0890515 , -3.45429252])
86+
"""
87+
88+
7889
def check_sympy_equal():
7990
""" Check SYMPY_EQUAL option
8091

0 commit comments

Comments
 (0)