From 7a4d5b525413d7a22a0da838f501e71c120726c6 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 7 Mar 2019 22:56:02 -0500 Subject: [PATCH 1/3] RF: centralize import of decorators from numpy.testing I kept receiving messages that imports from numpy.testing.decorators are deprecated (since 1.5 IIRC), so I found that some places still import them in the test files instead of centraly from nibabel.testing which already provides imports adaptor. So I RFed to avoid such imports, and moved a stub for @slow there too --- nibabel/nicom/tests/test_csareader.py | 2 +- nibabel/testing/__init__.py | 10 ++++++++++ nibabel/tests/nibabel_data.py | 2 +- nibabel/tests/test_processing.py | 2 +- nibabel/tests/test_quaternions.py | 9 +-------- nibabel/tests/test_viewers.py | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/nibabel/nicom/tests/test_csareader.py b/nibabel/nicom/tests/test_csareader.py index d0ecfddc6f..592dd2ba54 100644 --- a/nibabel/nicom/tests/test_csareader.py +++ b/nibabel/nicom/tests/test_csareader.py @@ -12,7 +12,7 @@ from nose.tools import (assert_true, assert_false, assert_equal, assert_raises) -from numpy.testing.decorators import skipif +from ...testing import skipif from nibabel.pydicom_compat import dicom_test, pydicom from .test_dicomwrappers import (IO_DATA_PATH, DATA) diff --git a/nibabel/testing/__init__.py b/nibabel/testing/__init__.py index 35aac71a49..ba027c97c7 100644 --- a/nibabel/testing/__init__.py +++ b/nibabel/testing/__init__.py @@ -21,8 +21,18 @@ try: from numpy.testing import dec skipif = dec.skipif + slow = dec.slow except ImportError: from numpy.testing.decorators import skipif + + # Recent (1.2) versions of numpy have this decorator + try: + from numpy.testing.decorators import slow + except ImportError: + def slow(t): + t.slow = True + return t + # Allow failed import of nose if not now running tests try: from nose.tools import (assert_equal, assert_not_equal, diff --git a/nibabel/tests/nibabel_data.py b/nibabel/tests/nibabel_data.py index 2ff473fd1d..529e103f46 100644 --- a/nibabel/tests/nibabel_data.py +++ b/nibabel/tests/nibabel_data.py @@ -4,7 +4,7 @@ from os import environ, listdir from os.path import dirname, realpath, join as pjoin, isdir, exists -from numpy.testing.decorators import skipif +from ..testing import skipif def get_nibabel_data(): diff --git a/nibabel/tests/test_processing.py b/nibabel/tests/test_processing.py index 2cc2dde2b4..34b30f14c8 100644 --- a/nibabel/tests/test_processing.py +++ b/nibabel/tests/test_processing.py @@ -30,7 +30,7 @@ from numpy.testing import (assert_almost_equal, assert_array_equal) -from numpy.testing.decorators import skipif +from ..testing import skipif from nose.tools import (assert_true, assert_false, assert_raises, assert_equal, assert_not_equal) diff --git a/nibabel/tests/test_quaternions.py b/nibabel/tests/test_quaternions.py index 7983b7037d..a3f2ba9546 100644 --- a/nibabel/tests/test_quaternions.py +++ b/nibabel/tests/test_quaternions.py @@ -11,14 +11,7 @@ import numpy as np from numpy import pi -# Recent (1.2) versions of numpy have this decorator -try: - from numpy.testing.decorators import slow -except ImportError: - def slow(t): - t.slow = True - return t - +from ..testing import slow from nose.tools import assert_raises, assert_true, assert_false, \ assert_equal diff --git a/nibabel/tests/test_viewers.py b/nibabel/tests/test_viewers.py index 75d261cc02..68710b3126 100644 --- a/nibabel/tests/test_viewers.py +++ b/nibabel/tests/test_viewers.py @@ -14,7 +14,7 @@ from ..optpkg import optional_package from ..viewers import OrthoSlicer3D -from numpy.testing.decorators import skipif +from ..testing import skipif from numpy.testing import assert_array_equal, assert_equal from nose.tools import assert_raises, assert_true From 0c36551c7398dcfb132fe4ce37b115c23d183b72 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 8 Mar 2019 11:36:02 -0500 Subject: [PATCH 2/3] RF: remove obsolete guard for older numpys --- nibabel/testing/__init__.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/nibabel/testing/__init__.py b/nibabel/testing/__init__.py index ba027c97c7..5cf69f2e10 100644 --- a/nibabel/testing/__init__.py +++ b/nibabel/testing/__init__.py @@ -23,15 +23,7 @@ skipif = dec.skipif slow = dec.slow except ImportError: - from numpy.testing.decorators import skipif - - # Recent (1.2) versions of numpy have this decorator - try: - from numpy.testing.decorators import slow - except ImportError: - def slow(t): - t.slow = True - return t + from numpy.testing.decorators import (skipif, slow) # Allow failed import of nose if not now running tests try: From c053e419afc4e6232cfde31c0d5d10daa5cfef62 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Tue, 12 Mar 2019 21:44:16 -0400 Subject: [PATCH 3/3] RF: Remove unnecessary try guard --- nibabel/testing/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/nibabel/testing/__init__.py b/nibabel/testing/__init__.py index 5cf69f2e10..2c0a93fe32 100644 --- a/nibabel/testing/__init__.py +++ b/nibabel/testing/__init__.py @@ -17,13 +17,9 @@ import numpy as np from numpy.testing import assert_array_equal - -try: - from numpy.testing import dec - skipif = dec.skipif - slow = dec.slow -except ImportError: - from numpy.testing.decorators import (skipif, slow) +from numpy.testing import dec +skipif = dec.skipif +slow = dec.slow # Allow failed import of nose if not now running tests try: