Commits

desmaj committed aec8e90

fixed tests to run under python3

Comments (0)

Files changed (3)

     def render_BitAnd(self, node):
         return "&"
     
+    def render_arg(self, node):
+        return node.arg
+    
     def render_arguments(self, node):
         sep = ", "
         arg_parts = []

astkit/test/test_rendering.py

 import ast
+import sys
 
 import astkit.render
 
     
     roundtrips = ["""
 if (length == 5):
-    print 'five'
+    printf('five')
 """,
                   """
 if (length == 5):
-    print 'five'
+    printf('five')
 else:
-    print '17'
+    printf('17')
 """,
                   """
 if (length == 5):
-    print 'five'
+    printf('five')
 else:
     if (length == 4):
-        print 'four'
+        printf('four')
     else:
-        print '17'
+        printf('17')
 """,
                   """
 def func(a, b, c='c', *stargs, **kwargs):
     def test_elif(self):
         initial = """
 if (length == 5):
-    print 'five'
+    printf('five')
 elif (length == 4):
-    print 'four'
+    printf('four')
 else:
-    print '17'
+    printf('17')
 """.lstrip()
         expected = """
 if (length == 5):
-    print 'five'
+    printf('five')
 else:
     if (length == 4):
-        print 'four'
+        printf('four')
     else:
-        print '17'
+        printf('17')
 """.lstrip()
         actual = render_stmt(ast.parse(initial))
         assert expected == actual, \
                        ),
      ]
 
+
+if sys.version_info[0] < 3:
+    class TestPython2StatementRendering(NodeRenderingTestCase):
+        render = render_stmt
+        nodes = [
+            (ast.Exec(body=ast.Name(id="the_body"),
+                      globals=ast.Name(id="g_dict"),
+                      locals=ast.Name(id="l_dict")),
+             "exec the_body in g_dict, l_dict\n"),
+            
+            (ast.Exec(body=ast.Name(id="the_body"),
+                      locals=ast.Name(id="l_dict")),
+             "exec the_body in l_dict\n"),
+            
+             (ast.Print(dest=ast.Name(id='stdout'),
+                        values=[ast.Str(s='frog'),
+                                ast.Str('toad'),
+                                ast.Name(id='friends')],
+                        nl=False),
+              "print >>stdout, 'frog', 'toad', friends,\n"),
+             
+            ]
+
 class TestStatementRendering(NodeRenderingTestCase):
     render = render_stmt
     nodes = [(ast.Assert(test=ast.BinOp(left=ast.Num(n=5),
                "    result = 'No class'\n"
                "    return result\n")),
 
-             (ast.Exec(body=ast.Name(id="the_body"),
-                       globals=ast.Name(id="g_dict"),
-                       locals=ast.Name(id="l_dict")),
-              "exec the_body in g_dict, l_dict\n"),
-
-             (ast.Exec(body=ast.Name(id="the_body"),
-                       locals=ast.Name(id="l_dict")),
-              "exec the_body in l_dict\n"),
-
              (ast.Expr(value=ast.Call(func="a_funny_call",
                                       args=[],
                                       keywords=[])),
 
              (ast.Pass(), 'pass\n'),
 
-             (ast.Print(dest=ast.Name(id='stdout'),
-                        values=[ast.Str(s='frog'),
-                                ast.Str('toad'),
-                                ast.Name(id='friends')],
-                        nl=False),
-              "print >>stdout, 'frog', 'toad', friends,\n"),
-             
              (ast.Raise(type='Exception', inst='exc', tback='tb'),
               'raise Exception, exc, tb\n'),
 
                 "    return result\n")),
              
              ]
-    
+
+if sys.version_info[0] < 3:
+    class TestPython2ExpressionRendering(NodeRenderingTestCase):
+        render = render_expr
+        nodes = [
+            (ast.Repr(value=ast.Name(id="frogs")),
+             'repr(frogs)'),
+            
+            ]
+
 class TestExpressionRendering(NodeRenderingTestCase):
     render = render_expr
     nodes = [(ast.Add(),
 
              (ast.Pow(), '**'),
              
-             (ast.Repr(value=ast.Name(id="frogs")),
-              'repr(frogs)'),
-
              (ast.Slice(lower=ast.Num(n=1),
                         upper=ast.Num(n=4),
                         step=ast.Num(n=6)),
 from setuptools import setup, find_packages
 import sys, os
 
-version = '0.2'
+version = '0.3'
 
 setup(name='astkit',
       version=version,