mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
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.)
This commit is contained in:
parent
b6429a2020
commit
e1578ce204
2 changed files with 34 additions and 1 deletions
|
@ -15,7 +15,12 @@ from test_support import verbose
|
|||
def roundtrip(f, s):
|
||||
st1 = f(s)
|
||||
t = st1.totuple()
|
||||
st2 = parser.sequence2ast(t)
|
||||
try:
|
||||
st2 = parser.sequence2ast(t)
|
||||
except parser.ParserError:
|
||||
print "Failing syntax tree:"
|
||||
pprint.pprint(t)
|
||||
raise
|
||||
|
||||
def roundtrip_fromfile(filename):
|
||||
roundtrip(suite, open(filename).read())
|
||||
|
@ -46,6 +51,18 @@ test_expr("foo(a, b, c, *args)")
|
|||
test_expr("foo(a, b, c, *args, **kw)")
|
||||
test_expr("foo(a, b, c, **kw)")
|
||||
test_expr("foo + bar")
|
||||
test_expr("lambda: 0")
|
||||
test_expr("lambda x: 0")
|
||||
test_expr("lambda *y: 0")
|
||||
test_expr("lambda *y, **z: 0")
|
||||
test_expr("lambda **z: 0")
|
||||
test_expr("lambda x, y: 0")
|
||||
test_expr("lambda foo=bar: 0")
|
||||
test_expr("lambda foo=bar, spaz=nifty+spit: 0")
|
||||
test_expr("lambda foo=bar, **z: 0")
|
||||
test_expr("lambda foo=bar, blaz=blat+2, **z: 0")
|
||||
test_expr("lambda foo=bar, blaz=blat+2, *y, **z: 0")
|
||||
test_expr("lambda x, *y, **z: 0")
|
||||
|
||||
print
|
||||
print "Statements:"
|
||||
|
@ -71,6 +88,8 @@ test_suite("a ^= b")
|
|||
test_suite("a <<= b")
|
||||
test_suite("a >>= b")
|
||||
test_suite("a **= b")
|
||||
test_suite("def f(): pass")
|
||||
test_suite("def f(foo=bar): pass")
|
||||
|
||||
#d = os.path.dirname(os.__file__)
|
||||
#roundtrip_fromfile(os.path.join(d, "os.py"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue