Skip to content

TEST: Use package-wide setup and teardown to adjust numpy print options #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion nibabel/affines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np

from six.moves import reduce
from . import setup_test # noqa


class AffineError(ValueError):
Expand Down
1 change: 0 additions & 1 deletion nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from platform import processor, machine

import numpy as np
from . import setup_test # noqa


class CastingError(Exception):
Expand Down
1 change: 0 additions & 1 deletion nibabel/nicom/dwiparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion nibabel/quaternions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down