2001-01-17 17:51:36 -04:00
|
|
|
from test_support import verbose, TestFailed
|
2000-07-25 19:15:45 -03:00
|
|
|
|
|
|
|
if verbose:
|
2001-01-18 23:25:56 -04:00
|
|
|
print 'Running tests on argument handling'
|
2000-07-25 19:15:45 -03:00
|
|
|
|
|
|
|
try:
|
2001-02-19 19:53:42 -04:00
|
|
|
exec 'def f(a, a): pass'
|
2000-07-25 19:15:45 -03:00
|
|
|
raise TestFailed, "duplicate arguments"
|
|
|
|
except SyntaxError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
2001-02-19 19:53:42 -04:00
|
|
|
exec 'def f(a = 0, a = 1): pass'
|
2000-07-25 19:15:45 -03:00
|
|
|
raise TestFailed, "duplicate keyword arguments"
|
|
|
|
except SyntaxError:
|
|
|
|
pass
|
2001-01-18 23:25:56 -04:00
|
|
|
|
|
|
|
try:
|
2001-02-19 19:53:42 -04:00
|
|
|
exec 'def f(a): global a; a = 1'
|
2001-01-18 23:25:56 -04:00
|
|
|
raise TestFailed, "variable is global and local"
|
|
|
|
except SyntaxError:
|
|
|
|
pass
|
2001-02-19 19:53:42 -04:00
|
|
|
|
|
|
|
print "testing complex args"
|
|
|
|
|
|
|
|
def comp_args((a, b)):
|
2001-02-21 03:29:48 -04:00
|
|
|
print a,b
|
2001-02-19 19:53:42 -04:00
|
|
|
|
|
|
|
comp_args((1, 2))
|
|
|
|
|
|
|
|
def comp_args((a, b)=(3, 4)):
|
|
|
|
print a, b
|
|
|
|
|
|
|
|
comp_args((1, 2))
|
|
|
|
comp_args()
|
|
|
|
|
|
|
|
def comp_args(a, (b, c)):
|
|
|
|
print a, b, c
|
|
|
|
|
|
|
|
comp_args(1, (2, 3))
|
|
|
|
|
|
|
|
def comp_args(a=2, (b, c)=(3, 4)):
|
|
|
|
print a, b, c
|
|
|
|
|
|
|
|
comp_args(1, (2, 3))
|
|
|
|
comp_args()
|
|
|
|
|
|
|
|
try:
|
|
|
|
exec 'def f(a=1, (b, c)): pass'
|
|
|
|
raise TestFailed, "non-default args after default"
|
|
|
|
except SyntaxError:
|
|
|
|
pass
|
2001-08-27 16:19:28 -03:00
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print "testing bad float literals"
|
|
|
|
|
|
|
|
def expect_error(s):
|
|
|
|
try:
|
|
|
|
eval(s)
|
|
|
|
raise TestFailed("%r accepted" % s)
|
|
|
|
except SyntaxError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
expect_error("2e")
|
|
|
|
expect_error("2.0e+")
|
|
|
|
expect_error("1e-")
|
|
|
|
expect_error("3-4e/21")
|