Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_parser.py @ 17322:bd110eadc19a legacy-trunk
One-liner critical fix from Jim Fulton: Eric's string-method crusade
got the order backwards in a line (for .find()).
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Thu, 05 Apr 2001 22:26:23 +0000 |
| parents | e59b835ad89a |
| children | 5391b9d022ac |
| rev | line source |
|---|---|
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
1 import os.path |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 import parser |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 import pprint |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 import sys |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 |
|
15966
e59b835ad89a
a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents:
15957
diff
changeset
|
6 from test_support import TestFailed |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
7 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 # First, we test that we can generate trees from valid source fragments, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 # and that these valid trees are indeed allowed by the tree-loading side |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 # of the parser module. |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 def roundtrip(f, s): |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 st1 = f(s) |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 t = st1.totuple() |
|
15507
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
17 try: |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
18 st2 = parser.sequence2ast(t) |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
19 except parser.ParserError: |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
20 raise TestFailed, s |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
22 def roundtrip_fromfile(filename): |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
23 roundtrip(parser.suite, open(filename).read()) |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
24 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
25 def test_expr(s): |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
26 print "expr:", s |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
27 roundtrip(parser.expr, s) |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
28 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
29 def test_suite(s): |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
30 print "suite:", s |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
31 roundtrip(parser.suite, s) |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
32 |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 print "Expressions:" |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
36 test_expr("foo(1)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
37 test_expr("[1, 2, 3]") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
38 test_expr("[x**3 for x in range(20)]") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
39 test_expr("[x**3 for x in range(20) if x % 3]") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
40 test_expr("foo(*args)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
41 test_expr("foo(*args, **kw)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
42 test_expr("foo(**kw)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
43 test_expr("foo(key=value)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
44 test_expr("foo(key=value, *args)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
45 test_expr("foo(key=value, *args, **kw)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
46 test_expr("foo(key=value, **kw)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
47 test_expr("foo(a, b, c, *args)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
48 test_expr("foo(a, b, c, *args, **kw)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
49 test_expr("foo(a, b, c, **kw)") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
50 test_expr("foo + bar") |
|
15507
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
51 test_expr("lambda: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
52 test_expr("lambda x: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
53 test_expr("lambda *y: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
54 test_expr("lambda *y, **z: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
55 test_expr("lambda **z: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
56 test_expr("lambda x, y: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
57 test_expr("lambda foo=bar: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
58 test_expr("lambda foo=bar, spaz=nifty+spit: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
59 test_expr("lambda foo=bar, **z: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
60 test_expr("lambda foo=bar, blaz=blat+2, **z: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
61 test_expr("lambda foo=bar, blaz=blat+2, *y, **z: 0") |
|
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
62 test_expr("lambda x, *y, **z: 0") |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
63 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 print |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 print "Statements:" |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
66 test_suite("print") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
67 test_suite("print 1") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
68 test_suite("print 1,") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
69 test_suite("print >>fp") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
70 test_suite("print >>fp, 1") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
71 test_suite("print >>fp, 1,") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
72 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
73 # expr_stmt |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
74 test_suite("a") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
75 test_suite("a = b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
76 test_suite("a = b = c = d = e") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
77 test_suite("a += b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
78 test_suite("a -= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
79 test_suite("a *= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
80 test_suite("a /= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
81 test_suite("a %= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
82 test_suite("a &= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
83 test_suite("a |= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
84 test_suite("a ^= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
85 test_suite("a <<= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
86 test_suite("a >>= b") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
87 test_suite("a **= b") |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
88 |
|
15507
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
89 test_suite("def f(): pass") |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
90 test_suite("def f(*args): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
91 test_suite("def f(*args, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
92 test_suite("def f(**kw): pass") |
|
15507
34058af976ce
Added tests to avoid regression on bug #125375.
Fred Drake <fdrake@acm.org>
parents:
14214
diff
changeset
|
93 test_suite("def f(foo=bar): pass") |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
94 test_suite("def f(foo=bar, *args): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
95 test_suite("def f(foo=bar, *args, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
96 test_suite("def f(foo=bar, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
97 |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
98 test_suite("def f(a, b): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
99 test_suite("def f(a, b, *args): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
100 test_suite("def f(a, b, *args, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
101 test_suite("def f(a, b, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
102 test_suite("def f(a, b, foo=bar): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
103 test_suite("def f(a, b, foo=bar, *args): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
104 test_suite("def f(a, b, foo=bar, *args, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
105 test_suite("def f(a, b, foo=bar, **kw): pass") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
106 |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
107 test_suite("from sys.path import *") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
108 test_suite("from sys.path import dirname") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
109 test_suite("from sys.path import dirname as my_dirname") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
110 test_suite("from sys.path import dirname, basename") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
111 test_suite("from sys.path import dirname as my_dirname, basename") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
112 test_suite("from sys.path import dirname, basename as my_basename") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
113 |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
114 test_suite("import sys") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
115 test_suite("import sys as system") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
116 test_suite("import sys, math") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
117 test_suite("import sys as system, math") |
|
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
118 test_suite("import sys, math as my_math") |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
119 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
120 #d = os.path.dirname(os.__file__) |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
121 #roundtrip_fromfile(os.path.join(d, "os.py")) |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
122 #roundtrip_fromfile(os.path.join(d, "test", "test_parser.py")) |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
124 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
125 # Second, we take *invalid* trees and make sure we get ParserError |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
126 # rejections for them. |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
127 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
128 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
129 print |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
130 print "Invalid parse trees:" |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
131 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
132 def check_bad_tree(tree, label): |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
133 print |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
134 print label |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
135 try: |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
136 parser.sequence2ast(tree) |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
137 except parser.ParserError: |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
138 print "caught expected exception for invalid tree" |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
139 else: |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
140 print "test failed: did not properly detect invalid tree:" |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
141 pprint.pprint(tree) |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
142 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
143 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
144 # not even remotely valid: |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
145 check_bad_tree((1, 2, 3), "<junk>") |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
146 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
147 # print >>fp, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
148 tree = \ |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
149 (257, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
150 (264, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
151 (265, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
152 (266, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
153 (268, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
154 (1, 'print'), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
155 (35, '>>'), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
156 (290, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
157 (291, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
158 (292, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
159 (293, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
160 (295, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
161 (296, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
162 (297, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
163 (298, (299, (300, (301, (302, (303, (1, 'fp')))))))))))))), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
164 (12, ','))), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
165 (4, ''))), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
166 (0, '')) |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
167 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
168 check_bad_tree(tree, "print >>fp,") |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
169 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
170 # a,,c |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
171 tree = \ |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
172 (258, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
173 (311, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
174 (290, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
175 (291, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
176 (292, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
177 (293, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
178 (295, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
179 (296, (297, (298, (299, (300, (301, (302, (303, (1, 'a')))))))))))))), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
180 (12, ','), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
181 (12, ','), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
182 (290, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
183 (291, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
184 (292, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
185 (293, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
186 (295, |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
187 (296, (297, (298, (299, (300, (301, (302, (303, (1, 'c'))))))))))))))), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
188 (4, ''), |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
189 (0, '')) |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
190 |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
191 check_bad_tree(tree, "a,,c") |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
192 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
193 # a $= b |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
194 tree = \ |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
195 (257, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
196 (264, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
197 (265, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
198 (266, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
199 (267, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
200 (312, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
201 (291, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
202 (292, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
203 (293, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
204 (294, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
205 (296, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
206 (297, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
207 (298, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
208 (299, (300, (301, (302, (303, (304, (1, 'a'))))))))))))))), |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
209 (268, (37, '$=')), |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
210 (312, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
211 (291, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
212 (292, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
213 (293, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
214 (294, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
215 (296, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
216 (297, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
217 (298, |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
218 (299, (300, (301, (302, (303, (304, (1, 'b'))))))))))))))))), |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
219 (4, ''))), |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
220 (0, '')) |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
221 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
222 check_bad_tree(tree, "a $= b") |
