summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-09-09 16:33:13 (GMT)
committerGitHub <noreply@github.com>2019-09-09 16:33:13 (GMT)
commit850573b836d5b82d1a1ebe75a635aaa0a3dff997 (patch)
treeeb7aa5da66e0dfa0520104fac656ae93f3a12a34 /Lib/test/test_ast.py
parent92709a263e9cec0bc646ccc1ea051fc528800d8d (diff)
downloadcpython-850573b836d5b82d1a1ebe75a635aaa0a3dff997.zip
cpython-850573b836d5b82d1a1ebe75a635aaa0a3dff997.tar.gz
cpython-850573b836d5b82d1a1ebe75a635aaa0a3dff997.tar.bz2
bpo-37995: Add an option to ast.dump() to produce a multiline output. (GH-15631)
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 07bbb4c..47e259e 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -645,6 +645,68 @@ class ASTHelpers_Test(unittest.TestCase):
"lineno=1, col_offset=0, end_lineno=1, end_col_offset=24)], type_ignores=[])"
)
+ def test_dump_indent(self):
+ node = ast.parse('spam(eggs, "and cheese")')
+ self.assertEqual(ast.dump(node, indent=3), """\
+Module(
+ body=[
+ Expr(
+ value=Call(
+ func=Name(id='spam', ctx=Load()),
+ args=[
+ Name(id='eggs', ctx=Load()),
+ Constant(value='and cheese', kind=None)],
+ keywords=[]))],
+ type_ignores=[])""")
+ self.assertEqual(ast.dump(node, annotate_fields=False, indent='\t'), """\
+Module(
+\t[
+\t\tExpr(
+\t\t\tCall(
+\t\t\t\tName('spam', Load()),
+\t\t\t\t[
+\t\t\t\t\tName('eggs', Load()),
+\t\t\t\t\tConstant('and cheese', None)],
+\t\t\t\t[]))],
+\t[])""")
+ self.assertEqual(ast.dump(node, include_attributes=True, indent=3), """\
+Module(
+ body=[
+ Expr(
+ value=Call(
+ func=Name(
+ id='spam',
+ ctx=Load(),
+ lineno=1,
+ col_offset=0,
+ end_lineno=1,
+ end_col_offset=4),
+ args=[
+ Name(
+ id='eggs',
+ ctx=Load(),
+ lineno=1,
+ col_offset=5,
+ end_lineno=1,
+ end_col_offset=9),
+ Constant(
+ value='and cheese',
+ kind=None,
+ lineno=1,
+ col_offset=11,
+ end_lineno=1,
+ end_col_offset=23)],
+ keywords=[],
+ lineno=1,
+ col_offset=0,
+ end_lineno=1,
+ end_col_offset=24),
+ 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),