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

Skip to content

Commit 4779399

Browse files
committed
Add test for syntax error on "x = 1 + 1".
Move check_syntax() function into test_support.
1 parent c348cd7 commit 4779399

4 files changed

Lines changed: 13 additions & 22 deletions

File tree

Lib/test/output/test_grammar

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ expr_input
1414
eval_input
1515
funcdef
1616
lambdef
17-
SyntaxError expected for "lambda x: x = 2"
1817
simple_stmt
1918
expr_stmt
2019
print_stmt
@@ -26,8 +25,6 @@ extended print_stmt
2625
1 2 3
2726
1 1 1
2827
hello world
29-
SyntaxError expected for "print ,"
30-
SyntaxError expected for "print >> x,"
3128
del_stmt
3229
pass_stmt
3330
flow_stmt
@@ -62,6 +59,4 @@ classdef
6259
[(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')]
6360
[(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), (5, 'Banana'), (5, 'Coconut')]
6461
[0, 0, 0]
65-
SyntaxError expected for "[i, s for i in nums for s in strs]"
66-
SyntaxError expected for "[x if y]"
6762
[('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]

Lib/test/test_grammar.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33

44
from test_support import *
55

6-
def check_syntax(statement):
7-
try:
8-
compile(statement, '<string>', 'exec')
9-
except SyntaxError:
10-
print 'SyntaxError expected for "%s"' % statement
11-
else:
12-
print 'Missing SyntaxError: "%s"' % statement
13-
146
print '1. Parser'
157

168
print '1.1 Tokens'
@@ -280,6 +272,9 @@ def d22v(a, b, c=1, d=2, *rest): pass
280272
abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4)
281273
# NB these variables are deleted below
282274

275+
check_syntax("x + 1 = 1")
276+
check_syntax("a + 1 = b + 2")
277+
283278
print 'print_stmt' # 'print' (test ',')* [test]
284279
print 1, 2, 3
285280
print 1, 2, 3,

Lib/test/test_scope.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from test.test_support import verify, TestFailed
1+
from test.test_support import verify, TestFailed, check_syntax
22

33
print "1. simple nesting"
44

@@ -177,14 +177,6 @@ def fact(n):
177177

178178
print "11. unoptimized namespaces"
179179

180-
def check_syntax(s):
181-
try:
182-
compile(s, '?', 'exec')
183-
except SyntaxError:
184-
pass
185-
else:
186-
raise TestFailed
187-
188180
check_syntax("""def unoptimized_clash1(strip):
189181
def f(s):
190182
from string import *

Lib/test/test_support.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ def verify(condition, reason='test failed'):
7979

8080
if not condition:
8181
raise TestFailed(reason)
82+
83+
def check_syntax(statement):
84+
try:
85+
compile(statement, '<string>', 'exec')
86+
except SyntaxError:
87+
pass
88+
else:
89+
print 'Missing SyntaxError: "%s"' % statement
90+

0 commit comments

Comments
 (0)