annotate Lib/test/test_parser.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents e3184e46303b
children 0602078bdce1 fa0ac845929b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 import parser
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
2 import test_support
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
3 import unittest
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 # 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
7 # 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
8 # of the parser module.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
11 class RoundtripLegalSyntaxTestCase(unittest.TestCase):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
12 def roundtrip(self, f, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
13 st1 = f(s)
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
14 t = st1.totuple()
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
15 try:
18670
384b9113a2e0 Use the "st" versions of the "ast" calls in the parser module -- there is
Fred Drake <fdrake@acm.org>
parents: 18647
diff changeset
16 st2 = parser.sequence2st(t)
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
17 except parser.ParserError:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
18 self.fail("could not roundtrip %r" % s)
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
19
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
20 self.assertEquals(t, st2.totuple(),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
21 "could not re-generate syntax tree")
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
22
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
23 def check_expr(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
24 self.roundtrip(parser.expr, s)
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
25
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
26 def check_suite(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
27 self.roundtrip(parser.suite, s)
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
29 def test_yield_statement(self):
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
30 self.check_suite("from __future__ import generators\n"
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
31 "def f(): yield 1")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
32 self.check_suite("from __future__ import generators\n"
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
33 "def f(): return; yield 1")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
34 self.check_suite("from __future__ import generators\n"
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
35 "def f(): yield 1; return")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
36 self.check_suite("from __future__ import generators\n"
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
37 "def f():\n"
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
38 " for x in range(30):\n"
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
39 " yield x\n")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
40
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
41 def test_expressions(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
42 self.check_expr("foo(1)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
43 self.check_expr("[1, 2, 3]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
44 self.check_expr("[x**3 for x in range(20)]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
45 self.check_expr("[x**3 for x in range(20) if x % 3]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
46 self.check_expr("foo(*args)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
47 self.check_expr("foo(*args, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
48 self.check_expr("foo(**kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
49 self.check_expr("foo(key=value)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
50 self.check_expr("foo(key=value, *args)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
51 self.check_expr("foo(key=value, *args, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
52 self.check_expr("foo(key=value, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
53 self.check_expr("foo(a, b, c, *args)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
54 self.check_expr("foo(a, b, c, *args, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
55 self.check_expr("foo(a, b, c, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
56 self.check_expr("foo + bar")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
57 self.check_expr("lambda: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
58 self.check_expr("lambda x: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
59 self.check_expr("lambda *y: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
60 self.check_expr("lambda *y, **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
61 self.check_expr("lambda **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
62 self.check_expr("lambda x, y: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
63 self.check_expr("lambda foo=bar: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
64 self.check_expr("lambda foo=bar, spaz=nifty+spit: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
65 self.check_expr("lambda foo=bar, **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
66 self.check_expr("lambda foo=bar, blaz=blat+2, **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
67 self.check_expr("lambda foo=bar, blaz=blat+2, *y, **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
68 self.check_expr("lambda x, *y, **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
69
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
70 def test_print(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
71 self.check_suite("print")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
72 self.check_suite("print 1")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
73 self.check_suite("print 1,")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
74 self.check_suite("print >>fp")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
75 self.check_suite("print >>fp, 1")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
76 self.check_suite("print >>fp, 1,")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
78 def test_simple_expression(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
79 # expr_stmt
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
80 self.check_suite("a")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
81
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
82 def test_simple_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
83 self.check_suite("a = b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
84 self.check_suite("a = b = c = d = e")
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
85
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
86 def test_simple_augmented_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
87 self.check_suite("a += b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
88 self.check_suite("a -= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
89 self.check_suite("a *= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
90 self.check_suite("a /= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
91 self.check_suite("a %= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
92 self.check_suite("a &= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
93 self.check_suite("a |= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
94 self.check_suite("a ^= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
95 self.check_suite("a <<= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
96 self.check_suite("a >>= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
97 self.check_suite("a **= b")
15752
c0822a05e923 Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents: 15507
diff changeset
98
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
99 def test_function_defs(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
100 self.check_suite("def f(): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
101 self.check_suite("def f(*args): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
102 self.check_suite("def f(*args, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
103 self.check_suite("def f(**kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
104 self.check_suite("def f(foo=bar): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
105 self.check_suite("def f(foo=bar, *args): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
106 self.check_suite("def f(foo=bar, *args, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
107 self.check_suite("def f(foo=bar, **kw): pass")
15752
c0822a05e923 Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents: 15507
diff changeset
108
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
109 self.check_suite("def f(a, b): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
110 self.check_suite("def f(a, b, *args): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
111 self.check_suite("def f(a, b, *args, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
112 self.check_suite("def f(a, b, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
113 self.check_suite("def f(a, b, foo=bar): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
114 self.check_suite("def f(a, b, foo=bar, *args): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
115 self.check_suite("def f(a, b, foo=bar, *args, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
116 self.check_suite("def f(a, b, foo=bar, **kw): pass")
15752
c0822a05e923 Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents: 15507
diff changeset
117
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
118 def test_import_from_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
119 self.check_suite("from sys.path import *")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
120 self.check_suite("from sys.path import dirname")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
121 self.check_suite("from sys.path import dirname as my_dirname")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
122 self.check_suite("from sys.path import dirname, basename")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
123 self.check_suite(
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
124 "from sys.path import dirname as my_dirname, basename")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
125 self.check_suite(
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
126 "from sys.path import dirname, basename as my_basename")
15752
c0822a05e923 Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents: 15507
diff changeset
127
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
128 def test_basic_import_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
129 self.check_suite("import sys")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
130 self.check_suite("import sys as system")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
131 self.check_suite("import sys, math")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
132 self.check_suite("import sys as system, math")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
133 self.check_suite("import sys, math as my_math")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
134
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
135 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136 # 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
137 # rejections for them.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
138 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
139
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
140 class IllegalSyntaxTestCase(unittest.TestCase):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
141 def check_bad_tree(self, tree, label):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
142 try:
18670
384b9113a2e0 Use the "st" versions of the "ast" calls in the parser module -- there is
Fred Drake <fdrake@acm.org>
parents: 18647
diff changeset
143 parser.sequence2st(tree)
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
144 except parser.ParserError:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
145 pass
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
146 else:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
147 self.fail("did not detect invalid tree for %r" % label)
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
148
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
149 def test_junk(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
150 # not even remotely valid:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
151 self.check_bad_tree((1, 2, 3), "<junk>")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
152
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
153 def test_illegal_yield_1(self):
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
154 """Illegal yield statement: def f(): return 1; yield 1"""
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
155 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
156 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
157 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
158 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
159 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
160 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
161 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
162 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
163 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
164 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
165 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
166 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
167 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
168 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
169 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
170 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
171 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
172 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
173 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
174 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
175 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
176 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
177 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
178 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
179 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
180 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
181 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
182 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
183 (302, (303, (304, (305, (2, '1')))))))))))))))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
184 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
185 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
186 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
187 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
188 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
189 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
190 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
191 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
192 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
193 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
194 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
195 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
196 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
197 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
198 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
199 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
200 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
201 (303, (304, (305, (2, '1')))))))))))))))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
202 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
203 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
204 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
205 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
206 self.check_bad_tree(tree, "def f():\n return 1\n yield 1")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
207
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
208 def test_illegal_yield_2(self):
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
209 """Illegal return in generator: def f(): return 1; yield 1"""
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
210 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
211 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
212 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
213 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
214 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
215 (278,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
216 (1, 'from'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
217 (281, (1, '__future__')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
218 (1, 'import'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
219 (279, (1, 'generators')))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
220 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
221 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
222 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
223 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
224 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
225 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
226 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
227 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
228 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
229 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
230 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
231 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
232 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
233 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
234 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
235 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
236 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
237 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
238 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
239 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
240 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
241 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
242 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
243 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
244 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
245 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
246 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
247 (302, (303, (304, (305, (2, '1')))))))))))))))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
248 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
249 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
250 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
251 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
252 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
253 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
254 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
255 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
256 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
257 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
258 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
259 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
260 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
261 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
262 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
263 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
264 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
265 (303, (304, (305, (2, '1')))))))))))))))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
266 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
267 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
268 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
269 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
270 self.check_bad_tree(tree, "def f():\n return 1\n yield 1")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
271
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
272 def test_print_chevron_comma(self):
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
273 """Illegal input: print >>fp,"""
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
274 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
275 (257,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
276 (264,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
277 (265,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
278 (266,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
279 (268,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
280 (1, 'print'),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
281 (35, '>>'),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
282 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
283 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
284 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
285 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
286 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
287 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
288 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
289 (298, (299, (300, (301, (302, (303, (1, 'fp')))))))))))))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
290 (12, ','))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
291 (4, ''))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
292 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
293 self.check_bad_tree(tree, "print >>fp,")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
294
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
295 def test_a_comma_comma_c(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
296 """Illegal input: a,,c"""
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
297 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
298 (258,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
299 (311,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
300 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
301 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
302 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
303 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
304 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
305 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
306 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
307 (298, (299, (300, (301, (302, (303, (1, 'a')))))))))))))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
308 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
309 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
310 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
311 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
312 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
313 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
314 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
315 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
316 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
317 (298, (299, (300, (301, (302, (303, (1, 'c'))))))))))))))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
318 (4, ''),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
319 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
320 self.check_bad_tree(tree, "a,,c")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
321
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
322 def test_illegal_operator(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
323 """Illegal input: a $= b"""
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
324 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
325 (257,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
326 (264,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
327 (265,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
328 (266,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
329 (267,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
330 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
331 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
332 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
333 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
334 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
335 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
336 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
337 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
338 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
339 (300, (301, (302, (303, (304, (1, 'a'))))))))))))))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
340 (268, (37, '$=')),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
341 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
342 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
343 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
344 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
345 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
346 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
347 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
348 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
349 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
350 (300, (301, (302, (303, (304, (1, 'b'))))))))))))))))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
351 (4, ''))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
352 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
353 self.check_bad_tree(tree, "a $= b")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
354
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
355
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
356 def test_main():
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
357 loader = unittest.TestLoader()
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
358 suite = unittest.TestSuite()
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
359 suite.addTest(loader.loadTestsFromTestCase(RoundtripLegalSyntaxTestCase))
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
360 suite.addTest(loader.loadTestsFromTestCase(IllegalSyntaxTestCase))
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
361 test_support.run_suite(suite)
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
362
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
363
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
364 if __name__ == "__main__":
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
365 test_main()