diff options
author | Georg Brandl <georg@python.org> | 2009-12-28 08:41:01 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-12-28 08:41:01 (GMT) |
commit | 1e28a27f845a59513ad3bebbd6ae19f399071bbd (patch) | |
tree | 22f39f9b43f61a56fbcca9327b968685159e7f00 /Lib | |
parent | 127d47092a98aa9b668dceb03c7b64d9c4c44adc (diff) | |
download | cpython-1e28a27f845a59513ad3bebbd6ae19f399071bbd.zip cpython-1e28a27f845a59513ad3bebbd6ae19f399071bbd.tar.gz cpython-1e28a27f845a59513ad3bebbd6ae19f399071bbd.tar.bz2 |
Merged revisions 77088 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77088 | georg.brandl | 2009-12-28 09:34:58 +0100 (Mo, 28 Dez 2009) | 1 line
#7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_exceptions.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 404b5d1..5be6757 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -618,6 +618,46 @@ class ExceptionTests(unittest.TestCase): tb2 = raiseMemError() self.assertEqual(tb1, tb2) + def test_exception_with_doc(self): + import _testcapi + doc2 = "This is a test docstring." + doc4 = "This is another test docstring." + + self.assertRaises(SystemError, _testcapi.make_exception_with_doc, + "error1") + + # test basic usage of PyErr_NewException + error1 = _testcapi.make_exception_with_doc("_testcapi.error1") + self.assertIs(type(error1), type) + self.assertTrue(issubclass(error1, Exception)) + self.assertIsNone(error1.__doc__) + + # test with given docstring + error2 = _testcapi.make_exception_with_doc("_testcapi.error2", doc2) + self.assertEqual(error2.__doc__, doc2) + + # test with explicit base (without docstring) + error3 = _testcapi.make_exception_with_doc("_testcapi.error3", + base=error2) + self.assertTrue(issubclass(error3, error2)) + + # test with explicit base tuple + class C(object): + pass + error4 = _testcapi.make_exception_with_doc("_testcapi.error4", doc4, + (error3, C)) + self.assertTrue(issubclass(error4, error3)) + self.assertTrue(issubclass(error4, C)) + self.assertEqual(error4.__doc__, doc4) + + # test with explicit dictionary + error5 = _testcapi.make_exception_with_doc("_testcapi.error5", "", + error4, {'a': 1}) + self.assertTrue(issubclass(error5, error4)) + self.assertEqual(error5.a, 1) + self.assertEqual(error5.__doc__, "") + + def test_main(): run_unittest(ExceptionTests) |