summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pep352.py
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-01-08 19:04:16 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-01-08 19:04:16 (GMT)
commitce8e33a095030e7af94f58f9da196b240bdf0476 (patch)
treeb0ba50cbb6e85c6be6f6e6a870e4232be50a0f9c /Lib/test/test_pep352.py
parent3ddc435af6873c6304058d7bcbcb19ee4fba7781 (diff)
downloadcpython-ce8e33a095030e7af94f58f9da196b240bdf0476.zip
cpython-ce8e33a095030e7af94f58f9da196b240bdf0476.tar.gz
cpython-ce8e33a095030e7af94f58f9da196b240bdf0476.tar.bz2
Reverting the Revision: 77368. I committed Flox's big patch for tests by
mistake. ( It may come in for sure tough)
Diffstat (limited to 'Lib/test/test_pep352.py')
-rw-r--r--Lib/test/test_pep352.py80
1 files changed, 37 insertions, 43 deletions
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py
index 103d835..c6d3a8d 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_pep352.py
@@ -6,23 +6,12 @@ from test.test_support import run_unittest
import os
from platform import system as platform_system
-DEPRECATION_WARNINGS = (
- "BaseException.message has been deprecated",
- "exceptions must derive from BaseException",
- "catching classes that don't inherit from BaseException is not allowed",
- "__getitem__ not supported for exception classes",
-)
-
-# 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)
- return func(*args, **kw)
- return wrapper
+def ignore_message_warning():
+ """Ignore the DeprecationWarning for BaseException.message."""
+ warnings.resetwarnings()
+ warnings.filterwarnings("ignore", "BaseException.message",
+ DeprecationWarning)
+
class ExceptionClassTests(unittest.TestCase):
@@ -32,12 +21,14 @@ class ExceptionClassTests(unittest.TestCase):
def test_builtins_new_style(self):
self.assertTrue(issubclass(Exception, object))
- @ignore_deprecation_warnings
def verify_instance_interface(self, ins):
- for attr in ("args", "message", "__str__", "__repr__", "__getitem__"):
- self.assertTrue(hasattr(ins, attr),
- "%s missing %s attribute" %
- (ins.__class__.__name__, attr))
+ with warnings.catch_warnings():
+ ignore_message_warning()
+ for attr in ("args", "message", "__str__", "__repr__",
+ "__getitem__"):
+ self.assertTrue(hasattr(ins, attr),
+ "%s missing %s attribute" %
+ (ins.__class__.__name__, attr))
def test_inheritance(self):
# Make sure the inheritance hierarchy matches the documentation
@@ -100,39 +91,43 @@ class ExceptionClassTests(unittest.TestCase):
self.assertEqual(given, expected, "%s: %s != %s" % (test_name,
given, expected))
- @ignore_deprecation_warnings
def test_interface_single_arg(self):
# Make sure interface works properly when given a single argument
arg = "spam"
exc = Exception(arg)
- results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg],
- [str(exc), str(arg)], [unicode(exc), unicode(arg)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)],
- [exc[0], arg])
- self.interface_test_driver(results)
+ with warnings.catch_warnings():
+ ignore_message_warning()
+ results = ([len(exc.args), 1], [exc.args[0], arg],
+ [exc.message, arg],
+ [str(exc), str(arg)], [unicode(exc), unicode(arg)],
+ [repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0],
+ arg])
+ self.interface_test_driver(results)
- @ignore_deprecation_warnings
def test_interface_multi_arg(self):
# Make sure interface correct when multiple arguments given
arg_count = 3
args = tuple(range(arg_count))
exc = Exception(*args)
- results = ([len(exc.args), arg_count], [exc.args, args],
- [exc.message, ''], [str(exc), str(args)],
- [unicode(exc), unicode(args)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)],
- [exc[-1], args[-1]])
- self.interface_test_driver(results)
-
- @ignore_deprecation_warnings
+ with warnings.catch_warnings():
+ ignore_message_warning()
+ results = ([len(exc.args), arg_count], [exc.args, args],
+ [exc.message, ''], [str(exc), str(args)],
+ [unicode(exc), unicode(args)],
+ [repr(exc), exc.__class__.__name__ + repr(exc.args)],
+ [exc[-1], args[-1]])
+ self.interface_test_driver(results)
+
def test_interface_no_arg(self):
# Make sure that with no args that interface is correct
exc = Exception()
- results = ([len(exc.args), 0], [exc.args, tuple()],
- [exc.message, ''],
- [str(exc), ''], [unicode(exc), u''],
- [repr(exc), exc.__class__.__name__ + '()'], [True, True])
- self.interface_test_driver(results)
+ with warnings.catch_warnings():
+ ignore_message_warning()
+ results = ([len(exc.args), 0], [exc.args, tuple()],
+ [exc.message, ''],
+ [str(exc), ''], [unicode(exc), u''],
+ [repr(exc), exc.__class__.__name__ + '()'], [True, True])
+ self.interface_test_driver(results)
def test_message_deprecation(self):
@@ -184,7 +179,6 @@ class UsageTests(unittest.TestCase):
self.fail("TypeError expected when catching %s as specified in a "
"tuple" % type(object_))
- @ignore_deprecation_warnings
def test_raise_classic(self):
# Raising a classic class is okay (for now).
class ClassicClass: