1
"""Test comparisons of Exceptions in except clauses.
3
New for PyPy - Could be incorporated into CPython regression tests.
6
from pypy.tool import test
8
class TestExceptionComp(test.AppTestCase):
11
self.space = test.objspace()
13
### XXX - String exceptions depreciated?
14
## def test_string(self):
21
## self.fail("Identical string exceptions do not match.")
23
## def test_stringfail(self):
24
## string1 = "string1"
25
## string1_ = "string" + "1"
26
## assert string1 is not string1_
30
## self.fail("Different string exceptions match.")
32
## self.fail("Non Identical string exceptions match.")
36
## self.fail("Unknown value for variable raise.")
39
def test_exception(self):
41
raise TypeError, "nothing"
45
self.fail("Identical exceptions do not match.")
47
def test_exceptionfail(self):
49
raise TypeError, "nothing"
51
self.fail("Different exceptions match.")
55
self.fail("Unanticipated value for exception raise.")
58
def test_called(self):
60
raise SyntaxError("Invalid")
64
self.fail("Instantiated exception does not match parent class.")
66
def test_calledfail(self):
68
raise SyntaxError("Invalid")
69
except ZeroDivisionError:
70
self.fail("Instantiated exception matches different parent class.")
74
self.fail("Unanticpated value for exception raise.")
77
def test_userclass(self):
78
class UserExcept(Exception):
81
raise UserExcept, "nothing"
85
self.fail("User defined class exceptions do not match.")
87
def test_subclass(self):
93
self.fail("Exception does not match parent class.")
95
def test_deepsubclass(self):
97
raise FloatingPointError("1.2r")
101
self.fail("Exception does not match grandparent class.")
103
def test_tuple(self):
105
raise ArithmeticError("2+jack")
106
except (ZeroDivisionError, ArithmeticError):
109
self.fail("Exception does not match self in tuple.")
111
def test_parenttuple(self):
113
raise ZeroDivisionError("0")
114
except (StandardError, SystemExit):
117
self.fail("Exception does not match parent in tuple.")
119
def test_nestedtuples(self):
121
raise AssertionError("0")
122
except (SystemExit, (KeyboardInterrupt, AssertionError)):
125
self.fail("Exception does not match self in nested tuple.")
127
def test_deeptuples(self):
130
except (FloatingPointError,(OSError,
131
(SyntaxError,IOError,ZeroDivisionError)),
132
(MemoryError, NotImplementedError)):
135
self.fail("Exception does not match self in deeply nested tuple.")
137
if __name__ == "__main__":