Skip to content

Commit d344fba

Browse files
committed
add tests for ast.parse()
1 parent 17a554f commit d344fba

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,61 @@ def test_repr_large_input_crash(self):
820820
r"Exceeds the limit \(\d+ digits\)"):
821821
repr(ast.Constant(value=eval(source)))
822822

823+
def test_pep_765_warnings(self):
824+
srcs = [
825+
textwrap.dedent("""
826+
def f():
827+
try:
828+
pass
829+
finally:
830+
return 42
831+
"""),
832+
textwrap.dedent("""
833+
for x in y:
834+
try:
835+
pass
836+
finally:
837+
break
838+
"""),
839+
textwrap.dedent("""
840+
for x in y:
841+
try:
842+
pass
843+
finally:
844+
continue
845+
"""),
846+
]
847+
for src in srcs:
848+
with self.assertWarnsRegex(SyntaxWarning, 'finally'):
849+
ast.parse(src)
850+
851+
def test_pep_765_no_warnings(self):
852+
srcs = [
853+
textwrap.dedent("""
854+
try:
855+
pass
856+
finally:
857+
def f():
858+
return 42
859+
"""),
860+
textwrap.dedent("""
861+
try:
862+
pass
863+
finally:
864+
for x in y:
865+
break
866+
"""),
867+
textwrap.dedent("""
868+
try:
869+
pass
870+
finally:
871+
for x in y:
872+
continue
873+
"""),
874+
]
875+
for src in srcs:
876+
ast.parse(src)
877+
823878

824879
class CopyTests(unittest.TestCase):
825880
"""Test copying and pickling AST nodes."""

0 commit comments

Comments
 (0)