Skip to content

Commit d5e90dc

Browse files
committed
TEST: Use package-wide setup and teardown to adjust numpy print options
1 parent b356a64 commit d5e90dc

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

nibabel/__init__.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,28 @@
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+
# Numpy changed print options in 1.14; we can update docstrings and remove
40+
# these when our minimum for building docs exceeds that
41+
_save_printopts = None
42+
43+
def setup_package():
44+
""" Set numpy print style to legacy="1.13" for newer versions of numpy """
45+
import nibabel as nb
46+
import numpy as np
4547
from distutils.version import LooseVersion
46-
if LooseVersion(numpy.__version__) >= LooseVersion('1.14'):
47-
numpy.set_printoptions(legacy="1.13")
48+
if nb._save_printopts is None:
49+
nb._save_printopts = np.get_printoptions().get('legacy')
50+
if LooseVersion(np.__version__) >= LooseVersion('1.14'):
51+
np.set_printoptions(legacy="1.13")
52+
53+
def teardown_package():
54+
""" Reset print options when tests finish """
55+
import nibabel as nb
56+
import numpy as np
57+
if nb._save_printopts is not None:
58+
np.set_printoptions(legacy=nb._save_printopts)
59+
nb._save_printopts = None
4860

4961

5062
# 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)