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