diff options
author | Ralf Gommers <ralf.gommers@googlemail.com> | 2013-07-16 12:28:18 -0700 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@googlemail.com> | 2013-07-16 12:28:18 -0700 |
commit | c067c156bf2ffb96d93083e468158ecbc35baba4 (patch) | |
tree | b73812a3a1a95a044c07c6352b5e254ffd792793 /numpy/testing/utils.py | |
parent | b55f2752140de3bd6969dd66960f649da44974a5 (diff) | |
parent | 05a15c8b621f953607429f3b67e079dfe1b439d6 (diff) | |
download | numpy-c067c156bf2ffb96d93083e468158ecbc35baba4.tar.gz |
Merge pull request #3520 from charris/replace-warningmanager
Replace use of WarningManager by warnings.catch_warnings and then deprecate it.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index ca564721a..bc0c59502 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -1365,6 +1365,8 @@ class WarningMessage(object): """ Holds the result of a single showwarning() call. + Deprecated in 1.8.0 + Notes ----- `WarningMessage` is copied from the Python 2.6 warnings module, @@ -1405,6 +1407,8 @@ class WarningManager(object): named 'warnings' and imported under that name. This argument is only useful when testing the warnings module itself. + Deprecated in 1.8.0 + Notes ----- `WarningManager` is a copy of the ``catch_warnings`` context manager @@ -1467,13 +1471,8 @@ def assert_warns(warning_class, func, *args, **kw): The value returned by `func`. """ - - # XXX: once we may depend on python >= 2.6, this can be replaced by the - # warnings module context manager. - ctx = WarningManager(record=True) - l = ctx.__enter__() - warnings.simplefilter('always') - try: + with warnings.catch_warnings(record=True) as l: + warnings.simplefilter('always') result = func(*args, **kw) if not len(l) > 0: raise AssertionError("No warning raised when calling %s" @@ -1481,8 +1480,6 @@ def assert_warns(warning_class, func, *args, **kw): if not l[0].category is warning_class: raise AssertionError("First warning for %s is not a " \ "%s( is %s)" % (func.__name__, warning_class, l[0])) - finally: - ctx.__exit__() return result def assert_no_warnings(func, *args, **kw): @@ -1503,18 +1500,12 @@ def assert_no_warnings(func, *args, **kw): The value returned by `func`. """ - # XXX: once we may depend on python >= 2.6, this can be replaced by the - # warnings module context manager. - ctx = WarningManager(record=True) - l = ctx.__enter__() - warnings.simplefilter('always') - try: + with warnings.catch_warnings(record=True) as l: + warnings.simplefilter('always') result = func(*args, **kw) if len(l) > 0: raise AssertionError("Got warnings when calling %s: %s" % (func.__name__, l)) - finally: - ctx.__exit__() return result |