From 683184169940666d351cdbbd44ac6fb91040f1f9 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Mon, 1 Apr 2013 19:51:21 -0400 Subject: [PATCH] Adding in some tests for print --- hy/compiler.py | 8 ++++++++ tests/compilers/test_ast.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index c89340b..c744cb6 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -166,6 +166,14 @@ class HyASTCompiler(object): @builds("print") def compile_print_expression(self, expr): expr.pop(0) # print + if sys.version_info[0] >= 3: + # AST changed with Python 3, we now just call it. + return ast.Call( + func=ast.Name(id='print', ctx=ast.Load()), + args=[self.compile(x) for x in expr], + lineno=expr.start_line, + col_offset=expr.start_column) + return ast.Print( lineno=expr.start_line, col_offset=expr.start_column, diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 848fd69..f4e4bc4 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -20,7 +20,9 @@ from hy.compiler import hy_compile, HyCompileError from hy.lex import tokenize + import ast +import sys def _ast_spotcheck(arg, root, secondary): @@ -73,3 +75,12 @@ def test_ast_non_decoratable(): assert True == False except TypeError: pass + + +def test_ast_print(): + """ Ensure print doesn't suck. """ + code = hy_compile(tokenize("(print \"foo\")")).body[0] + if sys.version_info[0] >= 3: + assert type(code.value) == ast.Call + return + assert type(code) == ast.Print