Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bdd23e

Browse files
author
Alan McIntyre
committed
Update README.txt to indicate nose version dependency, and port SciPy r4424 to NumPy
(prevent import of nose until actual execution of tests). Restored "raises" function to numpy/testing/utils.py until it can be replaced with the function of the same name from nose.tools after the lazy import.
1 parent 70974af commit 2bdd23e

6 files changed

Lines changed: 63 additions & 31 deletions

File tree

README.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ directory) with:
1313

1414
python -c 'import numpy; numpy.test()'
1515

16-
Please note that you must have the 'nose' test framework installed in order to
17-
run the tests. More information about nose is available here:
16+
Please note that you must have version 0.10 or later of the 'nose' test
17+
framework installed in order to run the tests. More information about nose is
18+
available here:
1819

1920
http://somethingaboutorange.com/mrl/projects/nose/
2021

numpy/testing/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010

1111
import decorators as dec
1212
from utils import *
13-
14-
try:
15-
import nose
16-
from nose.tools import raises
17-
except ImportError:
18-
pass
19-
2013
from numpytest import *
21-
2214
from pkgtester import Tester
2315
test = Tester().test

numpy/testing/decorators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
1111
"""
1212

13-
try:
14-
import nose
15-
except ImportError:
16-
pass
17-
1813
def slow(t):
1914
"""Labels a test as 'slow'.
2015
@@ -76,6 +71,9 @@ def skipif(skip_condition, msg=None):
7671
if msg is None:
7772
msg = 'Test skipped due to test condition'
7873
def skip_decorator(f):
74+
# Local import to avoid a hard nose dependency and only incur the
75+
# import time overhead at actual test-time.
76+
import nose
7977
def skipper(*args, **kwargs):
8078
if skip_condition:
8179
raise nose.SkipTest, msg
@@ -87,6 +85,9 @@ def skipper(*args, **kwargs):
8785
def skipknownfailure(f):
8886
''' Decorator to raise SkipTest for test known to fail
8987
'''
88+
# Local import to avoid a hard nose dependency and only incur the
89+
# import time overhead at actual test-time.
90+
import nose
9091
def skipper(*args, **kwargs):
9192
raise nose.SkipTest, 'This test is known to fail'
9293
return nose.tools.make_decorator(f)(skipper)

numpy/testing/nosetester.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@
77
import sys
88
import re
99

10-
import nose
10+
def import_nose():
11+
""" Import nose only when needed.
12+
"""
13+
fine_nose = True
14+
try:
15+
import nose
16+
from nose.tools import raises
17+
except ImportError:
18+
fine_nose = False
19+
else:
20+
nose_version = nose.__versioninfo__
21+
if nose_version[0] < 1 and nose_version[1] < 10:
22+
fine_nose = False
23+
24+
if not fine_nose:
25+
raise ImportError('Need nose >=0.10 for tests - see '
26+
'http://somethingaboutorange.com/mrl/projects/nose')
27+
28+
return nose
1129

1230
class NoseTester(object):
1331
""" Nose test runner.
@@ -113,6 +131,7 @@ def test(self, label='fast', verbose=1, extra_argv=None, doctests=False,
113131
doctests : boolean
114132
If True, run doctests in module, default False
115133
'''
134+
nose = import_nose()
116135
argv = self._test_argv(label, verbose, extra_argv)
117136
if doctests:
118137
argv+=['--with-doctest','--doctest-tests']
@@ -135,6 +154,7 @@ def bench(self, label='fast', verbose=1, extra_argv=None):
135154
''' Run benchmarks for module using nose
136155
137156
%(test_header)s'''
157+
nose = import_nose()
138158
argv = self._test_argv(label, verbose, extra_argv)
139159
argv += ['--match', r'(?:^|[\\b_\\.%s-])[Bb]ench' % os.sep]
140160
nose.run(argv=argv)

numpy/testing/pkgtester.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,4 @@
1111
See nosetester module for test implementation
1212
1313
'''
14-
fine_nose = True
15-
try:
16-
import nose
17-
except ImportError:
18-
fine_nose = False
19-
else:
20-
nose_version = nose.__versioninfo__
21-
if nose_version[0] < 1 and nose_version[1] < 10:
22-
fine_nose = False
23-
24-
if fine_nose:
25-
from numpy.testing.nosetester import NoseTester as Tester
26-
else:
27-
from numpy.testing.nulltester import NullTester as Tester
14+
from numpy.testing.nosetester import NoseTester as Tester

numpy/testing/utils.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
__all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',
1212
'assert_array_equal', 'assert_array_less', 'assert_string_equal',
1313
'assert_array_almost_equal', 'build_err_msg', 'jiffies', 'memusage',
14-
'rand', 'rundocs', 'runstring']
14+
'raises', 'rand', 'rundocs', 'runstring']
1515

1616
def rand(*args):
1717
"""Returns an array of random numbers with the given shape.
@@ -317,3 +317,34 @@ def rundocs(filename=None):
317317
for test in tests:
318318
runner.run(test)
319319
return
320+
321+
322+
def raises(*exceptions):
323+
""" Assert that a test function raises one of the specified exceptions to
324+
pass.
325+
"""
326+
# FIXME: when we transition to nose, just use its implementation. It's
327+
# better.
328+
def deco(function):
329+
def f2(*args, **kwds):
330+
try:
331+
function(*args, **kwds)
332+
except exceptions:
333+
pass
334+
except:
335+
# Anything else.
336+
raise
337+
else:
338+
raise AssertionError('%s() did not raise one of (%s)' %
339+
(function.__name__, ', '.join([e.__name__ for e in exceptions])))
340+
try:
341+
f2.__name__ = function.__name__
342+
except TypeError:
343+
# Python 2.3 does not permit this.
344+
pass
345+
f2.__dict__ = function.__dict__
346+
f2.__doc__ = function.__doc__
347+
f2.__module__ = function.__module__
348+
return f2
349+
350+
return deco

0 commit comments

Comments
 (0)