summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-01-07 06:02:19 (GMT)
committerFred Drake <fdrake@acm.org>2001-01-07 06:02:19 (GMT)
commite3fb18c1c47bda766c8e234368f4884cec1189ce (patch)
tree4e39db336003b9f91c0192e89bd906585854b597 /Lib
parent711370831afa0a50a2d4e59caebda622fc9fcb48 (diff)
downloadcpython-e3fb18c1c47bda766c8e234368f4884cec1189ce.zip
cpython-e3fb18c1c47bda766c8e234368f4884cec1189ce.tar.gz
cpython-e3fb18c1c47bda766c8e234368f4884cec1189ce.tar.bz2
Add more regression tests, including for the import statement variations.
These will detect regression on SF bug #127271 and other import statement bugs.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/output/test_parser25
-rw-r--r--Lib/test/test_parser.py45
2 files changed, 60 insertions, 10 deletions
diff --git a/Lib/test/output/test_parser b/Lib/test/output/test_parser
index 7558641..0381fb7 100644
--- a/Lib/test/output/test_parser
+++ b/Lib/test/output/test_parser
@@ -50,7 +50,32 @@ suite: a <<= b
suite: a >>= b
suite: a **= b
suite: def f(): pass
+suite: def f(*args): pass
+suite: def f(*args, **kw): pass
+suite: def f(**kw): pass
suite: def f(foo=bar): pass
+suite: def f(foo=bar, *args): pass
+suite: def f(foo=bar, *args, **kw): pass
+suite: def f(foo=bar, **kw): pass
+suite: def f(a, b): pass
+suite: def f(a, b, *args): pass
+suite: def f(a, b, *args, **kw): pass
+suite: def f(a, b, **kw): pass
+suite: def f(a, b, foo=bar): pass
+suite: def f(a, b, foo=bar, *args): pass
+suite: def f(a, b, foo=bar, *args, **kw): pass
+suite: def f(a, b, foo=bar, **kw): pass
+suite: from sys.path import *
+suite: from sys.path import dirname
+suite: from sys.path import dirname as my_dirname
+suite: from sys.path import dirname, basename
+suite: from sys.path import dirname as my_dirname, basename
+suite: from sys.path import dirname, basename as my_basename
+suite: import sys
+suite: import sys as system
+suite: import sys, math
+suite: import sys as system, math
+suite: import sys, math as my_math
Invalid parse trees:
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index bb22f6a..6885767 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -3,8 +3,7 @@ import parser
import pprint
import sys
-from parser import expr, suite, sequence2ast
-from test_support import verbose
+from test_support import TestFailed
#
# First, we test that we can generate trees from valid source fragments,
@@ -18,20 +17,18 @@ def roundtrip(f, s):
try:
st2 = parser.sequence2ast(t)
except parser.ParserError:
- print "Failing syntax tree:"
- pprint.pprint(t)
- raise
+ raise TestFailed, s
def roundtrip_fromfile(filename):
- roundtrip(suite, open(filename).read())
+ roundtrip(parser.suite, open(filename).read())
def test_expr(s):
print "expr:", s
- roundtrip(expr, s)
+ roundtrip(parser.expr, s)
def test_suite(s):
print "suite:", s
- roundtrip(suite, s)
+ roundtrip(parser.suite, s)
print "Expressions:"
@@ -88,8 +85,37 @@ 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(*args): pass")
+test_suite("def f(*args, **kw): pass")
+test_suite("def f(**kw): pass")
test_suite("def f(foo=bar): pass")
+test_suite("def f(foo=bar, *args): pass")
+test_suite("def f(foo=bar, *args, **kw): pass")
+test_suite("def f(foo=bar, **kw): pass")
+
+test_suite("def f(a, b): pass")
+test_suite("def f(a, b, *args): pass")
+test_suite("def f(a, b, *args, **kw): pass")
+test_suite("def f(a, b, **kw): pass")
+test_suite("def f(a, b, foo=bar): pass")
+test_suite("def f(a, b, foo=bar, *args): pass")
+test_suite("def f(a, b, foo=bar, *args, **kw): pass")
+test_suite("def f(a, b, foo=bar, **kw): pass")
+
+test_suite("from sys.path import *")
+test_suite("from sys.path import dirname")
+test_suite("from sys.path import dirname as my_dirname")
+test_suite("from sys.path import dirname, basename")
+test_suite("from sys.path import dirname as my_dirname, basename")
+test_suite("from sys.path import dirname, basename as my_basename")
+
+test_suite("import sys")
+test_suite("import sys as system")
+test_suite("import sys, math")
+test_suite("import sys as system, math")
+test_suite("import sys, math as my_math")
#d = os.path.dirname(os.__file__)
#roundtrip_fromfile(os.path.join(d, "os.py"))
@@ -107,10 +133,9 @@ def check_bad_tree(tree, label):
print
print label
try:
- sequence2ast(tree)
+ parser.sequence2ast(tree)
except parser.ParserError:
print "caught expected exception for invalid tree"
- pass
else:
print "test failed: did not properly detect invalid tree:"
pprint.pprint(tree)