summaryrefslogtreecommitdiff
path: root/numpy/testing
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2016-06-19 13:13:43 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2016-09-02 10:10:55 +0200
commit29a45efa15cf3992ab01b1535d51189319a7592d (patch)
treee673c38bf7c13100b6cda4febb42b816a4cc42f6 /numpy/testing
parenta93d9f7a97358e618aa52b2bbfa119317ee56d08 (diff)
downloadnumpy-29a45efa15cf3992ab01b1535d51189319a7592d.tar.gz
MAINT: Simplify deprecation test decorator
Also modify the corresponding test to suppress the non Deprecation warnings created to test specificity.
Diffstat (limited to 'numpy/testing')
-rw-r--r--numpy/testing/decorators.py13
-rw-r--r--numpy/testing/tests/test_decorators.py14
2 files changed, 12 insertions, 15 deletions
diff --git a/numpy/testing/decorators.py b/numpy/testing/decorators.py
index 6cde298e1..17400c0d5 100644
--- a/numpy/testing/decorators.py
+++ b/numpy/testing/decorators.py
@@ -15,10 +15,10 @@ function name, setup and teardown functions and so on - see
"""
from __future__ import division, absolute_import, print_function
-import warnings
import collections
-from .utils import SkipTest
+from .utils import SkipTest, assert_warns
+
def slow(t):
"""
@@ -251,15 +251,8 @@ def deprecated(conditional=True):
def _deprecated_imp(*args, **kwargs):
# Poor man's replacement for the with statement
- with warnings.catch_warnings(record=True) as l:
- warnings.simplefilter('always')
+ with assert_warns(DeprecationWarning):
f(*args, **kwargs)
- if not len(l) > 0:
- raise AssertionError("No warning raised when calling %s"
- % f.__name__)
- if not l[0].category is DeprecationWarning:
- raise AssertionError("First warning for %s is not a "
- "DeprecationWarning( is %s)" % (f.__name__, l[0]))
if isinstance(conditional, collections.Callable):
cond = conditional()
diff --git a/numpy/testing/tests/test_decorators.py b/numpy/testing/tests/test_decorators.py
index 7dbb5a828..721c0ef7e 100644
--- a/numpy/testing/tests/test_decorators.py
+++ b/numpy/testing/tests/test_decorators.py
@@ -1,8 +1,10 @@
from __future__ import division, absolute_import, print_function
+import warnings
+
from numpy.testing import (dec, assert_, assert_raises, run_module_suite,
SkipTest, KnownFailureException)
-import nose
+
def test_slow():
@dec.slow
@@ -172,10 +174,12 @@ def test_deprecated():
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)
+ with warnings.catch_warnings(record=True):
+ warnings.simplefilter("always") # do not propagate unrelated warnings
+ # fails if deprecated decorator just disables test. See #1453.
+ assert_raises(ValueError, deprecated_func2)
+ # warning is not a DeprecationWarning
+ assert_raises(AssertionError, deprecated_func3)
if __name__ == '__main__':