summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--as_string.py3
-rw-r--r--test/data/module2.py1
-rw-r--r--test/unittest_nodes.py25
3 files changed, 27 insertions, 2 deletions
diff --git a/as_string.py b/as_string.py
index 62ab5e84..3eeda096 100644
--- a/as_string.py
+++ b/as_string.py
@@ -395,7 +395,8 @@ class AsStringVisitor(object):
def visit_yield(self, node):
"""yield an ast.Yield node as string"""
- return 'yield %s' % node.value.accept(self)
+ yi_val = node.value and (" " + node.value.accept(self)) or ""
+ return 'yield' + yi_val
class AsStringVisitor3k(AsStringVisitor):
diff --git a/test/data/module2.py b/test/data/module2.py
index c8eba5e6..2b729c0d 100644
--- a/test/data/module2.py
+++ b/test/data/module2.py
@@ -81,6 +81,7 @@ exec 'c = 3' in {}, {}
def raise_string(a=2, *args, **kwargs):
raise Exception, 'yo'
yield 'coucou'
+ yield
a = (b) + (2)
c = (b) * (2)
c = (b) / (2)
diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py
index 22843230..944f8a80 100644
--- a/test/unittest_nodes.py
+++ b/test/unittest_nodes.py
@@ -34,7 +34,8 @@
import sys
from logilab.common import testlib
-from logilab.astng import builder, nodes, NotFoundError
+from logilab.astng.exceptions import ASTNGBuildingException, NotFoundError
+from logilab.astng import builder, nodes
from logilab.astng.as_string import as_string
from data import module as test_module
@@ -315,6 +316,28 @@ class ConstNodeTC(testlib.TestCase):
self._test(u'a')
+class NameNodeTC(testlib.TestCase):
+ def test_assign_to_True(self):
+ """test that True and False assignements don't crash"""
+ code = """True = False
+def hello(False):
+ pass
+del True
+ """
+ if sys.version_info >= (3, 0):
+ self.assertRaises(SyntaxError,#might become ASTNGBuildingException
+ abuilder.string_build, code)
+ else:
+ ast = abuilder.string_build(code)
+ ass_true = ast['True']
+ self.assertIsInstance(ass_true, nodes.AssName)
+ self.assertEqual(ass_true.name, "True")
+ del_true = ast.body[2].targets[0]
+ print ast.body[2], ast.body[2].targets
+ self.assertIsInstance(del_true, nodes.DelName)
+ self.assertEqual(del_true.name, "True")
+
+
class ArgumentsNodeTC(testlib.TestCase):
def test_linenumbering(self):
ast = abuilder.string_build('''