Skip to content

Commit 65c7ff6

Browse files
authored
Merge pull request #785 from effigies/fix/doctest_teardown
TEST: Use package-wide setup and teardown to adjust numpy print options
2 parents f3d115f + 4cccd86 commit 65c7ff6

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

nibabel/__init__.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,27 @@
3535
For more detailed information see the :ref:`manual`.
3636
"""
3737

38-
39-
def setup_test():
40-
""" Set numpy print options to "legacy" for new versions of numpy
41-
42-
If imported into a file, nosetest will run this before any doctests.
43-
"""
44-
import numpy
38+
# Package-wide test setup and teardown
39+
_test_states = {
40+
# Numpy changed print options in 1.14; we can update docstrings and remove
41+
# these when our minimum for building docs exceeds that
42+
'legacy_printopt': None,
43+
}
44+
45+
def setup_package():
46+
""" Set numpy print style to legacy="1.13" for newer versions of numpy """
47+
import numpy as np
4548
from distutils.version import LooseVersion
46-
if LooseVersion(numpy.__version__) >= LooseVersion('1.14'):
47-
numpy.set_printoptions(legacy="1.13")
49+
if LooseVersion(np.__version__) >= LooseVersion('1.14'):
50+
if _test_states.get('legacy_printopt') is None:
51+
_test_states['legacy_printopt'] = np.get_printoptions().get('legacy')
52+
np.set_printoptions(legacy="1.13")
53+
54+
def teardown_package():
55+
""" Reset print options when tests finish """
56+
import numpy as np
57+
if _test_states.get('legacy_printopt') is not None:
58+
np.set_printoptions(legacy=_test_states.pop('legacy_printopt'))
4859

4960

5061
# module imports

nibabel/affines.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77

88
from six.moves import reduce
9-
from . import setup_test # noqa
109

1110

1211
class AffineError(ValueError):

nibabel/casting.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from platform import processor, machine
99

1010
import numpy as np
11-
from . import setup_test # noqa
1211

1312

1413
class CastingError(Exception):

nibabel/nicom/dwiparams.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
'''
2222
import numpy as np
2323
import numpy.linalg as npl
24-
from .. import setup_test as setup_module # noqa
2524

2625

2726
def B2q(B, tol=None):

nibabel/nifti1.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from .spm99analyze import SpmAnalyzeHeader
2929
from .casting import have_binary128
3030
from .pydicom_compat import have_dicom, pydicom as pdcm
31-
from . import setup_test # noqa
3231

3332
# nifti1 flat header definition for Analyze-like first 348 bytes
3433
# first number in comments indicates offset in file header in bytes

nibabel/quaternions.py

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import math
2929
import numpy as np
30-
from . import setup_test # noqa
3130

3231
MAX_FLOAT = np.maximum_sctype(np.float)
3332
FLOAT_EPS = np.finfo(np.float).eps

0 commit comments

Comments
 (0)