Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70c5052

Browse filesBrowse files
committed
ENH: testing: add SkipTest and KnownFailureException
* use SkipTest in numpy tests instead of importing it from nose * add a KnownFailureException as an alias for KnownFailureTest (the former is preferred, but the latter is kept for backcompat) * rename the KnownFailure nose plugin into KnownFailurePlugin, and keep the old name for backcompat
1 parent cf66c68 commit 70c5052
Copy full SHA for 70c5052

13 files changed

+72
-59
lines changed

‎doc/release/1.11.0-notes.rst

Copy file name to clipboardExpand all lines: doc/release/1.11.0-notes.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ via ``python runtests.py --bench``. For more details, see ``benchmarks/README.rs
7171
arrays have memory overlap is added. ``np.may_share_memory`` also now
7272
has an option to spend more effort to reduce false positives.
7373

74+
* ``SkipTest`` and ``KnownFailureException`` exception classes are exposed in the
75+
``numpy.testing`` namespace. Raise them in a test function to mark the test to
76+
be skipped or mark it as a known failure, respectively.
77+
7478
Improvements
7579
============
7680

‎numpy/core/tests/test_multiarray.py

Copy file name to clipboardExpand all lines: numpy/core/tests/test_multiarray.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818

1919
import numpy as np
20-
from nose import SkipTest
2120
from numpy.compat import asbytes, getexception, strchar, unicode, sixu
2221
from test_print import in_foreign_locale
2322
from numpy.core.multiarray_tests import (
@@ -29,7 +28,7 @@
2928
TestCase, run_module_suite, assert_, assert_raises,
3029
assert_equal, assert_almost_equal, assert_array_equal,
3130
assert_array_almost_equal, assert_allclose,
32-
assert_array_less, runstring, dec
31+
assert_array_less, runstring, dec, SkipTest
3332
)
3433

3534
# Need to test an object that does not fully implement math interface

‎numpy/core/tests/test_print.py

Copy file name to clipboardExpand all lines: numpy/core/tests/test_print.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
from numpy.testing import (
9-
run_module_suite, assert_, assert_equal
9+
run_module_suite, assert_, assert_equal, SkipTest
1010
)
1111

1212

@@ -207,7 +207,7 @@ def test_scalar_format():
207207
def in_foreign_locale(func):
208208
"""
209209
Swap LC_NUMERIC locale to one in which the decimal point is ',' and not '.'
210-
If not possible, raise nose.SkipTest
210+
If not possible, raise SkipTest
211211
212212
"""
213213
if sys.platform == 'win32':
@@ -225,8 +225,8 @@ def wrapper(*args, **kwargs):
225225
except locale.Error:
226226
pass
227227
else:
228-
raise nose.SkipTest("Skipping locale test, because "
229-
"French locale not found")
228+
raise SkipTest("Skipping locale test, because "
229+
"French locale not found")
230230
return func(*args, **kwargs)
231231
finally:
232232
locale.setlocale(locale.LC_NUMERIC, locale=curloc)

‎numpy/f2py/tests/test_array_from_pyobj.py

Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_array_from_pyobj.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import sys
66
import copy
77

8-
import nose
9-
108
from numpy import (
119
array, alltrue, ndarray, zeros, dtype, intp, clongdouble
1210
)
1311
from numpy.testing import (
14-
run_module_suite, assert_, assert_equal
12+
run_module_suite, assert_, assert_equal, SkipTest
1513
)
1614
from numpy.core.multiarray import typeinfo
1715
import util
@@ -28,7 +26,7 @@ def setup():
2826

2927
# Check compiler availability first
3028
if not util.has_c_compiler():
31-
raise nose.SkipTest("No C compiler available")
29+
raise SkipTest("No C compiler available")
3230

3331
if wrap is None:
3432
config_code = """

‎numpy/f2py/tests/util.py

Copy file name to clipboardExpand all lines: numpy/f2py/tests/util.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import re
1818
import random
1919

20-
import nose
21-
2220
from numpy.compat import asbytes, asstr
2321
import numpy.f2py
22+
from numpy.testing import SkipTest
2423

2524
try:
2625
from hashlib import md5
@@ -334,7 +333,7 @@ def setUp(self):
334333

335334
# Check compiler availability first
336335
if not has_c_compiler():
337-
raise nose.SkipTest("No C compiler available")
336+
raise SkipTest("No C compiler available")
338337

339338
codes = []
340339
if self.sources:
@@ -350,9 +349,9 @@ def setUp(self):
350349
elif fn.endswith('.f90'):
351350
needs_f90 = True
352351
if needs_f77 and not has_f77_compiler():
353-
raise nose.SkipTest("No Fortran 77 compiler available")
352+
raise SkipTest("No Fortran 77 compiler available")
354353
if needs_f90 and not has_f90_compiler():
355-
raise nose.SkipTest("No Fortran 90 compiler available")
354+
raise SkipTest("No Fortran 90 compiler available")
356355

357356
# Build the module
358357
if self.code is not None:

‎numpy/lib/tests/test__datasource.py

Copy file name to clipboardExpand all lines: numpy/lib/tests/test__datasource.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from numpy.compat import asbytes
99
from numpy.testing import (
10-
run_module_suite, TestCase, assert_
10+
run_module_suite, TestCase, assert_, SkipTest
1111
)
1212
import numpy.lib._datasource as datasource
1313

@@ -137,8 +137,7 @@ def test_ValidGzipFile(self):
137137
import gzip
138138
except ImportError:
139139
# We don't have the gzip capabilities to test.
140-
import nose
141-
raise nose.SkipTest
140+
raise SkipTest
142141
# Test datasource's internal file_opener for Gzip files.
143142
filepath = os.path.join(self.tmpdir, 'foobar.txt.gz')
144143
fp = gzip.open(filepath, 'w')
@@ -154,8 +153,7 @@ def test_ValidBz2File(self):
154153
import bz2
155154
except ImportError:
156155
# We don't have the bz2 capabilities to test.
157-
import nose
158-
raise nose.SkipTest
156+
raise SkipTest
159157
# Test datasource's internal file_opener for BZip2 files.
160158
filepath = os.path.join(self.tmpdir, 'foobar.txt.bz2')
161159
fp = bz2.BZ2File(filepath, 'w')

‎numpy/lib/tests/test_format.py

Copy file name to clipboardExpand all lines: numpy/lib/tests/test_format.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
from numpy.compat import asbytes, asbytes_nested, sixu
288288
from numpy.testing import (
289289
run_module_suite, assert_, assert_array_equal, assert_raises, raises,
290-
dec
290+
dec, SkipTest
291291
)
292292
from numpy.lib import format
293293

@@ -812,7 +812,6 @@ def test_bad_header():
812812

813813

814814
def test_large_file_support():
815-
from nose import SkipTest
816815
if (sys.platform == 'win32' or sys.platform == 'cygwin'):
817816
raise SkipTest("Unknown if Windows has sparse filesystems")
818817
# try creating a large sparse file

‎numpy/linalg/tests/test_linalg.py

Copy file name to clipboardExpand all lines: numpy/linalg/tests/test_linalg.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from numpy.testing import (
1818
assert_, assert_equal, assert_raises, assert_array_equal,
1919
assert_almost_equal, assert_allclose, run_module_suite,
20-
dec
20+
dec, SkipTest
2121
)
2222

2323

@@ -1215,7 +1215,6 @@ def test_xerbla_override():
12151215
# Check that our xerbla has been successfully linked in. If it is not,
12161216
# the default xerbla routine is called, which prints a message to stdout
12171217
# and may, or may not, abort the process depending on the LAPACK package.
1218-
from nose import SkipTest
12191218

12201219
XERBLA_OK = 255
12211220

‎numpy/testing/decorators.py

Copy file name to clipboardExpand all lines: numpy/testing/decorators.py
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import warnings
1919
import collections
2020

21+
from .utils import SkipTest
2122

2223
def slow(t):
2324
"""
@@ -141,14 +142,14 @@ def get_msg(func,msg=None):
141142
def skipper_func(*args, **kwargs):
142143
"""Skipper for normal test functions."""
143144
if skip_val():
144-
raise nose.SkipTest(get_msg(f, msg))
145+
raise SkipTest(get_msg(f, msg))
145146
else:
146147
return f(*args, **kwargs)
147148

148149
def skipper_gen(*args, **kwargs):
149150
"""Skipper for test generators."""
150151
if skip_val():
151-
raise nose.SkipTest(get_msg(f, msg))
152+
raise SkipTest(get_msg(f, msg))
152153
else:
153154
for x in f(*args, **kwargs):
154155
yield x
@@ -166,7 +167,7 @@ def skipper_gen(*args, **kwargs):
166167

167168
def knownfailureif(fail_condition, msg=None):
168169
"""
169-
Make function raise KnownFailureTest exception if given condition is true.
170+
Make function raise KnownFailureException exception if given condition is true.
170171
171172
If the condition is a callable, it is used at runtime to dynamically
172173
make the decision. This is useful for tests that may require costly
@@ -178,15 +179,15 @@ def knownfailureif(fail_condition, msg=None):
178179
Flag to determine whether to mark the decorated test as a known
179180
failure (if True) or not (if False).
180181
msg : str, optional
181-
Message to give on raising a KnownFailureTest exception.
182+
Message to give on raising a KnownFailureException exception.
182183
Default is None.
183184
184185
Returns
185186
-------
186187
decorator : function
187-
Decorator, which, when applied to a function, causes SkipTest
188-
to be raised when `skip_condition` is True, and the function
189-
to be called normally otherwise.
188+
Decorator, which, when applied to a function, causes
189+
KnownFailureException to be raised when `fail_condition` is True,
190+
and the function to be called normally otherwise.
190191
191192
Notes
192193
-----
@@ -207,11 +208,11 @@ def knownfail_decorator(f):
207208
# Local import to avoid a hard nose dependency and only incur the
208209
# import time overhead at actual test-time.
209210
import nose
210-
from .noseclasses import KnownFailureTest
211+
from .noseclasses import KnownFailureException
211212

212213
def knownfailer(*args, **kwargs):
213214
if fail_val():
214-
raise KnownFailureTest(msg)
215+
raise KnownFailureException(msg)
215216
else:
216217
return f(*args, **kwargs)
217218
return nose.tools.make_decorator(f)(knownfailer)

‎numpy/testing/noseclasses.py

Copy file name to clipboardExpand all lines: numpy/testing/noseclasses.py
+9-10Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import doctest
11+
import inspect
1112

1213
import nose
1314
from nose.plugins import doctests as npd
@@ -16,7 +17,8 @@
1617
from nose.util import src
1718
import numpy
1819
from .nosetester import get_package_name
19-
import inspect
20+
from .utils import KnownFailureException, KnownFailureTest
21+
2022

2123
# Some of the classes in this module begin with 'Numpy' to clearly distinguish
2224
# them from the plethora of very similar names from nose/unittest/doctest
@@ -298,27 +300,22 @@ def configure(self, options, config):
298300
if p.name != self.to_unplug]
299301

300302

301-
class KnownFailureTest(Exception):
302-
'''Raise this exception to mark a test as a known failing test.'''
303-
pass
304-
305-
306-
class KnownFailure(ErrorClassPlugin):
303+
class KnownFailurePlugin(ErrorClassPlugin):
307304
'''Plugin that installs a KNOWNFAIL error class for the
308-
KnownFailureClass exception. When KnownFailureTest is raised,
305+
KnownFailureClass exception. When KnownFailure is raised,
309306
the exception will be logged in the knownfail attribute of the
310307
result, 'K' or 'KNOWNFAIL' (verbose) will be output, and the
311308
exception will not be counted as an error or failure.'''
312309
enabled = True
313-
knownfail = ErrorClass(KnownFailureTest,
310+
knownfail = ErrorClass(KnownFailureException,
314311
label='KNOWNFAIL',
315312
isfailure=False)
316313

317314
def options(self, parser, env=os.environ):
318315
env_opt = 'NOSE_WITHOUT_KNOWNFAIL'
319316
parser.add_option('--no-knownfail', action='store_true',
320317
dest='noKnownFail', default=env.get(env_opt, False),
321-
help='Disable special handling of KnownFailureTest '
318+
help='Disable special handling of KnownFailure '
322319
'exceptions')
323320

324321
def configure(self, options, conf):
@@ -329,6 +326,8 @@ def configure(self, options, conf):
329326
if disable:
330327
self.enabled = False
331328

329+
KnownFailure = KnownFailurePlugin # backwards compat
330+
332331

333332
# Class allows us to save the results of the tests in runTests - see runTests
334333
# method docstring for details

‎numpy/testing/nosetester.py

Copy file name to clipboardExpand all lines: numpy/testing/nosetester.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def run_module_suite(file_to_run=None, argv=None):
121121
argv = argv + [file_to_run]
122122

123123
nose = import_nose()
124-
from .noseclasses import KnownFailure
125-
nose.run(argv=argv, addplugins=[KnownFailure()])
124+
from .noseclasses import KnownFailurePlugin
125+
nose.run(argv=argv, addplugins=[KnownFailurePlugin()])
126126

127127

128128
class NoseTester(object):
@@ -301,8 +301,8 @@ def prepare_test_args(self, label='fast', verbose=1, extra_argv=None,
301301
'--cover-tests', '--cover-erase']
302302
# construct list of plugins
303303
import nose.plugins.builtin
304-
from .noseclasses import KnownFailure, Unplugger
305-
plugins = [KnownFailure()]
304+
from .noseclasses import KnownFailurePlugin, Unplugger
305+
plugins = [KnownFailurePlugin()]
306306
plugins += [p() for p in nose.plugins.builtin.plugins]
307307
# add doctesting if required
308308
doctest_argv = '--with-doctest' in argv

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.