diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/testing/decorators.py | 6 | ||||
-rw-r--r-- | numpy/testing/tests/test_decorators.py | 41 |
2 files changed, 37 insertions, 10 deletions
diff --git a/numpy/testing/decorators.py b/numpy/testing/decorators.py index 68335cc18..a7cc9a847 100644 --- a/numpy/testing/decorators.py +++ b/numpy/testing/decorators.py @@ -129,9 +129,9 @@ def skipif(skip_condition, msg=None): def get_msg(func,msg=None): """Skip message with information about function being skipped.""" - if msg is None: + if msg is None: out = 'Test skipped due to test condition' - else: + else: out = '\n'+msg return "Skipping test: %s%s" % (func.__name__,out) @@ -158,7 +158,7 @@ def skipif(skip_condition, msg=None): skipper = skipper_gen else: skipper = skipper_func - + return nose.tools.make_decorator(f)(skipper) return skip_decorator diff --git a/numpy/testing/tests/test_decorators.py b/numpy/testing/tests/test_decorators.py index 504971e61..a28e24ac3 100644 --- a/numpy/testing/tests/test_decorators.py +++ b/numpy/testing/tests/test_decorators.py @@ -8,7 +8,7 @@ def test_slow(): def slow_func(x,y,z): pass - assert(slow_func.slow) + assert_(slow_func.slow) def test_setastest(): @dec.setastest() @@ -23,11 +23,11 @@ def test_setastest(): def f_isnottest(a): pass - assert(f_default.__test__) - assert(f_istest.__test__) - assert(not f_isnottest.__test__) + assert_(f_default.__test__) + assert_(f_istest.__test__) + assert_(not f_isnottest.__test__) -class DidntSkipException(Exception): +class DidntSkipException(Exception): pass def test_skip_functions_hardcoded(): @@ -148,9 +148,36 @@ def test_skip_generators_callable(): pass -if __name__ == '__main__': - run_module_suite() +def test_deprecated(): + @dec.deprecated(True) + def non_deprecated_func(): + pass + + @dec.deprecated() + def deprecated_func(): + import warnings + warnings.warn("TEST: deprecated func", DeprecationWarning) + @dec.deprecated() + def deprecated_func2(): + import warnings + warnings.warn("AHHHH") + raise ValueError + @dec.deprecated() + def deprecated_func3(): + import warnings + warnings.warn("AHHHH") + # marked as deprecated, but does not raise DeprecationWarning + assert_raises(AssertionError, non_deprecated_func) + # should be silent + deprecated_func() + # fails if deprecated decorator just disables test. See #1453. + assert_raises(ValueError, deprecated_func2) + # first warnings is not a DeprecationWarning + assert_raises(AssertionError, deprecated_func3) + +if __name__ == '__main__': + run_module_suite() |