annotate Lib/test/test_parser.py @ 38664:7619216bbc19 2.4

Bug #1502728: Correctly link against librt library on HP-UX. (backport from rev. 46743)
author Georg Brandl <georg@python.org>
date Thu, 08 Jun 2006 12:54:16 +0000
parents f7474d31ba3f
children 7c2780c9e51b
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
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 22719
diff changeset
3 from test import test_support
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 # First, we test that we can generate trees from valid source fragments,
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 # and that these valid trees are indeed allowed by the tree-loading side
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8 # of the parser module.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
11 class RoundtripLegalSyntaxTestCase(unittest.TestCase):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
12
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
13 def roundtrip(self, f, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
14 st1 = f(s)
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
15 t = st1.totuple()
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
16 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
17 st2 = parser.sequence2st(t)
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
18 except parser.ParserError, why:
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
19 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
20
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
21 self.assertEquals(t, st2.totuple(),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
22 "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
23
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
24 def check_expr(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
25 self.roundtrip(parser.expr, s)
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
26
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
27 def check_suite(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
28 self.roundtrip(parser.suite, s)
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
30 def test_yield_statement(self):
22719
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
31 self.check_suite("def f(): yield 1")
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
32 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
33 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
34 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
35 " 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
36 " yield x\n")
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
37
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
38 def test_expressions(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
39 self.check_expr("foo(1)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
40 self.check_expr("[1, 2, 3]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
41 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
42 self.check_expr("[x**3 for x in range(20) if x % 3]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
43 self.check_expr("foo(*args)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
44 self.check_expr("foo(*args, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
45 self.check_expr("foo(**kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
46 self.check_expr("foo(key=value)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
47 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
48 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
49 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
50 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
51 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
52 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
53 self.check_expr("foo + bar")
27517
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
54 self.check_expr("foo - bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
55 self.check_expr("foo * bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
56 self.check_expr("foo / bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
57 self.check_expr("foo // bar")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
58 self.check_expr("lambda: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
59 self.check_expr("lambda x: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
60 self.check_expr("lambda *y: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
61 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
62 self.check_expr("lambda **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
72
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
73 def test_print(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
74 self.check_suite("print")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
75 self.check_suite("print 1")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
76 self.check_suite("print 1,")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
77 self.check_suite("print >>fp")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
78 self.check_suite("print >>fp, 1")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
79 self.check_suite("print >>fp, 1,")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
80
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
81 def test_simple_expression(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
82 # expr_stmt
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
83 self.check_suite("a")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
84
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
85 def test_simple_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
86 self.check_suite("a = b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
87 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
88
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
89 def test_simple_augmented_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
90 self.check_suite("a += b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
91 self.check_suite("a -= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
92 self.check_suite("a *= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
93 self.check_suite("a /= b")
27517
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
94 self.check_suite("a //= b")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
95 self.check_suite("a %= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
96 self.check_suite("a &= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
97 self.check_suite("a |= b")
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")
15752
c0822a05e923 Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents: 15507
diff changeset
102
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
103 def test_function_defs(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
104 self.check_suite("def f(): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
105 self.check_suite("def f(*args): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
106 self.check_suite("def f(*args, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
107 self.check_suite("def f(**kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
108 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
109 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
110 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
111 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
112
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
113 self.check_suite("def f(a, b): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
114 self.check_suite("def f(a, b, *args): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
115 self.check_suite("def f(a, b, *args, **kw): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
116 self.check_suite("def f(a, b, **kw): 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(a, b, foo=bar): 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(a, b, foo=bar, *args): 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(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
120 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
121
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
122 self.check_suite("@staticmethod\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
123 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
124 self.check_suite("@staticmethod\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
125 "@funcattrs(x, y)\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
126 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
127 self.check_suite("@funcattrs()\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
128 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
129
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
130 def test_import_from_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 self.check_suite(
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
142 "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
143 self.check_suite(
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
144 "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
145 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
146 "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
147 self.check_suite(
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
148 "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
149 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
150 "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
151 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
152 "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
153
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
154 def test_basic_import_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
155 self.check_suite("import sys")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
156 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
157 self.check_suite("import sys, math")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
158 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
159 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
160
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
161 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
162 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
163 "pass\n")
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
164
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
165 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
166 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
167
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
168 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
169 # 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
170 # rejections for them.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
171 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
172
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
173 class IllegalSyntaxTestCase(unittest.TestCase):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
174
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
175 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
176 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
177 parser.sequence2st(tree)
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
178 except parser.ParserError:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
179 pass
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
180 else:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
181 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
182
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
183 def test_junk(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
184 # not even remotely valid:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
185 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
186
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
187 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
188 # 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
189 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
190 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
191 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
192 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
193 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
194 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
195 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
196 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
197 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
198 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
199 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
200 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
201 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
202 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
203 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
204 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
205 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
206 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
207 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
208 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
209 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
210 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
211 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
212 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
213 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
214 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
215 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
216 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
217 (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
218 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
219 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
220 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
221 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
222 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
223 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
224 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
225 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
226 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
227 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
228 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
229 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
230 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
231 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
232 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
233 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
234 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
235 (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
236 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
237 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
238 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
239 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
240 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
241
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
242 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
243 # 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
244 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
245 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
246 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
247 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
248 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
249 (278,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
250 (1, 'from'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
251 (281, (1, '__future__')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
252 (1, 'import'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
253 (279, (1, 'generators')))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
254 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
255 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
256 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
257 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
258 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
259 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
260 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
261 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
262 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
263 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
264 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
265 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
266 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
267 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
268 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
269 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
270 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
271 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
272 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
273 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
274 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
275 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
276 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
277 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
278 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
279 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
280 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
281 (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
282 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
283 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
284 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
285 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
286 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
287 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
288 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
289 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
290 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
291 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
292 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
293 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
294 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
295 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
296 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
297 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
298 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
299 (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
300 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
301 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
302 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
303 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
304 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
305
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
306 def test_print_chevron_comma(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
307 # Illegal input: print >>fp,
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
308 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
309 (257,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
310 (264,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
311 (265,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
312 (266,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
313 (268,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
314 (1, 'print'),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
315 (35, '>>'),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
316 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
317 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
318 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
319 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
320 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
321 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
322 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
323 (298, (299, (300, (301, (302, (303, (1, 'fp')))))))))))))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
324 (12, ','))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
325 (4, ''))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
326 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
327 self.check_bad_tree(tree, "print >>fp,")
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
328
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
329 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
330 # Illegal input: a,,c
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
331 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
332 (258,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
333 (311,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
334 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
335 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
336 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
337 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
338 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
339 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
340 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
341 (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
342 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
343 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
344 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
345 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
346 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
347 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
348 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
349 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
350 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
351 (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
352 (4, ''),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
353 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
354 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
355
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
356 def test_illegal_operator(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
357 # Illegal input: a $= b
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 (257,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
360 (264,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
361 (265,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
362 (266,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
363 (267,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
364 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
365 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
366 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
367 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
368 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
369 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
370 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
371 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
372 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
373 (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
374 (268, (37, '$=')),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
375 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
376 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
377 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
378 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
379 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
380 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
381 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
382 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
383 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
384 (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
385 (4, ''))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
386 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
387 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
388
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
389 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
390 #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
391 tree = (257,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
392 (264,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
393 (265,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
394 (266,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
395 (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
396 (4, ''),
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27777
diff changeset
397 (0, ''))
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
398 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
399
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
400 def test_main():
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
401 test_support.run_unittest(
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
402 RoundtripLegalSyntaxTestCase,
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
403 IllegalSyntaxTestCase
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
404 )
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
405
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
406
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
407 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
408 test_main()