annotate Lib/test/test_parser.py @ 48416:fb02fedfe647

Merged revisions 64677 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64677 | brett.cannon | 2008-07-02 14:52:42 -0700 (Wed, 02 Jul 2008) | 2 lines Revert r64673 and instead just change the file encoding. ........
author Brett Cannon <bcannon@gmail.com>
date Wed, 02 Jul 2008 22:06:12 +0000
parents 9c930a32cebb
children 6d6d3e037550
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 unittest
45852
30c4e1ca8421 Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45446
diff changeset
3 import sys
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45852
diff changeset
4 from test import support
14111
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 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 # 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
8 # 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
9 # of the parser module.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
12 class RoundtripLegalSyntaxTestCase(unittest.TestCase):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
13
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
14 def roundtrip(self, f, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
15 st1 = f(s)
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
16 t = st1.totuple()
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
17 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
18 st2 = parser.sequence2st(t)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
19 except parser.ParserError as why:
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
20 self.fail("could not roundtrip %r: %s" % (s, why))
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
21
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
22 self.assertEquals(t, st2.totuple(),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
23 "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
24
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
25 def check_expr(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
26 self.roundtrip(parser.expr, s)
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
27
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
28 def check_suite(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
29 self.roundtrip(parser.suite, s)
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
31 def test_yield_statement(self):
22719
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
32 self.check_suite("def f(): yield 1")
35298
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
33 self.check_suite("def f(): yield")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
34 self.check_suite("def f(): x += yield")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
35 self.check_suite("def f(): x = yield 1")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
36 self.check_suite("def f(): x = y = yield 1")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
37 self.check_suite("def f(): x = yield")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
38 self.check_suite("def f(): x = y = yield")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
39 self.check_suite("def f(): 1 + (yield)*2")
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
40 self.check_suite("def f(): (yield 1)*2")
22719
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
41 self.check_suite("def f(): return; yield 1")
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
42 self.check_suite("def f(): yield 1; return")
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
43 self.check_suite("def f():\n"
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
44 " 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
45 " yield x\n")
35298
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
46 self.check_suite("def f():\n"
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
47 " if (yield):\n"
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
48 " yield x\n")
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
49
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
50 def test_expressions(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
51 self.check_expr("foo(1)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
52 self.check_expr("[1, 2, 3]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
53 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
54 self.check_expr("[x**3 for x in range(20) if x % 3]")
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35742
diff changeset
55 self.check_expr("[x**3 for x in range(20) if x % 2 if x % 3]")
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35742
diff changeset
56 self.check_expr("list(x**3 for x in range(20))")
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35742
diff changeset
57 self.check_expr("list(x**3 for x in range(20) if x % 3)")
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 35742
diff changeset
58 self.check_expr("list(x**3 for x in range(20) if x % 2 if x % 3)")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
59 self.check_expr("foo(*args)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
60 self.check_expr("foo(*args, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
61 self.check_expr("foo(**kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
62 self.check_expr("foo(key=value)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
63 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
64 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
65 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
66 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
67 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
68 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
69 self.check_expr("foo + bar")
27517
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
70 self.check_expr("foo - bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
71 self.check_expr("foo * bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
72 self.check_expr("foo / bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
73 self.check_expr("foo // bar")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
74 self.check_expr("lambda: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
75 self.check_expr("lambda x: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
76 self.check_expr("lambda *y: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
77 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
78 self.check_expr("lambda **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
79 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
80 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
81 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
82 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
83 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
84 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
85 self.check_expr("lambda x, *y, **z: 0")
32121
302d399cfd37 SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
86 self.check_expr("(x for x in range(10))")
302d399cfd37 SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
87 self.check_expr("foo(x for x in range(10))")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
88
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
89 def test_simple_expression(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
90 # expr_stmt
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
91 self.check_suite("a")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
92
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
93 def test_simple_assignments(self):
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 = c = d = e")
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
96
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
97 def test_simple_augmented_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
98 self.check_suite("a += b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
99 self.check_suite("a -= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
100 self.check_suite("a *= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
101 self.check_suite("a /= b")
27517
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
102 self.check_suite("a //= b")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
103 self.check_suite("a %= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
104 self.check_suite("a &= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
105 self.check_suite("a |= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
106 self.check_suite("a ^= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
107 self.check_suite("a <<= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
108 self.check_suite("a >>= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
109 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
110
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
111 def test_function_defs(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
112 self.check_suite("def f(): 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(*args): 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(*args, **kw): 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(**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(foo=bar): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
117 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
118 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
119 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
120
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
130 self.check_suite("@staticmethod\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
131 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
132 self.check_suite("@staticmethod\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
133 "@funcattrs(x, y)\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
134 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
135 self.check_suite("@funcattrs()\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
136 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
137
34887
7c2780c9e51b Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents: 33353
diff changeset
138 def test_class_defs(self):
7c2780c9e51b Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents: 33353
diff changeset
139 self.check_suite("class foo():pass")
43862
d4f9706cb46b Patch 1144 by David Binger, fix for parser module. With unittest.
Guido van Rossum <guido@python.org>
parents: 42312
diff changeset
140 self.check_suite("class foo(object):pass")
34920
67a89b43dcc7 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34887
diff changeset
141
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
142 def test_import_from_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
143 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
144 self.check_suite("from sys.path import dirname")
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
145 self.check_suite("from sys.path import (dirname)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
146 self.check_suite("from sys.path import (dirname,)")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
147 self.check_suite("from sys.path import dirname as my_dirname")
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
148 self.check_suite("from sys.path import (dirname as my_dirname)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
149 self.check_suite("from sys.path import (dirname as my_dirname,)")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
150 self.check_suite("from sys.path import dirname, basename")
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
151 self.check_suite("from sys.path import (dirname, basename)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
152 self.check_suite("from sys.path import (dirname, basename,)")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
153 self.check_suite(
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
154 "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
155 self.check_suite(
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
156 "from sys.path import (dirname as my_dirname, basename)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
157 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
158 "from sys.path import (dirname as my_dirname, basename,)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
159 self.check_suite(
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
160 "from sys.path import dirname, basename as my_basename")
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
161 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
162 "from sys.path import (dirname, basename as my_basename)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
163 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
164 "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
165
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
166 def test_basic_import_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
167 self.check_suite("import sys")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
168 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
169 self.check_suite("import sys, math")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
170 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
171 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
172
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
173 def test_pep263(self):
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
174 self.check_suite("# -*- coding: iso-8859-1 -*-\n"
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
175 "pass\n")
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
176
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
177 def test_assert(self):
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
178 self.check_suite("assert alo < ahi and blo < bhi\n")
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
179
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
180 def test_position(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
181 # An absolutely minimal test of position information. Better
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
182 # tests would be a big project.
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
183 code = "def f(x):\n return x + 1\n"
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
184 st1 = parser.suite(code)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
185 st2 = st1.totuple(line_info=1, col_info=1)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
186
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
187 def walk(tree):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
188 node_type = tree[0]
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
189 next = tree[1]
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
190 if isinstance(next, tuple):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
191 for elt in tree[1:]:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
192 for x in walk(elt):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
193 yield x
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
194 else:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
195 yield tree
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
196
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
197 terminals = list(walk(st2))
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
198 self.assertEqual([
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
199 (1, 'def', 1, 0),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
200 (1, 'f', 1, 4),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
201 (7, '(', 1, 5),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
202 (1, 'x', 1, 6),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
203 (8, ')', 1, 7),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
204 (11, ':', 1, 8),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
205 (4, '', 1, 9),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
206 (5, '', 2, -1),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
207 (1, 'return', 2, 4),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
208 (1, 'x', 2, 11),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
209 (14, '+', 2, 13),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
210 (2, '1', 2, 15),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
211 (4, '', 2, 16),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
212 (6, '', 2, -1),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
213 (4, '', 2, -1),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
214 (0, '', 2, -1)],
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
215 terminals)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
216
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
217
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
218 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
219 # 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
220 # rejections for them.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
221 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
222
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
223 class IllegalSyntaxTestCase(unittest.TestCase):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
224
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
225 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
226 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
227 parser.sequence2st(tree)
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
228 except parser.ParserError:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
229 pass
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
230 else:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
231 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
232
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
233 def test_junk(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
234 # not even remotely valid:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
235 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
236
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
237 def test_illegal_yield_1(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
238 # Illegal yield statement: def f(): return 1; yield 1
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
239 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
240 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
241 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
242 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
243 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
244 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
245 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
246 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
247 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
248 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
249 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
250 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
251 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
252 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
253 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
254 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
255 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
256 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
257 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
258 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
259 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
260 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
261 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
262 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
263 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
264 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
265 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
266 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
267 (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
268 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
269 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
270 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
271 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
272 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
273 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
274 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
275 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
276 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
277 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
278 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
279 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
280 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
281 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
282 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
283 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
284 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
285 (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
286 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
287 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
288 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
289 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
290 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
291
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
292 def test_illegal_yield_2(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
293 # Illegal return in generator: def f(): return 1; yield 1
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
294 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
295 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
296 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
297 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
298 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
299 (278,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
300 (1, 'from'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
301 (281, (1, '__future__')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
302 (1, 'import'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
303 (279, (1, 'generators')))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
304 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
305 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
306 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
307 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
308 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
309 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
310 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
311 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
312 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
313 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
314 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
315 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
316 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
317 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
318 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
319 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
320 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
321 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
322 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
323 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
324 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
325 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
326 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
327 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
328 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
329 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
330 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
331 (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
332 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
333 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
334 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
335 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
336 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
337 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
338 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
339 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
340 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
341 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
342 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
343 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
344 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
345 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
346 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
347 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
348 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
349 (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
350 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
351 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
352 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
353 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
354 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
355
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
356 def test_a_comma_comma_c(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
357 # Illegal input: a,,c
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
358 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
359 (258,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
360 (311,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
361 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
362 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
363 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
364 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
365 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
366 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
367 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
368 (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
369 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
370 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
371 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
372 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
373 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
374 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
375 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
376 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
377 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
378 (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
379 (4, ''),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
380 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
381 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
382
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
383 def test_illegal_operator(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
384 # Illegal input: a $= b
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
385 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
386 (257,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
387 (264,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
388 (265,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
389 (266,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
390 (267,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
391 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
392 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
393 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
394 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
395 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
396 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
397 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
398 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
399 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
400 (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
401 (268, (37, '$=')),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
402 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
403 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
404 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
405 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
406 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
407 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
408 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
409 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
410 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
411 (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
412 (4, ''))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
413 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
414 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
415
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
416 def test_malformed_global(self):
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
417 #doesn't have global keyword in ast
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
418 tree = (257,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
419 (264,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
420 (265,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
421 (266,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
422 (282, (1, 'foo'))), (4, ''))),
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
423 (4, ''),
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27777
diff changeset
424 (0, ''))
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
425 self.check_bad_tree(tree, "malformed global ast")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
426
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
427
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
428 class CompileTestCase(unittest.TestCase):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
429
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
430 # These tests are very minimal. :-(
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
431
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
432 def test_compile_expr(self):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
433 st = parser.expr('2 + 3')
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
434 code = parser.compilest(st)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
435 self.assertEquals(eval(code), 5)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
436
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
437 def test_compile_suite(self):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
438 st = parser.suite('x = 2; y = x + 3')
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
439 code = parser.compilest(st)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
440 globs = {}
39782
c94f37054f19 Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents: 37879
diff changeset
441 exec(code, globs)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
442 self.assertEquals(globs['y'], 5)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
443
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
444 def test_compile_error(self):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
445 st = parser.suite('1 = 3 + 4')
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
446 self.assertRaises(SyntaxError, parser.compilest, st)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
447
42309
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
448 def test_compile_badunicode(self):
42312
007ed6cdd1f7 Make test_parser pass after merge.
Guido van Rossum <guido@python.org>
parents: 42309
diff changeset
449 st = parser.suite('a = "\\U12345678"')
42309
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
450 self.assertRaises(SyntaxError, parser.compilest, st)
42312
007ed6cdd1f7 Make test_parser pass after merge.
Guido van Rossum <guido@python.org>
parents: 42309
diff changeset
451 st = parser.suite('a = "\\u1"')
42309
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
452 self.assertRaises(SyntaxError, parser.compilest, st)
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
453
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
454 class ParserStackLimitTestCase(unittest.TestCase):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
455 """try to push the parser to/over it's limits.
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
456 see http://bugs.python.org/issue1881 for a discussion
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
457 """
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
458 def _nested_expression(self, level):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
459 return "["*level+"]"*level
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
460
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
461 def test_deeply_nested_list(self):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
462 # XXX used to be 99 levels in 2.x
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
463 e = self._nested_expression(93)
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
464 st = parser.expr(e)
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
465 st.compile()
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
466
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
467 def test_trigger_memory_error(self):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
468 e = self._nested_expression(100)
45852
30c4e1ca8421 Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45446
diff changeset
469 print("Expecting 's_push: parser stack overflow' in next line",
30c4e1ca8421 Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45446
diff changeset
470 file=sys.stderr)
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
471 self.assertRaises(MemoryError, parser.expr, e)
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
472
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
473 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45852
diff changeset
474 support.run_unittest(
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
475 RoundtripLegalSyntaxTestCase,
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
476 IllegalSyntaxTestCase,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
477 CompileTestCase,
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
478 ParserStackLimitTestCase,
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
479 )
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
480
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
481
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
482 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
483 test_main()