Skip to content

Commit

Permalink
add tests for ast.parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Feb 18, 2025
1 parent 17a554f commit d344fba
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,61 @@ def test_repr_large_input_crash(self):
r"Exceeds the limit \(\d+ digits\)"):
repr(ast.Constant(value=eval(source)))

def test_pep_765_warnings(self):
srcs = [
textwrap.dedent("""
def f():
try:
pass
finally:
return 42
"""),
textwrap.dedent("""
for x in y:
try:
pass
finally:
break
"""),
textwrap.dedent("""
for x in y:
try:
pass
finally:
continue
"""),
]
for src in srcs:
with self.assertWarnsRegex(SyntaxWarning, 'finally'):
ast.parse(src)

def test_pep_765_no_warnings(self):
srcs = [
textwrap.dedent("""
try:
pass
finally:
def f():
return 42
"""),
textwrap.dedent("""
try:
pass
finally:
for x in y:
break
"""),
textwrap.dedent("""
try:
pass
finally:
for x in y:
continue
"""),
]
for src in srcs:
ast.parse(src)


class CopyTests(unittest.TestCase):
"""Test copying and pickling AST nodes."""
Expand Down

0 comments on commit d344fba

Please sign in to comment.