summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-03-29 13:24:23 (GMT)
committerGeorg Brandl <georg@python.org>2008-03-29 13:24:23 (GMT)
commitf2bfd54d6f2acde253ae24805edf116c372bd81e (patch)
tree30964d80bd483e0c2a18b7e80638883cc52ad565 /Lib/test/test_compile.py
parentea13dc629caed2dd44b1ba5b611e1ba2ac1fd96f (diff)
downloadcpython-f2bfd54d6f2acde253ae24805edf116c372bd81e.zip
cpython-f2bfd54d6f2acde253ae24805edf116c372bd81e.tar.gz
cpython-f2bfd54d6f2acde253ae24805edf116c372bd81e.tar.bz2
Properly check for consistency with the third argument of
compile() when compiling an AST node.
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r--Lib/test/test_compile.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index ba55dfa..e8695ac 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -441,6 +441,20 @@ if 1:
self.assert_(type(ast) == _ast.Module)
co2 = compile(ast, '%s3' % fname, 'exec')
self.assertEqual(co1, co2)
+ # the code object's filename comes from the second compilation step
+ self.assertEqual(co2.co_filename, '%s3' % fname)
+
+ # raise exception when node type doesn't match with compile mode
+ co1 = compile('print 1', '<string>', 'exec', _ast.PyCF_ONLY_AST)
+ self.assertRaises(TypeError, compile, co1, '<ast>', 'eval')
+
+ # raise exception when node type is no start node
+ self.assertRaises(TypeError, compile, _ast.If(), '<ast>', 'exec')
+
+ # raise exception when node has invalid children
+ ast = _ast.Module()
+ ast.body = [_ast.BoolOp()]
+ self.assertRaises(TypeError, compile, ast, '<ast>', 'exec')
def test_main():