[Python-checkins] python/dist/src/Lib/test test_parser.py, 1.11.2.2, 1.11.2.3

nascheme@users.sourceforge.net nascheme at users.sourceforge.net
Tue Oct 11 23:37:32 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22615/Lib/test

Modified Files:
      Tag: ast-branch
	test_parser.py 
Log Message:
Implement PyNode_Compile() for the AST compiler.  Add some minimal tests
for parser.compilest().


Index: test_parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_parser.py,v
retrieving revision 1.11.2.2
retrieving revision 1.11.2.3
diff -u -d -r1.11.2.2 -r1.11.2.3
--- test_parser.py	7 Jan 2005 06:59:10 -0000	1.11.2.2
+++ test_parser.py	11 Oct 2005 21:37:28 -0000	1.11.2.3
@@ -397,10 +397,33 @@
                 (0, ''))
         self.check_bad_tree(tree, "malformed global ast")
 
+
+class CompileTestCase(unittest.TestCase):
+
+    # These tests are very minimal. :-(
+
+    def test_compile_expr(self):
+        st = parser.expr('2 + 3')
+        code = parser.compilest(st)
+        self.assertEquals(eval(code), 5)
+
+    def test_compile_suite(self):
+        st = parser.suite('x = 2; y = x + 3')
+        code = parser.compilest(st)
+        globs = {}
+        exec code in globs
+        self.assertEquals(globs['y'], 5)
+
+    def test_compile_error(self):
+        st = parser.suite('1 = 3 + 4')
+        self.assertRaises(SyntaxError, parser.compilest, st)
+
+
 def test_main():
     test_support.run_unittest(
         RoundtripLegalSyntaxTestCase,
-        IllegalSyntaxTestCase
+        IllegalSyntaxTestCase,
+        CompileTestCase,
     )
 
 



More information about the Python-checkins mailing list