diff options
author | Georg Brandl <georg@python.org> | 2009-05-25 21:02:56 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-05-25 21:02:56 (GMT) |
commit | 944f684ce6f439bc868d4b189c45f726dfb9d3b1 (patch) | |
tree | 3fd9c596e78b01836158508978ce8eab678bb37b /Lib/test/test_compiler.py | |
parent | 04516611e7e4ceaef6fef9413719e9cb5b4bb087 (diff) | |
download | cpython-944f684ce6f439bc868d4b189c45f726dfb9d3b1.zip cpython-944f684ce6f439bc868d4b189c45f726dfb9d3b1.tar.gz cpython-944f684ce6f439bc868d4b189c45f726dfb9d3b1.tar.bz2 |
Allow multiple context managers in one with statement, as proposed
in http://codereview.appspot.com/53094 and accepted by Guido.
The construct is transformed into multiple With AST nodes so that
there should be no problems with the semantics.
Diffstat (limited to 'Lib/test/test_compiler.py')
-rw-r--r-- | Lib/test/test_compiler.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index 052e07e..f1fef74 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -165,6 +165,27 @@ class CompilerTest(unittest.TestCase): exec c in dct self.assertEquals(dct.get('result'), 1) + def testWithMult(self): + events = [] + class Ctx: + def __init__(self, n): + self.n = n + def __enter__(self): + events.append(self.n) + def __exit__(self, *args): + pass + c = compiler.compile('from __future__ import with_statement\n' + 'def f():\n' + ' with Ctx(1) as tc, Ctx(2) as tc2:\n' + ' return 1\n' + 'result = f()', + '<string>', + 'exec' ) + dct = {'Ctx': Ctx} + exec c in dct + self.assertEquals(dct.get('result'), 1) + self.assertEquals(events, [1, 2]) + def testGlobal(self): code = compiler.compile('global x\nx=1', '<string>', 'exec') d1 = {'__builtins__': {}} |