Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_parser.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | ea36de7926f8 |
| children | 9ee8c00f7e63 |
| 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 |
|
45849
3b39b7bb2c07
Note that the stderr output of the test is intentional.
Martin v. Löwis <martin@v.loewis.de>
parents:
45443
diff
changeset
|
3 import sys |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
4 import struct |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
5 from test import test_support as support |
|
14111
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 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 # 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
|
9 # 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
|
10 # of the parser module. |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
13 class RoundtripLegalSyntaxTestCase(unittest.TestCase): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
14 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
15 def roundtrip(self, f, s): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
16 st1 = f(s) |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
17 t = st1.totuple() |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
18 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
|
19 st2 = parser.sequence2st(t) |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
20 except parser.ParserError, why: |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
21 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
|
22 |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62778
diff
changeset
|
23 self.assertEqual(t, st2.totuple(), |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62778
diff
changeset
|
24 "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
|
25 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
26 def check_expr(self, s): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
27 self.roundtrip(parser.expr, s) |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14111
diff
changeset
|
28 |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
29 def test_flags_passed(self): |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
30 # The unicode literals flags has to be passed from the paser to AST |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
31 # generation. |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
32 suite = parser.suite("from __future__ import unicode_literals; x = ''") |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
33 code = suite.compile() |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
34 scope = {} |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
35 exec code in scope |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58250
diff
changeset
|
36 self.assertIsInstance(scope["x"], unicode) |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48312
diff
changeset
|
37 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
38 def check_suite(self, s): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
39 self.roundtrip(parser.suite, s) |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
18647
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
41 def test_yield_statement(self): |
|
22719
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") |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34920
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 " 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
|
55 " 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
|
56 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
|
57 " if (yield):\n" |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34920
diff
changeset
|
58 " 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
|
59 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
60 def test_expressions(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
61 self.check_expr("foo(1)") |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
62 self.check_expr("{1:1}") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
63 self.check_expr("{1:1, 2:2, 3:3}") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
64 self.check_expr("{1:1, 2:2, 3:3,}") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
65 self.check_expr("{1}") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
66 self.check_expr("{1, 2, 3}") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
67 self.check_expr("{1, 2, 3,}") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
68 self.check_expr("[]") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
69 self.check_expr("[1]") |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
70 self.check_expr("[1, 2, 3]") |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
71 self.check_expr("[1, 2, 3,]") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
72 self.check_expr("()") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
73 self.check_expr("(1,)") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
74 self.check_expr("(1, 2, 3)") |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57597
diff
changeset
|
75 self.check_expr("(1, 2, 3,)") |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
76 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
|
77 self.check_expr("[x**3 for x in range(20) if x % 3]") |
|
37623
2fd6ad582203
Add another little test to make sure we roundtrip multiple list comp ifs ok.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
78 self.check_expr("[x**3 for x in range(20) if x % 2 if x % 3]") |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
79 self.check_expr("[x+y for x in range(30) for y in range(20) if x % 2 if y % 3]") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
80 #self.check_expr("[x for x in lambda: True, lambda: False if x()]") |
|
37623
2fd6ad582203
Add another little test to make sure we roundtrip multiple list comp ifs ok.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
81 self.check_expr("list(x**3 for x in range(20))") |
|
2fd6ad582203
Add another little test to make sure we roundtrip multiple list comp ifs ok.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
82 self.check_expr("list(x**3 for x in range(20) if x % 3)") |
|
2fd6ad582203
Add another little test to make sure we roundtrip multiple list comp ifs ok.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
83 self.check_expr("list(x**3 for x in range(20) if x % 2 if x % 3)") |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
84 self.check_expr("list(x+y for x in range(30) for y in range(20) if x % 2 if y % 3)") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
85 self.check_expr("{x**3 for x in range(30)}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
86 self.check_expr("{x**3 for x in range(30) if x % 3}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
87 self.check_expr("{x**3 for x in range(30) if x % 2 if x % 3}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
88 self.check_expr("{x+y for x in range(30) for y in range(20) if x % 2 if y % 3}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
89 self.check_expr("{x**3: y**2 for x, y in zip(range(30), range(30))}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
90 self.check_expr("{x**3: y**2 for x, y in zip(range(30), range(30)) if x % 3}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
91 self.check_expr("{x**3: y**2 for x, y in zip(range(30), range(30)) if x % 3 if y % 3}") |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
92 self.check_expr("{x:y for x in range(30) for y in range(20) if x % 2 if y % 3}") |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
93 self.check_expr("foo(*args)") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
94 self.check_expr("foo(*args, **kw)") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
95 self.check_expr("foo(**kw)") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
96 self.check_expr("foo(key=value)") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 self.check_expr("foo(a, b, c, **kw)") |
|
48312
504e6d030e84
check that the parser module can handle the new keyword syntax
Benjamin Peterson <benjamin@python.org>
parents:
45849
diff
changeset
|
103 self.check_expr("foo(a, *args, keyword=23)") |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
104 self.check_expr("foo + bar") |
|
27517
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
24957
diff
changeset
|
105 self.check_expr("foo - bar") |
|
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
24957
diff
changeset
|
106 self.check_expr("foo * bar") |
|
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
24957
diff
changeset
|
107 self.check_expr("foo / bar") |
|
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
24957
diff
changeset
|
108 self.check_expr("foo // bar") |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
109 self.check_expr("lambda: 0") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
110 self.check_expr("lambda x: 0") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
111 self.check_expr("lambda *y: 0") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
112 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
|
113 self.check_expr("lambda **z: 0") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 self.check_expr("lambda x, *y, **z: 0") |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
121 self.check_expr("lambda x: 5 if x else 2") |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
122 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
|
123 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
|
124 |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
125 def test_print(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
126 self.check_suite("print") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
127 self.check_suite("print 1") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
128 self.check_suite("print 1,") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
129 self.check_suite("print >>fp") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
130 self.check_suite("print >>fp, 1") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
131 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
|
132 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
133 def test_simple_expression(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
134 # expr_stmt |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
135 self.check_suite("a") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
136 |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
137 def test_simple_assignments(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
138 self.check_suite("a = b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
139 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
|
140 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
141 def test_simple_augmented_assignments(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
142 self.check_suite("a += b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
143 self.check_suite("a -= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
144 self.check_suite("a *= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
145 self.check_suite("a /= b") |
|
27517
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
24957
diff
changeset
|
146 self.check_suite("a //= b") |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
147 self.check_suite("a %= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
148 self.check_suite("a &= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
149 self.check_suite("a |= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
150 self.check_suite("a ^= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
151 self.check_suite("a <<= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
152 self.check_suite("a >>= b") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
153 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
|
154 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
155 def test_function_defs(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
156 self.check_suite("def f(): pass") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
174 self.check_suite("@staticmethod\n" |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
175 "def f(): pass") |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
176 self.check_suite("@staticmethod\n" |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
177 "@funcattrs(x, y)\n" |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
178 "def f(): pass") |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
179 self.check_suite("@funcattrs()\n" |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
180 "def f(): pass") |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
181 |
|
34887
7c2780c9e51b
Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents:
33353
diff
changeset
|
182 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
|
183 self.check_suite("class foo():pass") |
|
62769
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
184 self.check_suite("@class_decorator\n" |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
185 "class foo():pass") |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
186 self.check_suite("@class_decorator(arg)\n" |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
187 "class foo():pass") |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
188 self.check_suite("@decorator1\n" |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
189 "@decorator2\n" |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
190 "class foo():pass") |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
191 |
|
34920
67a89b43dcc7
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34887
diff
changeset
|
192 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
193 def test_import_from_statement(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 self.check_suite( |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
205 "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
|
206 self.check_suite( |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32888
diff
changeset
|
207 "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
|
208 self.check_suite( |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32888
diff
changeset
|
209 "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
|
210 self.check_suite( |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
211 "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
|
212 self.check_suite( |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32888
diff
changeset
|
213 "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
|
214 self.check_suite( |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32888
diff
changeset
|
215 "from sys.path import (dirname, basename as my_basename,)") |
|
49629
45ac5196fa67
backport r67077 from the trunk: parser module now correctly validates relative imports
Benjamin Peterson <benjamin@python.org>
parents:
37623
diff
changeset
|
216 self.check_suite("from .bogus import x") |
|
15752
c0822a05e923
Add more regression tests, including for the import statement variations.
Fred Drake <fdrake@acm.org>
parents:
15507
diff
changeset
|
217 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
218 def test_basic_import_statement(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
219 self.check_suite("import sys") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
220 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
|
221 self.check_suite("import sys, math") |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
222 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
|
223 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
|
224 |
|
62781
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
225 def test_relative_imports(self): |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
226 self.check_suite("from . import name") |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
227 self.check_suite("from .. import name") |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
228 self.check_suite("from .pkg import name") |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
229 self.check_suite("from ..pkg import name") |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
230 |
|
27777
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
231 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
|
232 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
|
233 "pass\n") |
|
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
234 |
|
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
235 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
|
236 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
|
237 |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
238 def test_with(self): |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
239 self.check_suite("with open('x'): pass\n") |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
240 self.check_suite("with open('x') as f: pass\n") |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
50065
diff
changeset
|
241 self.check_suite("with open('x') as f, open('y') as g: pass\n") |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
242 |
|
50065
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
243 def test_try_stmt(self): |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
244 self.check_suite("try: pass\nexcept: pass\n") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
245 self.check_suite("try: pass\nfinally: pass\n") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
246 self.check_suite("try: pass\nexcept A: pass\nfinally: pass\n") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
247 self.check_suite("try: pass\nexcept A: pass\nexcept: pass\n" |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
248 "finally: pass\n") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
249 self.check_suite("try: pass\nexcept: pass\nelse: pass\n") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
250 self.check_suite("try: pass\nexcept: pass\nelse: pass\n" |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
251 "finally: pass\n") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
252 |
|
62655
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50065
diff
changeset
|
253 def test_except_clause(self): |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50065
diff
changeset
|
254 self.check_suite("try: pass\nexcept: pass\n") |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50065
diff
changeset
|
255 self.check_suite("try: pass\nexcept A: pass\n") |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50065
diff
changeset
|
256 self.check_suite("try: pass\nexcept A, e: pass\n") |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50065
diff
changeset
|
257 self.check_suite("try: pass\nexcept A as e: pass\n") |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50065
diff
changeset
|
258 |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
259 def test_position(self): |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
260 # An absolutely minimal test of position information. Better |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
261 # tests would be a big project. |
|
57597
9c597b0a6a9b
fix test_parser from tokenizer tweak
Benjamin Peterson <benjamin@python.org>
parents:
57204
diff
changeset
|
262 code = "def f(x):\n return x + 1" |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
263 st1 = parser.suite(code) |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
264 st2 = st1.totuple(line_info=1, col_info=1) |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
265 |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
266 def walk(tree): |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
267 node_type = tree[0] |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
268 next = tree[1] |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
269 if isinstance(next, tuple): |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
270 for elt in tree[1:]: |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
271 for x in walk(elt): |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
272 yield x |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
273 else: |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
274 yield tree |
|
39683
904958216813
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
39635
diff
changeset
|
275 |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
276 terminals = list(walk(st2)) |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
277 self.assertEqual([ |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
278 (1, 'def', 1, 0), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
279 (1, 'f', 1, 4), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
280 (7, '(', 1, 5), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
281 (1, 'x', 1, 6), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
282 (8, ')', 1, 7), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
283 (11, ':', 1, 8), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
284 (4, '', 1, 9), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
285 (5, '', 2, -1), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
286 (1, 'return', 2, 4), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
287 (1, 'x', 2, 11), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
288 (14, '+', 2, 13), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
289 (2, '1', 2, 15), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
290 (4, '', 2, 16), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
291 (6, '', 2, -1), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
292 (4, '', 2, -1), |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
293 (0, '', 2, -1)], |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
294 terminals) |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
295 |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37623
diff
changeset
|
296 |
|
14111
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
297 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
298 # 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
|
299 # rejections for them. |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
300 # |
|
87b8f0ea50e8
Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
301 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
302 class IllegalSyntaxTestCase(unittest.TestCase): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
303 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
304 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
|
305 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
|
306 parser.sequence2st(tree) |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
307 except parser.ParserError: |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
308 pass |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
309 else: |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
310 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
|
311 |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
312 def test_junk(self): |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
313 # not even remotely valid: |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
314 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
|
315 |
|
18647
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
316 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
|
317 # 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
|
318 tree = \ |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
319 (257, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
320 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
321 (285, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
322 (259, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
323 (1, 'def'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
324 (1, 'f'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
325 (260, (7, '('), (8, ')')), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
326 (11, ':'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
327 (291, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
328 (4, ''), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
329 (5, ''), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
330 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
331 (265, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
332 (266, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
333 (272, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
334 (275, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
335 (1, 'return'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
336 (313, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
337 (292, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
338 (293, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
339 (294, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
340 (295, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
341 (297, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
342 (298, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
343 (299, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
344 (300, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
345 (301, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
346 (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
|
347 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
348 (265, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
349 (266, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
350 (272, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
351 (276, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
352 (1, 'yield'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
353 (313, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
354 (292, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
355 (293, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
356 (294, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
357 (295, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
358 (297, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
359 (298, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
360 (299, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
361 (300, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
362 (301, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
363 (302, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
364 (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
|
365 (4, ''))), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
366 (6, ''))))), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
367 (4, ''), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
368 (0, '')))) |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
369 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
|
370 |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
371 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
|
372 # 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
|
373 tree = \ |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
374 (257, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
375 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
376 (265, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
377 (266, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
378 (278, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
379 (1, 'from'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
380 (281, (1, '__future__')), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
381 (1, 'import'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
382 (279, (1, 'generators')))), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
383 (4, ''))), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
384 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
385 (285, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
386 (259, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
387 (1, 'def'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
388 (1, 'f'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
389 (260, (7, '('), (8, ')')), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
390 (11, ':'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
391 (291, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
392 (4, ''), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
393 (5, ''), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
394 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
395 (265, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
396 (266, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
397 (272, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
398 (275, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
399 (1, 'return'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
400 (313, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
401 (292, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
402 (293, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
403 (294, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
404 (295, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
405 (297, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
406 (298, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
407 (299, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
408 (300, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
409 (301, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
410 (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
|
411 (264, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
412 (265, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
413 (266, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
414 (272, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
415 (276, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
416 (1, 'yield'), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
417 (313, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
418 (292, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
419 (293, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
420 (294, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
421 (295, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
422 (297, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
423 (298, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
424 (299, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
425 (300, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
426 (301, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
427 (302, |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
428 (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
|
429 (4, ''))), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
430 (6, ''))))), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
431 (4, ''), |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
432 (0, '')))) |
|
ad82cafe45ac
Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents:
18027
diff
changeset
|
433 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
|
434 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
435 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
|
436 # Illegal input: print >>fp, |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
437 tree = \ |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
438 (257, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
439 (264, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
440 (265, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
441 (266, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
442 (268, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
443 (1, 'print'), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
444 (35, '>>'), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
445 (290, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
446 (291, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
447 (292, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
448 (293, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
449 (295, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
450 (296, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
451 (297, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
452 (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
|
453 (12, ','))), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
454 (4, ''))), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
455 (0, '')) |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
456 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
|
457 |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
458 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
|
459 # Illegal input: a,,c |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
460 tree = \ |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
461 (258, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
462 (311, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
463 (290, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
464 (291, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
465 (292, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
466 (293, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
467 (295, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
468 (296, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
469 (297, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
470 (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
|
471 (12, ','), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
472 (12, ','), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
473 (290, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
474 (291, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
475 (292, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
476 (293, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
477 (295, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
478 (296, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
479 (297, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
480 (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
|
481 (4, ''), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
482 (0, '')) |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
483 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
|
484 |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
485 def test_illegal_operator(self): |
|
24957
dc66eb4cd17a
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
486 # Illegal input: a $= b |
|
18027
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
487 tree = \ |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
488 (257, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
489 (264, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
490 (265, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
491 (266, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
492 (267, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
493 (312, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
494 (291, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
495 (292, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
496 (293, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
497 (294, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
498 (296, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
499 (297, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
500 (298, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
501 (299, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
502 (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
|
503 (268, (37, '$=')), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
504 (312, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
505 (291, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
506 (292, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
507 (293, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
508 (294, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
509 (296, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
510 (297, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
511 (298, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
512 (299, |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
513 (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
|
514 (4, ''))), |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
515 (0, '')) |
|
5391b9d022ac
Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents:
15966
diff
changeset
|
516 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
|
517 |
|
27777
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
518 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
|
519 #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
|
520 tree = (257, |
|
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
521 (264, |
|
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
522 (265, |
|
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
523 (266, |
|
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
524 (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
|
525 (4, ''), |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27777
diff
changeset
|
526 (0, '')) |
|
27777
5f6931b8352e
Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27517
diff
changeset
|
527 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
|
528 |
|
62781
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
529 def test_missing_import_source(self): |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
530 # from import a |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
531 tree = \ |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
532 (257, |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
533 (267, |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
534 (268, |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
535 (269, |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
536 (281, |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
537 (283, (1, 'from'), (1, 'import'), |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
538 (286, (284, (1, 'fred')))))), |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
539 (4, ''))), |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
540 (4, ''), (0, '')) |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
541 self.check_bad_tree(tree, "from import a") |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
542 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
543 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
544 class CompileTestCase(unittest.TestCase): |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
545 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
546 # These tests are very minimal. :-( |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
547 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
548 def test_compile_expr(self): |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
549 st = parser.expr('2 + 3') |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
550 code = parser.compilest(st) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62778
diff
changeset
|
551 self.assertEqual(eval(code), 5) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
552 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
553 def test_compile_suite(self): |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
554 st = parser.suite('x = 2; y = x + 3') |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
555 code = parser.compilest(st) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
556 globs = {} |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
557 exec code in globs |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62778
diff
changeset
|
558 self.assertEqual(globs['y'], 5) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
559 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
560 def test_compile_error(self): |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
561 st = parser.suite('1 = 3 + 4') |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
562 self.assertRaises(SyntaxError, parser.compilest, st) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
563 |
|
42308
6775ee6d89d3
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
Guido van Rossum <guido@python.org>
parents:
39683
diff
changeset
|
564 def test_compile_badunicode(self): |
|
6775ee6d89d3
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
Guido van Rossum <guido@python.org>
parents:
39683
diff
changeset
|
565 st = parser.suite('a = u"\U12345678"') |
|
6775ee6d89d3
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
Guido van Rossum <guido@python.org>
parents:
39683
diff
changeset
|
566 self.assertRaises(SyntaxError, parser.compilest, st) |
|
6775ee6d89d3
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
Guido van Rossum <guido@python.org>
parents:
39683
diff
changeset
|
567 st = parser.suite('a = u"\u1"') |
|
6775ee6d89d3
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
Guido van Rossum <guido@python.org>
parents:
39683
diff
changeset
|
568 self.assertRaises(SyntaxError, parser.compilest, st) |
|
6775ee6d89d3
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
Guido van Rossum <guido@python.org>
parents:
39683
diff
changeset
|
569 |
|
80593
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
570 def test_issue_9011(self): |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
571 # Issue 9011: compilation of an unary minus expression changed |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
572 # the meaning of the ST, so that a second compilation produced |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
573 # incorrect results. |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
574 st = parser.expr('-3') |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
575 code1 = parser.compilest(st) |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
576 self.assertEqual(eval(code1), -3) |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
577 code2 = parser.compilest(st) |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
578 self.assertEqual(eval(code2), -3) |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
579 |
|
ea36de7926f8
Issue #9011: AST creation no longer modifies CST for negated numeric literals.
Mark Dickinson <mdickinson@enthought.com>
parents:
78396
diff
changeset
|
580 |
|
45443
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
581 class ParserStackLimitTestCase(unittest.TestCase): |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
582 """try to push the parser to/over it's limits. |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
583 see http://bugs.python.org/issue1881 for a discussion |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
584 """ |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
585 def _nested_expression(self, level): |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
586 return "["*level+"]"*level |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
587 |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
588 def test_deeply_nested_list(self): |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
589 e = self._nested_expression(99) |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
590 st = parser.expr(e) |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
591 st.compile() |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
592 |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
593 def test_trigger_memory_error(self): |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
594 e = self._nested_expression(100) |
|
45849
3b39b7bb2c07
Note that the stderr output of the test is intentional.
Martin v. Löwis <martin@v.loewis.de>
parents:
45443
diff
changeset
|
595 print >>sys.stderr, "Expecting 's_push: parser stack overflow' in next line" |
|
45443
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
596 self.assertRaises(MemoryError, parser.expr, e) |
|
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
597 |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
598 class STObjectTestCase(unittest.TestCase): |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
599 """Test operations on ST objects themselves""" |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
600 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
601 check_sizeof = support.check_sizeof |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
602 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
603 @support.cpython_only |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
604 def test_sizeof(self): |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
605 def XXXROUNDUP(n): |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
606 if n <= 1: |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
607 return n |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
608 if n <= 128: |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
609 return (n + 3) & ~3 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
610 return 1 << (n - 1).bit_length() |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
611 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
612 basesize = support.calcobjsize('Pii') |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
613 nodesize = struct.calcsize('hP3iP0h') |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
614 def sizeofchildren(node): |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
615 if node is None: |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
616 return 0 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
617 res = 0 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
618 hasstr = len(node) > 1 and isinstance(node[-1], str) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
619 if hasstr: |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
620 res += len(node[-1]) + 1 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
621 children = node[1:-1] if hasstr else node[1:] |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
622 if children: |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
623 res += XXXROUNDUP(len(children)) * nodesize |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
624 for child in children: |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
625 res += sizeofchildren(child) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
626 return res |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
627 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
628 def check_st_sizeof(st): |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
629 self.check_sizeof(st, basesize + nodesize + |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
630 sizeofchildren(st.totuple())) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
631 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
632 check_st_sizeof(parser.expr('2 + 3')) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
633 check_st_sizeof(parser.expr('2 + 3 + 4')) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
634 check_st_sizeof(parser.suite('x = 2 + 3')) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
635 check_st_sizeof(parser.suite('')) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
636 check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-')) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
637 check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']')) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
638 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
639 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
640 # XXX tests for pickling and unpickling of ST objects should go here |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
641 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18670
diff
changeset
|
642 def test_main(): |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
643 support.run_unittest( |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
27963
diff
changeset
|
644 RoundtripLegalSyntaxTestCase, |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
645 IllegalSyntaxTestCase, |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35298
diff
changeset
|
646 CompileTestCase, |
|
45443
ca5f2f960617
Issue 1881. Increased the stack limit from 500 to 1500. Also added
Facundo Batista <facundobatista@gmail.com>
parents:
42308
diff
changeset
|
647 ParserStackLimitTestCase, |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68256
diff
changeset
|
648 STObjectTestCase, |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
27963
diff
changeset
|
649 ) |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18670
diff
changeset
|
650 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18670
diff
changeset
|
651 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18670
diff
changeset
|
652 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
|
653 test_main() |
