ยปCore Development>Code coverage>Lib/test/test_exception_variations.py

Python code coverage for Lib/test/test_exception_variations.py

#countcontent
1n/a
2n/aimport unittest
3n/a
4n/aclass ExceptionTestCase(unittest.TestCase):
5n/a def test_try_except_else_finally(self):
6n/a hit_except = False
7n/a hit_else = False
8n/a hit_finally = False
9n/a
10n/a try:
11n/a raise Exception('nyaa!')
12n/a except:
13n/a hit_except = True
14n/a else:
15n/a hit_else = True
16n/a finally:
17n/a hit_finally = True
18n/a
19n/a self.assertTrue(hit_except)
20n/a self.assertTrue(hit_finally)
21n/a self.assertFalse(hit_else)
22n/a
23n/a def test_try_except_else_finally_no_exception(self):
24n/a hit_except = False
25n/a hit_else = False
26n/a hit_finally = False
27n/a
28n/a try:
29n/a pass
30n/a except:
31n/a hit_except = True
32n/a else:
33n/a hit_else = True
34n/a finally:
35n/a hit_finally = True
36n/a
37n/a self.assertFalse(hit_except)
38n/a self.assertTrue(hit_finally)
39n/a self.assertTrue(hit_else)
40n/a
41n/a def test_try_except_finally(self):
42n/a hit_except = False
43n/a hit_finally = False
44n/a
45n/a try:
46n/a raise Exception('yarr!')
47n/a except:
48n/a hit_except = True
49n/a finally:
50n/a hit_finally = True
51n/a
52n/a self.assertTrue(hit_except)
53n/a self.assertTrue(hit_finally)
54n/a
55n/a def test_try_except_finally_no_exception(self):
56n/a hit_except = False
57n/a hit_finally = False
58n/a
59n/a try:
60n/a pass
61n/a except:
62n/a hit_except = True
63n/a finally:
64n/a hit_finally = True
65n/a
66n/a self.assertFalse(hit_except)
67n/a self.assertTrue(hit_finally)
68n/a
69n/a def test_try_except(self):
70n/a hit_except = False
71n/a
72n/a try:
73n/a raise Exception('ahoy!')
74n/a except:
75n/a hit_except = True
76n/a
77n/a self.assertTrue(hit_except)
78n/a
79n/a def test_try_except_no_exception(self):
80n/a hit_except = False
81n/a
82n/a try:
83n/a pass
84n/a except:
85n/a hit_except = True
86n/a
87n/a self.assertFalse(hit_except)
88n/a
89n/a def test_try_except_else(self):
90n/a hit_except = False
91n/a hit_else = False
92n/a
93n/a try:
94n/a raise Exception('foo!')
95n/a except:
96n/a hit_except = True
97n/a else:
98n/a hit_else = True
99n/a
100n/a self.assertFalse(hit_else)
101n/a self.assertTrue(hit_except)
102n/a
103n/a def test_try_except_else_no_exception(self):
104n/a hit_except = False
105n/a hit_else = False
106n/a
107n/a try:
108n/a pass
109n/a except:
110n/a hit_except = True
111n/a else:
112n/a hit_else = True
113n/a
114n/a self.assertFalse(hit_except)
115n/a self.assertTrue(hit_else)
116n/a
117n/a def test_try_finally_no_exception(self):
118n/a hit_finally = False
119n/a
120n/a try:
121n/a pass
122n/a finally:
123n/a hit_finally = True
124n/a
125n/a self.assertTrue(hit_finally)
126n/a
127n/a def test_nested(self):
128n/a hit_finally = False
129n/a hit_inner_except = False
130n/a hit_inner_finally = False
131n/a
132n/a try:
133n/a try:
134n/a raise Exception('inner exception')
135n/a except:
136n/a hit_inner_except = True
137n/a finally:
138n/a hit_inner_finally = True
139n/a finally:
140n/a hit_finally = True
141n/a
142n/a self.assertTrue(hit_inner_except)
143n/a self.assertTrue(hit_inner_finally)
144n/a self.assertTrue(hit_finally)
145n/a
146n/a def test_nested_else(self):
147n/a hit_else = False
148n/a hit_finally = False
149n/a hit_except = False
150n/a hit_inner_except = False
151n/a hit_inner_else = False
152n/a
153n/a try:
154n/a try:
155n/a pass
156n/a except:
157n/a hit_inner_except = True
158n/a else:
159n/a hit_inner_else = True
160n/a
161n/a raise Exception('outer exception')
162n/a except:
163n/a hit_except = True
164n/a else:
165n/a hit_else = True
166n/a finally:
167n/a hit_finally = True
168n/a
169n/a self.assertFalse(hit_inner_except)
170n/a self.assertTrue(hit_inner_else)
171n/a self.assertFalse(hit_else)
172n/a self.assertTrue(hit_finally)
173n/a self.assertTrue(hit_except)
174n/a
175n/aif __name__ == '__main__':
176n/a unittest.main()