summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unparse.py
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2020-03-09 20:27:03 (GMT)
committerGitHub <noreply@github.com>2020-03-09 20:27:03 (GMT)
commite7cab7f780ac253999512ee86374fc3454342811 (patch)
tree99730c46952032d120813ab45075276e9c9459ef /Lib/test/test_unparse.py
parent111e4ee52a1739e7c7221adde2fc364ef4954af2 (diff)
downloadcpython-e7cab7f780ac253999512ee86374fc3454342811.zip
cpython-e7cab7f780ac253999512ee86374fc3454342811.tar.gz
cpython-e7cab7f780ac253999512ee86374fc3454342811.tar.bz2
bpo-38870: Simplify sequence interleaves in ast.unparse (GH-17892)
Diffstat (limited to 'Lib/test/test_unparse.py')
-rw-r--r--Lib/test/test_unparse.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index d33f32e..3d87cfb 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -280,6 +280,20 @@ class UnparseTestCase(ASTTestCase):
self.check_ast_roundtrip(r"""{**{'y': 2}, 'x': 1}""")
self.check_ast_roundtrip(r"""{**{'y': 2}, **{'x': 1}}""")
+ def test_ext_slices(self):
+ self.check_ast_roundtrip("a[i]")
+ self.check_ast_roundtrip("a[i,]")
+ self.check_ast_roundtrip("a[i, j]")
+ self.check_ast_roundtrip("a[()]")
+ self.check_ast_roundtrip("a[i:j]")
+ self.check_ast_roundtrip("a[:j]")
+ self.check_ast_roundtrip("a[i:]")
+ self.check_ast_roundtrip("a[i:j:k]")
+ self.check_ast_roundtrip("a[:j:k]")
+ self.check_ast_roundtrip("a[i::k]")
+ self.check_ast_roundtrip("a[i:j,]")
+ self.check_ast_roundtrip("a[i:j, k]")
+
def test_invalid_raise(self):
self.check_invalid(ast.Raise(exc=None, cause=ast.Name(id="X")))
@@ -310,6 +324,12 @@ class UnparseTestCase(ASTTestCase):
# check as Module docstrings for easy testing
self.check_ast_roundtrip(f"'{docstring}'")
+ def test_constant_tuples(self):
+ self.check_src_roundtrip(ast.Constant(value=(1,), kind=None), "(1,)")
+ self.check_src_roundtrip(
+ ast.Constant(value=(1, 2, 3), kind=None), "(1, 2, 3)"
+ )
+
class CosmeticTestCase(ASTTestCase):
"""Test if there are cosmetic issues caused by unnecesary additions"""
@@ -344,20 +364,6 @@ class CosmeticTestCase(ASTTestCase):
self.check_src_roundtrip("call((yield x))")
self.check_src_roundtrip("return x + (yield x)")
- def test_subscript(self):
- self.check_src_roundtrip("a[i]")
- self.check_src_roundtrip("a[i,]")
- self.check_src_roundtrip("a[i, j]")
- self.check_src_roundtrip("a[()]")
- self.check_src_roundtrip("a[i:j]")
- self.check_src_roundtrip("a[:j]")
- self.check_src_roundtrip("a[i:]")
- self.check_src_roundtrip("a[i:j:k]")
- self.check_src_roundtrip("a[:j:k]")
- self.check_src_roundtrip("a[i::k]")
- self.check_src_roundtrip("a[i:j,]")
- self.check_src_roundtrip("a[i:j, k]")
-
def test_docstrings(self):
docstrings = (
'"""simple doc string"""',