summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-08-29 06:30:23 (GMT)
committerGitHub <noreply@github.com>2019-08-29 06:30:23 (GMT)
commite64f948e762a6b9fd02e2902ccf42438df6fcb61 (patch)
tree833c88bf7abd2b0ded10bd61468c0d238dedf514 /Lib/test/test_ast.py
parentb235a1b47394eedc5f8ea4cf214f56c4c6932e59 (diff)
downloadcpython-e64f948e762a6b9fd02e2902ccf42438df6fcb61.zip
cpython-e64f948e762a6b9fd02e2902ccf42438df6fcb61.tar.gz
cpython-e64f948e762a6b9fd02e2902ccf42438df6fcb61.tar.bz2
bpo-37950: Fix ast.dump() when call with incompletely initialized node. (GH-15510)
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 3d12397..07bbb4c 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -645,6 +645,35 @@ class ASTHelpers_Test(unittest.TestCase):
"lineno=1, col_offset=0, end_lineno=1, end_col_offset=24)], type_ignores=[])"
)
+ def test_dump_incomplete(self):
+ node = ast.Raise(lineno=3, col_offset=4)
+ self.assertEqual(ast.dump(node),
+ "Raise()"
+ )
+ self.assertEqual(ast.dump(node, include_attributes=True),
+ "Raise(lineno=3, col_offset=4)"
+ )
+ node = ast.Raise(exc=ast.Name(id='e', ctx=ast.Load()), lineno=3, col_offset=4)
+ self.assertEqual(ast.dump(node),
+ "Raise(exc=Name(id='e', ctx=Load()))"
+ )
+ self.assertEqual(ast.dump(node, annotate_fields=False),
+ "Raise(Name('e', Load()))"
+ )
+ self.assertEqual(ast.dump(node, include_attributes=True),
+ "Raise(exc=Name(id='e', ctx=Load()), lineno=3, col_offset=4)"
+ )
+ self.assertEqual(ast.dump(node, annotate_fields=False, include_attributes=True),
+ "Raise(Name('e', Load()), lineno=3, col_offset=4)"
+ )
+ node = ast.Raise(cause=ast.Name(id='e', ctx=ast.Load()))
+ self.assertEqual(ast.dump(node),
+ "Raise(cause=Name(id='e', ctx=Load()))"
+ )
+ self.assertEqual(ast.dump(node, annotate_fields=False),
+ "Raise(cause=Name('e', Load()))"
+ )
+
def test_copy_location(self):
src = ast.parse('1 + 1', mode='eval')
src.body.right = ast.copy_location(ast.Num(2), src.body.right)