[pypy-svn] r14218 - in pypy/dist/pypy/interpreter/pyparser: . test

adim at codespeak.net adim at codespeak.net
Mon Jul 4 15:56:47 CEST 2005


Author: adim
Date: Mon Jul  4 15:56:46 2005
New Revision: 14218

Modified:
   pypy/dist/pypy/interpreter/pyparser/pythonutil.py
   pypy/dist/pypy/interpreter/pyparser/test/test_samples.py
Log:
single inputs must be processed as exec statements



Modified: pypy/dist/pypy/interpreter/pyparser/pythonutil.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonutil.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonutil.py	Mon Jul  4 15:56:46 2005
@@ -11,7 +11,7 @@
 TARGET_DICT = {
     'exec'   : "file_input",
     'eval'   : "eval_input",
-    'single' : "single_input",
+    'single' : "file_input",
     }
 
 ## convenience functions around CPython's parser functions
@@ -27,11 +27,11 @@
     """parse python source using CPython's parser module and return
     nested tuples
     """
-    if mode == 'exec':
-        tp = parser.suite(source)
-    else:
+    if mode == 'eval':
         tp = parser.expr(source)
-    return tp.totuple()
+    else:
+        tp = parser.suite(source)
+    return parser.ast2tuple(tp, line_info=lineno)
 
 ## convenience functions around recparser functions
 def pypy_parsefile(filename, lineno=False):

Modified: pypy/dist/pypy/interpreter/pyparser/test/test_samples.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/test_samples.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/test/test_samples.py	Mon Jul  4 15:56:46 2005
@@ -100,6 +100,12 @@
     for snippet in snippets:
         yield check_parse_input, snippet, 'exec'
 
+def test_single_inputs():
+    snippets = ['a=1', 'True', 'def f(a):\n    return a+1\n\n']
+    for snippet in snippets:
+        yield check_parse_input, snippet, 'single'
+
+    
 def test_bad_inputs():
     inputs = ['x = (', 'x = (\n', 'x = (\n\n']
     for inp in inputs:



More information about the Pypy-commit mailing list