2 from test
.test_support
import run_unittest
5 class ExceptionTestCase(unittest
.TestCase
):
6 def test_try_except_else_finally(self
):
12 raise Exception, 'nyaa!'
20 self
.assertTrue(hit_except
)
21 self
.assertTrue(hit_finally
)
22 self
.assertFalse(hit_else
)
24 def test_try_except_else_finally_no_exception(self
):
38 self
.assertFalse(hit_except
)
39 self
.assertTrue(hit_finally
)
40 self
.assertTrue(hit_else
)
42 def test_try_except_finally(self
):
47 raise Exception, 'yarr!'
53 self
.assertTrue(hit_except
)
54 self
.assertTrue(hit_finally
)
56 def test_try_except_finally_no_exception(self
):
67 self
.assertFalse(hit_except
)
68 self
.assertTrue(hit_finally
)
70 def test_try_except(self
):
74 raise Exception, 'ahoy!'
78 self
.assertTrue(hit_except
)
80 def test_try_except_no_exception(self
):
88 self
.assertFalse(hit_except
)
90 def test_try_except_else(self
):
95 raise Exception, 'foo!'
101 self
.assertFalse(hit_else
)
102 self
.assertTrue(hit_except
)
104 def test_try_except_else_no_exception(self
):
115 self
.assertFalse(hit_except
)
116 self
.assertTrue(hit_else
)
118 def test_try_finally_no_exception(self
):
126 self
.assertTrue(hit_finally
)
128 def test_nested(self
):
130 hit_inner_except
= False
131 hit_inner_finally
= False
135 raise Exception, 'inner exception'
137 hit_inner_except
= True
139 hit_inner_finally
= True
143 self
.assertTrue(hit_inner_except
)
144 self
.assertTrue(hit_inner_finally
)
145 self
.assertTrue(hit_finally
)
147 def test_nested_else(self
):
151 hit_inner_except
= False
152 hit_inner_else
= False
158 hit_inner_except
= True
160 hit_inner_else
= True
162 raise Exception, 'outer exception'
170 self
.assertFalse(hit_inner_except
)
171 self
.assertTrue(hit_inner_else
)
172 self
.assertFalse(hit_else
)
173 self
.assertTrue(hit_finally
)
174 self
.assertTrue(hit_except
)
177 run_unittest(ExceptionTestCase
)
179 if __name__
== '__main__':