~mwhudson/pypy/imported-builtinrefactor

« back to all changes in this revision

Viewing changes to pypy/interpreter/test/test_exceptcomp.py

  • Committer: hpk
  • Date: 2003-09-17 20:58:52 UTC
  • Revision ID: svn-v4:fd0d7bf2-dfb6-0310-8d31-b7ecfe96aada:pypy/branch/builtinrefactor:1357
the final merge of the builtinrefactor branch into the trunk.  See 

http://codespeak.net/pipermail/pypy-dev/2003q3/001012.html

for in-depth discussion and description of what is new. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Test comparisons of Exceptions in except clauses.
2
 
 
3
 
New for PyPy - Could be incorporated into CPython regression tests.
4
 
"""
5
 
import autopath
6
 
from pypy.tool import test
7
 
 
8
 
class TestExceptionComp(test.AppTestCase):
9
 
 
10
 
    def setUp(self):
11
 
        self.space = test.objspace()
12
 
 
13
 
### XXX - String exceptions depreciated?
14
 
##    def test_string(self):
15
 
##        string = "string"
16
 
##        try:
17
 
##            raise string
18
 
##        except string:
19
 
##            pass
20
 
##        except:
21
 
##            self.fail("Identical string exceptions do not match.") 
22
 
##
23
 
##    def test_stringfail(self):
24
 
##        string1 = "string1"
25
 
##        string1_ = "string" + "1"
26
 
##        assert string1 is not string1_
27
 
##        try:
28
 
##            raise string1
29
 
##        except "string2":
30
 
##            self.fail("Different string exceptions match.") 
31
 
##        except string1_:
32
 
##            self.fail("Non Identical string exceptions match.")
33
 
##        except string1:
34
 
##            pass
35
 
##        except:
36
 
##            self.fail("Unknown value for variable raise.")
37
 
            
38
 
 
39
 
    def test_exception(self):
40
 
        try:
41
 
            raise TypeError, "nothing"
42
 
        except TypeError:
43
 
            pass
44
 
        except:
45
 
            self.fail("Identical exceptions do not match.") 
46
 
 
47
 
    def test_exceptionfail(self):
48
 
        try:
49
 
            raise TypeError, "nothing"
50
 
        except KeyError:
51
 
            self.fail("Different exceptions match.")
52
 
        except TypeError:
53
 
            pass
54
 
        except:
55
 
            self.fail("Unanticipated value for exception raise.")
56
 
            
57
 
 
58
 
    def test_called(self):
59
 
        try:
60
 
            raise SyntaxError("Invalid")
61
 
        except SyntaxError:
62
 
            pass
63
 
        except:
64
 
            self.fail("Instantiated exception does not match parent class.") 
65
 
 
66
 
    def test_calledfail(self):
67
 
        try:
68
 
            raise SyntaxError("Invalid")
69
 
        except ZeroDivisionError:
70
 
            self.fail("Instantiated exception matches different parent class.") 
71
 
        except SyntaxError:
72
 
            pass
73
 
        except:
74
 
            self.fail("Unanticpated value for exception raise.")
75
 
            
76
 
        
77
 
    def test_userclass(self):
78
 
        class UserExcept(Exception):
79
 
            pass
80
 
        try:
81
 
            raise UserExcept, "nothing"
82
 
        except UserExcept:
83
 
            pass
84
 
        except:
85
 
            self.fail("User defined class exceptions do not match.") 
86
 
            
87
 
    def test_subclass(self):
88
 
        try:
89
 
            raise KeyError("key")
90
 
        except LookupError:
91
 
            pass
92
 
        except:
93
 
            self.fail("Exception does not match parent class.") 
94
 
 
95
 
    def test_deepsubclass(self):
96
 
        try:
97
 
            raise FloatingPointError("1.2r")
98
 
        except Exception:
99
 
            pass
100
 
        except:
101
 
            self.fail("Exception does not match grandparent class.") 
102
 
 
103
 
    def test_tuple(self):
104
 
        try:
105
 
            raise ArithmeticError("2+jack")
106
 
        except (ZeroDivisionError, ArithmeticError):
107
 
            pass
108
 
        except:
109
 
            self.fail("Exception does not match self in tuple.") 
110
 
 
111
 
    def test_parenttuple(self):
112
 
        try:
113
 
            raise ZeroDivisionError("0")
114
 
        except (StandardError, SystemExit):
115
 
            pass
116
 
        except:
117
 
            self.fail("Exception does not match parent in tuple.") 
118
 
 
119
 
    def test_nestedtuples(self):
120
 
        try:
121
 
            raise AssertionError("0")
122
 
        except (SystemExit, (KeyboardInterrupt, AssertionError)):
123
 
            pass
124
 
        except:
125
 
            self.fail("Exception does not match self in nested tuple.") 
126
 
 
127
 
    def test_deeptuples(self):
128
 
        try:
129
 
            raise IOError
130
 
        except (FloatingPointError,(OSError,
131
 
                                    (SyntaxError,IOError,ZeroDivisionError)),
132
 
                (MemoryError, NotImplementedError)):
133
 
            pass
134
 
        except:
135
 
            self.fail("Exception does not match self in deeply nested tuple.")
136
 
            
137
 
if __name__ == "__main__":
138
 
    test.main()