Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1578ce

Browse files
committed
Added tests to avoid regression on bug #125375.
roundtrip(): Show the offending syntax tree when things break; this makes it a little easier to debug the module by adding test cases. (Still need better tests for this module, but there's not enough time today.)
1 parent b6429a2 commit e1578ce

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

Lib/test/output/test_parser

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ expr: foo(a, b, c, *args)
1515
expr: foo(a, b, c, *args, **kw)
1616
expr: foo(a, b, c, **kw)
1717
expr: foo + bar
18+
expr: lambda: 0
19+
expr: lambda x: 0
20+
expr: lambda *y: 0
21+
expr: lambda *y, **z: 0
22+
expr: lambda **z: 0
23+
expr: lambda x, y: 0
24+
expr: lambda foo=bar: 0
25+
expr: lambda foo=bar, spaz=nifty+spit: 0
26+
expr: lambda foo=bar, **z: 0
27+
expr: lambda foo=bar, blaz=blat+2, **z: 0
28+
expr: lambda foo=bar, blaz=blat+2, *y, **z: 0
29+
expr: lambda x, *y, **z: 0
1830

1931
Statements:
2032
suite: print
@@ -37,6 +49,8 @@ suite: a ^= b
3749
suite: a <<= b
3850
suite: a >>= b
3951
suite: a **= b
52+
suite: def f(): pass
53+
suite: def f(foo=bar): pass
4054

4155
Invalid parse trees:
4256

Lib/test/test_parser.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
def roundtrip(f, s):
1616
st1 = f(s)
1717
t = st1.totuple()
18-
st2 = parser.sequence2ast(t)
18+
try:
19+
st2 = parser.sequence2ast(t)
20+
except parser.ParserError:
21+
print "Failing syntax tree:"
22+
pprint.pprint(t)
23+
raise
1924

2025
def roundtrip_fromfile(filename):
2126
roundtrip(suite, open(filename).read())
@@ -46,6 +51,18 @@ def test_suite(s):
4651
test_expr("foo(a, b, c, *args, **kw)")
4752
test_expr("foo(a, b, c, **kw)")
4853
test_expr("foo + bar")
54+
test_expr("lambda: 0")
55+
test_expr("lambda x: 0")
56+
test_expr("lambda *y: 0")
57+
test_expr("lambda *y, **z: 0")
58+
test_expr("lambda **z: 0")
59+
test_expr("lambda x, y: 0")
60+
test_expr("lambda foo=bar: 0")
61+
test_expr("lambda foo=bar, spaz=nifty+spit: 0")
62+
test_expr("lambda foo=bar, **z: 0")
63+
test_expr("lambda foo=bar, blaz=blat+2, **z: 0")
64+
test_expr("lambda foo=bar, blaz=blat+2, *y, **z: 0")
65+
test_expr("lambda x, *y, **z: 0")
4966

5067
print
5168
print "Statements:"
@@ -71,6 +88,8 @@ def test_suite(s):
7188
test_suite("a <<= b")
7289
test_suite("a >>= b")
7390
test_suite("a **= b")
91+
test_suite("def f(): pass")
92+
test_suite("def f(foo=bar): pass")
7493

7594
#d = os.path.dirname(os.__file__)
7695
#roundtrip_fromfile(os.path.join(d, "os.py"))

0 commit comments

Comments
 (0)