Skip to content

Commit 2282ccc

Browse files
committed
Move AST test to test_ast
1 parent a595ccc commit 2282ccc

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,25 @@ def f():
880880
for src in srcs:
881881
ast.parse(src)
882882

883+
def test_tstring(self):
884+
# Test AST structure for simple t-string
885+
tree = ast.parse('t"Hello"')
886+
self.assertIsInstance(tree.body[0].value, ast.TemplateStr)
887+
self.assertIsInstance(tree.body[0].value.values[0], ast.Constant)
888+
889+
# Test AST for t-string with interpolation
890+
tree = ast.parse('t"Hello {name}"')
891+
self.assertIsInstance(tree.body[0].value, ast.TemplateStr)
892+
self.assertIsInstance(tree.body[0].value.values[0], ast.Constant)
893+
self.assertIsInstance(tree.body[0].value.values[1], ast.Interpolation)
894+
895+
# Test AST for implicit concat of t-string with f-string
896+
tree = ast.parse('t"Hello {name}" f"{name}"')
897+
self.assertIsInstance(tree.body[0].value, ast.TemplateStr)
898+
self.assertIsInstance(tree.body[0].value.values[0], ast.Constant)
899+
self.assertIsInstance(tree.body[0].value.values[1], ast.Interpolation)
900+
self.assertIsInstance(tree.body[0].value.values[2], ast.FormattedValue)
901+
883902

884903
class CopyTests(unittest.TestCase):
885904
"""Test copying and pickling AST nodes."""

Lib/test/test_tstring.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,6 @@ def test_nested_templates(self):
202202
self.assertEqual(t_interp.conversion, None)
203203
self.assertEqual(t_interp.format_spec, "")
204204

205-
def test_ast_structure(self):
206-
# Test AST structure for simple t-string
207-
tree = ast.parse('t"Hello"')
208-
self.assertIsInstance(tree.body[0].value, ast.TemplateStr)
209-
self.assertIsInstance(tree.body[0].value.values[0], ast.Constant)
210-
211-
# Test AST for t-string with interpolation
212-
tree = ast.parse('t"Hello {name}"')
213-
self.assertIsInstance(tree.body[0].value, ast.TemplateStr)
214-
self.assertIsInstance(tree.body[0].value.values[0], ast.Constant)
215-
self.assertIsInstance(tree.body[0].value.values[1], ast.Interpolation)
216-
217205
def test_syntax_errors(self):
218206
for case, err in (
219207
("t'", "unterminated t-string literal"),

0 commit comments

Comments
 (0)