diff --git a/nibabel/__init__.py b/nibabel/__init__.py index 20f1aafefc..20fdad3469 100644 --- a/nibabel/__init__.py +++ b/nibabel/__init__.py @@ -35,16 +35,27 @@ For more detailed information see the :ref:`manual`. """ - -def setup_test(): - """ Set numpy print options to "legacy" for new versions of numpy - - If imported into a file, nosetest will run this before any doctests. - """ - import numpy +# Package-wide test setup and teardown +_test_states = { + # Numpy changed print options in 1.14; we can update docstrings and remove + # these when our minimum for building docs exceeds that + 'legacy_printopt': None, + } + +def setup_package(): + """ Set numpy print style to legacy="1.13" for newer versions of numpy """ + import numpy as np from distutils.version import LooseVersion - if LooseVersion(numpy.__version__) >= LooseVersion('1.14'): - numpy.set_printoptions(legacy="1.13") + if LooseVersion(np.__version__) >= LooseVersion('1.14'): + if _test_states.get('legacy_printopt') is None: + _test_states['legacy_printopt'] = np.get_printoptions().get('legacy') + np.set_printoptions(legacy="1.13") + +def teardown_package(): + """ Reset print options when tests finish """ + import numpy as np + if _test_states.get('legacy_printopt') is not None: + np.set_printoptions(legacy=_test_states.pop('legacy_printopt')) # module imports diff --git a/nibabel/affines.py b/nibabel/affines.py index 057233e454..07154089a1 100644 --- a/nibabel/affines.py +++ b/nibabel/affines.py @@ -6,7 +6,6 @@ import numpy as np from six.moves import reduce -from . import setup_test # noqa class AffineError(ValueError): diff --git a/nibabel/casting.py b/nibabel/casting.py index 3709ee1dea..89be788da5 100644 --- a/nibabel/casting.py +++ b/nibabel/casting.py @@ -8,7 +8,6 @@ from platform import processor, machine import numpy as np -from . import setup_test # noqa class CastingError(Exception): diff --git a/nibabel/nicom/dwiparams.py b/nibabel/nicom/dwiparams.py index 1fda89b0da..e9d05c0d57 100644 --- a/nibabel/nicom/dwiparams.py +++ b/nibabel/nicom/dwiparams.py @@ -21,7 +21,6 @@ ''' import numpy as np import numpy.linalg as npl -from .. import setup_test as setup_module # noqa def B2q(B, tol=None): diff --git a/nibabel/nifti1.py b/nibabel/nifti1.py index a050195234..c2d409e81a 100644 --- a/nibabel/nifti1.py +++ b/nibabel/nifti1.py @@ -28,7 +28,6 @@ from .spm99analyze import SpmAnalyzeHeader from .casting import have_binary128 from .pydicom_compat import have_dicom, pydicom as pdcm -from . import setup_test # noqa # nifti1 flat header definition for Analyze-like first 348 bytes # first number in comments indicates offset in file header in bytes diff --git a/nibabel/quaternions.py b/nibabel/quaternions.py index f9318a93f2..adc2367238 100644 --- a/nibabel/quaternions.py +++ b/nibabel/quaternions.py @@ -27,7 +27,6 @@ import math import numpy as np -from . import setup_test # noqa MAX_FLOAT = np.maximum_sctype(np.float) FLOAT_EPS = np.finfo(np.float).eps