Show More
@@ -55,21 +55,23 b' class test_ctxmanager(unittest.TestCase)' | |||||
55 | def test_raise_on_enter(self): |
|
55 | def test_raise_on_enter(self): | |
56 | trace = [] |
|
56 | trace = [] | |
57 | addtrace = trace.append |
|
57 | addtrace = trace.append | |
58 | with self.assertRaises(ctxerror): |
|
58 | def go(): | |
59 | with ctxmanager(ctxmgr('a', addtrace), |
|
59 | with ctxmanager(ctxmgr('a', addtrace), | |
60 | lambda: raise_on_enter('b', addtrace)) as c: |
|
60 | lambda: raise_on_enter('b', addtrace)) as c: | |
61 | c.enter() |
|
61 | c.enter() | |
62 | addtrace('unreachable') |
|
62 | addtrace('unreachable') | |
|
63 | self.assertRaises(ctxerror, go) | |||
63 | self.assertEqual(trace, [('enter', 'a'), ('raise', 'b'), ('exit', 'a')]) |
|
64 | self.assertEqual(trace, [('enter', 'a'), ('raise', 'b'), ('exit', 'a')]) | |
64 |
|
65 | |||
65 | def test_raise_on_exit(self): |
|
66 | def test_raise_on_exit(self): | |
66 | trace = [] |
|
67 | trace = [] | |
67 | addtrace = trace.append |
|
68 | addtrace = trace.append | |
68 | with self.assertRaises(ctxerror): |
|
69 | def go(): | |
69 | with ctxmanager(ctxmgr('a', addtrace), |
|
70 | with ctxmanager(ctxmgr('a', addtrace), | |
70 | lambda: raise_on_exit('b', addtrace)) as c: |
|
71 | lambda: raise_on_exit('b', addtrace)) as c: | |
71 | c.enter() |
|
72 | c.enter() | |
72 | addtrace('running') |
|
73 | addtrace('running') | |
|
74 | self.assertRaises(ctxerror, go) | |||
73 | self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'), 'running', |
|
75 | self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'), 'running', | |
74 | ('raise', 'b'), ('exit', 'a')]) |
|
76 | ('raise', 'b'), ('exit', 'a')]) | |
75 |
|
77 |
General Comments 0
You need to be logged in to leave comments.
Login now