summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compiler.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-01-27 17:43:02 (GMT)
committerGeorg Brandl <georg@python.org>2007-01-27 17:43:02 (GMT)
commitab49684f550ce6b12614b8a329f4d280e20e1277 (patch)
treef813125ca6d4bbda770e4e3566e470069f917f09 /Lib/test/test_compiler.py
parent7a7cbae77b417b855bdfe5f7c536893cbefcbb1d (diff)
downloadcpython-ab49684f550ce6b12614b8a329f4d280e20e1277.zip
cpython-ab49684f550ce6b12614b8a329f4d280e20e1277.tar.gz
cpython-ab49684f550ce6b12614b8a329f4d280e20e1277.tar.bz2
Patch #1638243: the compiler package is now able to correctly compile
a with statement; previously, executing code containing a with statement compiled by the compiler package crashed the interpreter.
Diffstat (limited to 'Lib/test/test_compiler.py')
-rw-r--r--Lib/test/test_compiler.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
index 81f2ea8..229d8a3 100644
--- a/Lib/test/test_compiler.py
+++ b/Lib/test/test_compiler.py
@@ -7,6 +7,12 @@ from random import random
# How much time in seconds can pass before we print a 'Still working' message.
_PRINT_WORKING_MSG_INTERVAL = 5 * 60
+class TrivialContext(object):
+ def __enter__(self):
+ return self
+ def __exit__(self, *exc_info):
+ pass
+
class CompilerTest(unittest.TestCase):
def testCompileLibrary(self):
@@ -123,6 +129,31 @@ class CompilerTest(unittest.TestCase):
'eval')
self.assertEquals(eval(c), [(0, 3), (1, 3), (2, 3)])
+ def testWith(self):
+ # SF bug 1638243
+ c = compiler.compile('from __future__ import with_statement\n'
+ 'def f():\n'
+ ' with TrivialContext():\n'
+ ' return 1\n'
+ 'result = f()',
+ '<string>',
+ 'exec' )
+ dct = {'TrivialContext': TrivialContext}
+ exec c in dct
+ self.assertEquals(dct.get('result'), 1)
+
+ def testWithAss(self):
+ c = compiler.compile('from __future__ import with_statement\n'
+ 'def f():\n'
+ ' with TrivialContext() as tc:\n'
+ ' return 1\n'
+ 'result = f()',
+ '<string>',
+ 'exec' )
+ dct = {'TrivialContext': TrivialContext}
+ exec c in dct
+ self.assertEquals(dct.get('result'), 1)
+
NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)