summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unparse.py
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2021-05-08 23:32:04 (GMT)
committerGitHub <noreply@github.com>2021-05-08 23:32:04 (GMT)
commit3d98ececda1335c7ed2a6c6a2b0d3bb46f2d3c55 (patch)
tree06e8fc589778b1456e87080873238e64f445dd45 /Lib/test/test_unparse.py
parenta0bd9e9c11f5f52c7ddd19144c8230da016b53c6 (diff)
downloadcpython-3d98ececda1335c7ed2a6c6a2b0d3bb46f2d3c55.zip
cpython-3d98ececda1335c7ed2a6c6a2b0d3bb46f2d3c55.tar.gz
cpython-3d98ececda1335c7ed2a6c6a2b0d3bb46f2d3c55.tar.bz2
bpo-43417: Better buffer handling for ast.unparse (GH-24772)
Diffstat (limited to 'Lib/test/test_unparse.py')
-rw-r--r--Lib/test/test_unparse.py35
1 files changed, 27 insertions, 8 deletions
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index 9f67b49..534431b 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -149,6 +149,27 @@ class UnparseTestCase(ASTTestCase):
# Tests for specific bugs found in earlier versions of unparse
def test_fstrings(self):
+ self.check_ast_roundtrip("f'a'")
+ self.check_ast_roundtrip("f'{{}}'")
+ self.check_ast_roundtrip("f'{{5}}'")
+ self.check_ast_roundtrip("f'{{5}}5'")
+ self.check_ast_roundtrip("f'X{{}}X'")
+ self.check_ast_roundtrip("f'{a}'")
+ self.check_ast_roundtrip("f'{ {1:2}}'")
+ self.check_ast_roundtrip("f'a{a}a'")
+ self.check_ast_roundtrip("f'a{a}{a}a'")
+ self.check_ast_roundtrip("f'a{a}a{a}a'")
+ self.check_ast_roundtrip("f'{a!r}x{a!s}12{{}}{a!a}'")
+ self.check_ast_roundtrip("f'{a:10}'")
+ self.check_ast_roundtrip("f'{a:100_000{10}}'")
+ self.check_ast_roundtrip("f'{a!r:10}'")
+ self.check_ast_roundtrip("f'{a:a{b}10}'")
+ self.check_ast_roundtrip(
+ "f'a{b}{c!s}{d!r}{e!a}{f:a}{g:a{b}}{h!s:a}"
+ "{j!s:{a}b}{k!s:a{b}c}{l!a:{b}c{d}}{x+y=}'"
+ )
+
+ def test_fstrings_special_chars(self):
# See issue 25180
self.check_ast_roundtrip(r"""f'{f"{0}"*3}'""")
self.check_ast_roundtrip(r"""f'{f"{y}"*3}'""")
@@ -323,15 +344,13 @@ class UnparseTestCase(ASTTestCase):
def test_invalid_raise(self):
self.check_invalid(ast.Raise(exc=None, cause=ast.Name(id="X")))
- def test_invalid_fstring_constant(self):
- self.check_invalid(ast.JoinedStr(values=[ast.Constant(value=100)]))
-
- def test_invalid_fstring_conversion(self):
+ def test_invalid_fstring_value(self):
self.check_invalid(
- ast.FormattedValue(
- value=ast.Constant(value="a", kind=None),
- conversion=ord("Y"), # random character
- format_spec=None,
+ ast.JoinedStr(
+ values=[
+ ast.Name(id="test"),
+ ast.Constant(value="test")
+ ]
)
)