blob: a18925f46588dc4ee9a812e661ffb0fdf8bb2884 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# ticket: t536
__doc__ = """
>>> inner_result
['ENTER']
>>> result # doctest: +ELLIPSIS
['ENTER', ...EXIT (<...ValueError...>,...ValueError..., <traceback object at ...)...]
>>> inner_result_no_exc
['ENTER']
>>> result_no_exc
['ENTER', 'EXIT (None, None, None)']
"""
class ContextManager(object):
def __init__(self, result):
self.result = result
def __enter__(self):
self.result.append("ENTER")
def __exit__(self, *values):
self.result.append("EXIT %r" % (values,))
return True
result_no_exc = []
with ContextManager(result_no_exc) as c:
inner_result_no_exc = result_no_exc[:]
result = []
with ContextManager(result) as c:
inner_result = result[:]
raise ValueError('TEST')
|