diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-07-11 20:29:08 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-07-12 07:27:07 -0600 |
commit | 05a15c8b621f953607429f3b67e079dfe1b439d6 (patch) | |
tree | c3c851bffa1d85399b4547f2a1620ad87c2c07bc /numpy/testing/utils.py | |
parent | a053a4372aba0af0bd63ffd5e207baf469cfc7bf (diff) | |
download | numpy-05a15c8b621f953607429f3b67e079dfe1b439d6.tar.gz |
MAINT: Remove uses of the WarningManager class.
WarningManager was a workaround for the lack of the with statement
in Python versions < 2.6. As those versions are no longer supported
it can be removed.
Deprecation notes are added to WarningManager and WarningMessage, but
to avoid a cascade of messages in third party apps, no warnings are
raised at this time, that can be done later.
Closes #3519.
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 |