add extra tests to verify that co_varnames is being set up properly
also normalize checks for syntax errors and delete commented out definition of verify.
This commit is contained in:
parent
a6ebc4841d
commit
92e9f29aec
|
@ -24,6 +24,8 @@ extended print_stmt
|
||||||
1 2 3
|
1 2 3
|
||||||
1 1 1
|
1 1 1
|
||||||
hello world
|
hello world
|
||||||
|
SyntaxError expected for "print ,"
|
||||||
|
SyntaxError expected for "print >> x,"
|
||||||
del_stmt
|
del_stmt
|
||||||
pass_stmt
|
pass_stmt
|
||||||
flow_stmt
|
flow_stmt
|
||||||
|
@ -56,6 +58,6 @@ classdef
|
||||||
[(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'), (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'), (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'), (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'), (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')]
|
[(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'), (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'), (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'), (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'), (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')]
|
||||||
[(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), (5, 'Banana'), (5, 'Coconut')]
|
[(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), (5, 'Banana'), (5, 'Coconut')]
|
||||||
[0, 0, 0]
|
[0, 0, 0]
|
||||||
good: got a SyntaxError as expected
|
SyntaxError expected for "[i, s for i in nums for s in strs]"
|
||||||
good: got a SyntaxError as expected
|
SyntaxError expected for "[x if y]"
|
||||||
[('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]
|
[('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]
|
||||||
|
|
|
@ -3,6 +3,14 @@
|
||||||
|
|
||||||
from test_support import *
|
from test_support import *
|
||||||
|
|
||||||
|
def check_syntax(statement):
|
||||||
|
try:
|
||||||
|
compile(statement, '<string>', 'exec')
|
||||||
|
except SyntaxError:
|
||||||
|
print 'SyntaxError expected for "%s"' % statement
|
||||||
|
else:
|
||||||
|
print 'Missing SyntaxError: "%s"' % statement
|
||||||
|
|
||||||
print '1. Parser'
|
print '1. Parser'
|
||||||
|
|
||||||
print '1.1 Tokens'
|
print '1.1 Tokens'
|
||||||
|
@ -83,9 +91,6 @@ x = 3.1e4
|
||||||
|
|
||||||
print '1.1.3 String literals'
|
print '1.1.3 String literals'
|
||||||
|
|
||||||
##def verify(s):
|
|
||||||
## if not s: raise TestFailed, 'see traceback'
|
|
||||||
|
|
||||||
x = ''; y = ""; verify(len(x) == 0 and x == y)
|
x = ''; y = ""; verify(len(x) == 0 and x == y)
|
||||||
x = '\''; y = "'"; verify(len(x) == 1 and x == y and ord(x) == 39)
|
x = '\''; y = "'"; verify(len(x) == 1 and x == y and ord(x) == 39)
|
||||||
x = '"'; y = "\""; verify(len(x) == 1 and x == y and ord(x) == 34)
|
x = '"'; y = "\""; verify(len(x) == 1 and x == y and ord(x) == 34)
|
||||||
|
@ -154,12 +159,20 @@ f1(*(), **{})
|
||||||
def f2(one_argument): pass
|
def f2(one_argument): pass
|
||||||
def f3(two, arguments): pass
|
def f3(two, arguments): pass
|
||||||
def f4(two, (compound, (argument, list))): pass
|
def f4(two, (compound, (argument, list))): pass
|
||||||
|
def f5((compound, first), two): pass
|
||||||
|
verify(f2.func_code.co_varnames == ('one_argument',))
|
||||||
|
verify(f3.func_code.co_varnames == ('two', 'arguments'))
|
||||||
|
verify(f4.func_code.co_varnames == ('two', '.2', 'compound', 'argument',
|
||||||
|
'list'))
|
||||||
|
verify(f5.func_code.co_varnames == ('.0', 'two', 'compound', 'first'))
|
||||||
def a1(one_arg,): pass
|
def a1(one_arg,): pass
|
||||||
def a2(two, args,): pass
|
def a2(two, args,): pass
|
||||||
def v0(*rest): pass
|
def v0(*rest): pass
|
||||||
def v1(a, *rest): pass
|
def v1(a, *rest): pass
|
||||||
def v2(a, b, *rest): pass
|
def v2(a, b, *rest): pass
|
||||||
def v3(a, (b, c), *rest): pass
|
def v3(a, (b, c), *rest): return a, b, c, rest
|
||||||
|
verify(v3.func_code.co_varnames == ('a', '.2', 'rest', 'b', 'c'))
|
||||||
|
verify(v3(1, (2, 3), 4) == (1, 2, 3, (4,)))
|
||||||
def d01(a=1): pass
|
def d01(a=1): pass
|
||||||
d01()
|
d01()
|
||||||
d01(1)
|
d01(1)
|
||||||
|
@ -302,13 +315,6 @@ def tellme(file=None):
|
||||||
driver()
|
driver()
|
||||||
|
|
||||||
# syntax errors
|
# syntax errors
|
||||||
def check_syntax(statement):
|
|
||||||
try:
|
|
||||||
compile(statement, '<string>', 'exec')
|
|
||||||
except SyntaxError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print 'Missing SyntaxError: "%s"' % statement
|
|
||||||
check_syntax('print ,')
|
check_syntax('print ,')
|
||||||
check_syntax('print >> x,')
|
check_syntax('print >> x,')
|
||||||
|
|
||||||
|
@ -618,17 +624,8 @@ def test_in_func(l):
|
||||||
|
|
||||||
print test_in_func(nums)
|
print test_in_func(nums)
|
||||||
|
|
||||||
try:
|
check_syntax("[i, s for i in nums for s in strs]")
|
||||||
eval("[i, s for i in nums for s in strs]")
|
check_syntax("[x if y]")
|
||||||
print "FAIL: should have raised a SyntaxError!"
|
|
||||||
except SyntaxError:
|
|
||||||
print "good: got a SyntaxError as expected"
|
|
||||||
|
|
||||||
try:
|
|
||||||
eval("[x if y]")
|
|
||||||
print "FAIL: should have raised a SyntaxError!"
|
|
||||||
except SyntaxError:
|
|
||||||
print "good: got a SyntaxError as expected"
|
|
||||||
|
|
||||||
suppliers = [
|
suppliers = [
|
||||||
(1, "Boeing"),
|
(1, "Boeing"),
|
||||||
|
|
Loading…
Reference in New Issue