Merged revisions 79539 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79539 | florent.xicluna | 2010-04-01 01:01:03 +0300 (Thu, 01 Apr 2010) | 2 lines
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
........
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py
index 666d6c9..3f23af5 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_pep352.py
@@ -2,7 +2,7 @@
import __builtin__
import exceptions
import warnings
-from test.test_support import run_unittest
+from test.test_support import run_unittest, check_warnings
import os
import sys
from platform import system as platform_system
@@ -15,14 +15,13 @@
"catching classes that don't inherit from BaseException is not allowed",
"__get(item|slice)__ not supported for exception classes"])
+_deprecations = [(msg, DeprecationWarning) for msg in DEPRECATION_WARNINGS]
+
# Silence Py3k and other deprecation warnings
def ignore_deprecation_warnings(func):
"""Ignore the known DeprecationWarnings."""
def wrapper(*args, **kw):
- with warnings.catch_warnings():
- warnings.resetwarnings()
- for text in DEPRECATION_WARNINGS:
- warnings.filterwarnings("ignore", text, DeprecationWarning)
+ with check_warnings(*_deprecations, quiet=True):
return func(*args, **kw)
return wrapper
@@ -139,16 +138,8 @@
def test_message_deprecation(self):
# As of Python 2.6, BaseException.message is deprecated.
- with warnings.catch_warnings():
- warnings.resetwarnings()
- warnings.filterwarnings('error')
-
- try:
- BaseException().message
- except DeprecationWarning:
- pass
- else:
- self.fail("BaseException.message not deprecated")
+ with check_warnings(("", DeprecationWarning)):
+ BaseException().message
class UsageTests(unittest.TestCase):