1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
"""Misc. exception related tests
Made for Jython.
"""
from test import test_support
import unittest
class C:
def __str__(self):
raise Exception("E")
def __repr__(self):
raise Exception("S")
class ExceptionsTestCase(unittest.TestCase):
def test_keyerror_str(self):
self.assertEquals(str(KeyError()), '')
# Is actually repr(args[0])
self.assertEquals(str(KeyError('')), "''")
self.assertEquals(str(KeyError('', '')), "('', '')")
#From bugtests/test076.py
def test_raise_no_arg(self):
r = None
try:
try:
raise RuntimeError("dummy")
except RuntimeError:
raise
except RuntimeError, e:
r = str(e)
self.assertEquals(r, "dummy")
def testBugFix1149372(self):
try:
c = C()
str(c)
except Exception, e:
assert e.args[0] == "E"
return
unittest.fail("if __str__ raises an exception, re-raise")
def test_main():
test_support.run_unittest(ExceptionsTestCase)
if __name__ == '__main__':
test_main()
|