##// END OF EJS Templates
util: rename ctxmanager's __call__ method to enter
Bryan O'Sullivan -
r27785:ba427b51 default
parent child Browse files
Show More
@@ -2655,7 +2655,7 b' class ctxmanager(object):'
2655 def __enter__(self):
2655 def __enter__(self):
2656 return self
2656 return self
2657
2657
2658 def __call__(self):
2658 def enter(self):
2659 '''Create and enter context managers in the order in which they were
2659 '''Create and enter context managers in the order in which they were
2660 passed to the constructor.'''
2660 passed to the constructor.'''
2661 values = []
2661 values = []
@@ -45,7 +45,7 b' class test_ctxmanager(unittest.TestCase)'
45 trace = []
45 trace = []
46 addtrace = trace.append
46 addtrace = trace.append
47 with ctxmanager(ctxmgr('a', addtrace), ctxmgr('b', addtrace)) as c:
47 with ctxmanager(ctxmgr('a', addtrace), ctxmgr('b', addtrace)) as c:
48 a, b = c()
48 a, b = c.enter()
49 c.atexit(addtrace, ('atexit', 'x'))
49 c.atexit(addtrace, ('atexit', 'x'))
50 c.atexit(addtrace, ('atexit', 'y'))
50 c.atexit(addtrace, ('atexit', 'y'))
51 self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'),
51 self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'),
@@ -58,7 +58,7 b' class test_ctxmanager(unittest.TestCase)'
58 with self.assertRaises(ctxerror):
58 with self.assertRaises(ctxerror):
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()
61 c.enter()
62 addtrace('unreachable')
62 addtrace('unreachable')
63 self.assertEqual(trace, [('enter', 'a'), ('raise', 'b'), ('exit', 'a')])
63 self.assertEqual(trace, [('enter', 'a'), ('raise', 'b'), ('exit', 'a')])
64
64
@@ -68,7 +68,7 b' class test_ctxmanager(unittest.TestCase)'
68 with self.assertRaises(ctxerror):
68 with self.assertRaises(ctxerror):
69 with ctxmanager(ctxmgr('a', addtrace),
69 with ctxmanager(ctxmgr('a', addtrace),
70 lambda: raise_on_exit('b', addtrace)) as c:
70 lambda: raise_on_exit('b', addtrace)) as c:
71 c()
71 c.enter()
72 addtrace('running')
72 addtrace('running')
73 self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'), 'running',
73 self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'), 'running',
74 ('raise', 'b'), ('exit', 'a')])
74 ('raise', 'b'), ('exit', 'a')])
General Comments 0
You need to be logged in to leave comments. Login now