comparison tests/test-ctxmanager.py @ 27786:4a7dc29bfad8

test-ctxmanager: fix Python 2.6 compatibility problem
author Bryan O'Sullivan <bryano@fb.com>
date Thu, 14 Jan 2016 09:31:03 -0800
parents ba427b51f1d8
children 441491aba8c3
comparison
equal deleted inserted replaced
27785:ba427b51f1d8 27786:4a7dc29bfad8
53 ('exit', 'b'), ('exit', 'a')]) 53 ('exit', 'b'), ('exit', 'a')])
54 54
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
76 if __name__ == '__main__': 78 if __name__ == '__main__':
77 silenttestrunner.main(__name__) 79 silenttestrunner.main(__name__)