summaryrefslogtreecommitdiff
path: root/tests/run/with_statement_module_level_T536.pyx
blob: 506c362f9e93b8d30dd0b84a7987e5e80237bfe3 (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: 536

__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')