File: test_exceptcomp.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (86 lines) | stat: -rw-r--r-- 2,399 bytes parent folder | download | duplicates (6)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Test comparisons of Exceptions in except clauses.

New for PyPy - Could be incorporated into CPython regression tests.
"""

class AppTestExceptionComp: 

    def test_exception(self):
        try:
            raise TypeError("nothing")
        except TypeError:
            pass
        except:
            self.fail("Identical exceptions do not match.") 

    def test_exceptionfail(self):
        try:
            raise TypeError("nothing")
        except KeyError:
            self.fail("Different exceptions match.")
        except TypeError:
            pass
        except:
            self.fail("Unanticipated value for exception raise.")
            

    def test_called(self):
        try:
            raise SyntaxError("Invalid")
        except SyntaxError:
            pass
        except:
            self.fail("Instantiated exception does not match parent class.") 

    def test_calledfail(self):
        try:
            raise SyntaxError("Invalid")
        except ZeroDivisionError:
            self.fail("Instantiated exception matches different parent class.") 
        except SyntaxError:
            pass
        except:
            self.fail("Unanticpated value for exception raise.")
            
        
    def test_userclass(self):
        class UserExcept(Exception):
            pass
        try:
            raise UserExcept("nothing")
        except UserExcept:
            pass
        except:
            self.fail("User defined class exceptions do not match.") 
            
    def test_subclass(self):
        try:
            raise KeyError("key")
        except LookupError:
            pass
        except:
            self.fail("Exception does not match parent class.") 

    def test_deepsubclass(self):
        try:
            raise FloatingPointError("1.2r")
        except Exception:
            pass
        except:
            self.fail("Exception does not match grandparent class.") 

    def test_tuple(self):
        try:
            raise ArithmeticError("2+jack")
        except (ZeroDivisionError, ArithmeticError):
            pass
        except:
            self.fail("Exception does not match self in tuple.") 

    def test_parenttuple(self):
        try:
            raise ZeroDivisionError("0")
        except (Exception, SystemExit):
            pass
        except:
            self.fail("Exception does not match parent in tuple.")