annotate Lib/test/test_parser.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents f683ca2b30e3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 import parser
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
2 import unittest
45852
30c4e1ca8421 Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45446
diff changeset
3 import sys
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
4 import operator
78391
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
5 import struct
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45852
diff changeset
6 from test import support
82575
10a82140f36d #11963: avoid printing messages in test_parser. Initial patch by Éric Araujo.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 78397
diff changeset
7 from test.script_helper import assert_python_failure
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 # 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
11 # 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
12 # of the parser module.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
15 class RoundtripLegalSyntaxTestCase(unittest.TestCase):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
16
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
17 def roundtrip(self, f, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
18 st1 = f(s)
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
19 t = st1.totuple()
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
20 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
21 st2 = parser.sequence2st(t)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
22 except parser.ParserError as why:
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
23 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
24
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
25 self.assertEqual(t, st2.totuple(),
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
26 "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
27
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
28 def check_expr(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
29 self.roundtrip(parser.expr, s)
14214
b5fb175ad528 Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents: 14111
diff changeset
30
49624
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
31 def test_flags_passed(self):
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
32 # The unicode literals flags has to be passed from the paser to AST
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
33 # generation.
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
34 suite = parser.suite("from __future__ import unicode_literals; x = ''")
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
35 code = suite.compile()
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
36 scope = {}
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
37 exec(code, {}, scope)
58473
71acd4482e65 Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 57678
diff changeset
38 self.assertIsInstance(scope["x"], str)
49624
f3234e43e1fe Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48788
diff changeset
39
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
40 def check_suite(self, s):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
41 self.roundtrip(parser.suite, s)
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
43 def test_yield_statement(self):
22719
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 self.check_suite("def f(): yield 1; return")
74356
d64ac9ab4cd0 Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents: 70638
diff changeset
55 self.check_suite("def f(): yield from 1")
d64ac9ab4cd0 Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents: 70638
diff changeset
56 self.check_suite("def f(): x = yield from 1")
d64ac9ab4cd0 Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents: 70638
diff changeset
57 self.check_suite("def f(): f((yield from 1))")
d64ac9ab4cd0 Implement PEP 380 - 'yield from' (closes #11682)
Nick Coghlan <ncoghlan@gmail.com>
parents: 70638
diff changeset
58 self.check_suite("def f(): yield 1; return 1")
22719
fa0ac845929b Remove some now-obsolete generator future statements.
Tim Peters <tim.peters@gmail.com>
parents: 20013
diff changeset
59 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
60 " 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
61 " 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
62 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
63 " if (yield):\n"
b2fe5f8fcfdd PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents: 34920
diff changeset
64 " 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
65
76647
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
66 def test_nonlocal_statement(self):
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
67 self.check_suite("def f():\n"
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
68 " x = 0\n"
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
69 " def g():\n"
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
70 " nonlocal x\n")
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
71 self.check_suite("def f():\n"
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
72 " x = y = 0\n"
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
73 " def g():\n"
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
74 " nonlocal x, y\n")
b7e491b9094f Issue #14696: Fix parser module to understand 'nonlocal' declarations.
Mark Dickinson <mdickinson@enthought.com>
parents: 76635
diff changeset
75
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
76 def test_expressions(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
77 self.check_expr("foo(1)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
78 self.check_expr("[1, 2, 3]")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
79 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
80 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
81 self.check_expr("[x**3 for x in range(20) if x % 2 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
82 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
83 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
84 self.check_expr("list(x**3 for x in range(20) if x % 2 if x % 3)")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
85 self.check_expr("foo(*args)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
86 self.check_expr("foo(*args, **kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
87 self.check_expr("foo(**kw)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
88 self.check_expr("foo(key=value)")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
89 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
90 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
91 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
92 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
93 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
94 self.check_expr("foo(a, b, c, **kw)")
48788
6d6d3e037550 Merged revisions 65885,65892,65894,65898 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47201
diff changeset
95 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
96 self.check_expr("foo + bar")
27517
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
97 self.check_expr("foo - bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
98 self.check_expr("foo * bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
99 self.check_expr("foo / bar")
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
100 self.check_expr("foo // bar")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
101 self.check_expr("lambda: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
102 self.check_expr("lambda x: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
103 self.check_expr("lambda *y: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
104 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
105 self.check_expr("lambda **z: 0")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
106 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
107 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
108 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
109 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
110 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
111 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
112 self.check_expr("lambda x, *y, **z: 0")
32121
302d399cfd37 SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
113 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
114 self.check_expr("foo(x for x in range(10))")
76824
2b1cc84bf1d9 Issue #14741: Fix missing support for ellipsis in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76822
diff changeset
115 self.check_expr("...")
2b1cc84bf1d9 Issue #14741: Fix missing support for ellipsis in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76822
diff changeset
116 self.check_expr("a[...]")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
117
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
118 def test_simple_expression(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
119 # expr_stmt
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
120 self.check_suite("a")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
121
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
122 def test_simple_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
123 self.check_suite("a = b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
124 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
125
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
126 def test_simple_augmented_assignments(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
127 self.check_suite("a += b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
128 self.check_suite("a -= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
129 self.check_suite("a *= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
130 self.check_suite("a /= b")
27517
51abb5e86226 Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents: 24957
diff changeset
131 self.check_suite("a //= b")
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
132 self.check_suite("a %= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
133 self.check_suite("a &= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
134 self.check_suite("a |= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
135 self.check_suite("a ^= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
136 self.check_suite("a <<= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
137 self.check_suite("a >>= b")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
138 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
139
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
140 def test_function_defs(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
141 self.check_suite("def f(): pass")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
159 self.check_suite("@staticmethod\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
160 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
161 self.check_suite("@staticmethod\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
162 "@funcattrs(x, y)\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
163 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
164 self.check_suite("@funcattrs()\n"
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
165 "def f(): pass")
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32121
diff changeset
166
76635
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
167 # keyword-only arguments
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
168 self.check_suite("def f(*, a): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
169 self.check_suite("def f(*, a = 5): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
170 self.check_suite("def f(*, a = 5, b): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
171 self.check_suite("def f(*, a, b = 5): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
172 self.check_suite("def f(*, a, b = 5, **kwds): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
173 self.check_suite("def f(*args, a): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
174 self.check_suite("def f(*args, a = 5): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
175 self.check_suite("def f(*args, a = 5, b): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
176 self.check_suite("def f(*args, a, b = 5): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
177 self.check_suite("def f(*args, a, b = 5, **kwds): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
178
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
179 # function annotations
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
180 self.check_suite("def f(a: int): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
181 self.check_suite("def f(a: int = 5): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
182 self.check_suite("def f(*args: list): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
183 self.check_suite("def f(**kwds: dict): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
184 self.check_suite("def f(*, a: int): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
185 self.check_suite("def f(*, a: int = 5): pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
186 self.check_suite("def f() -> int: pass")
9f57d66689ca Issue #9154: Fix parser module to understand function annotations.
Mark Dickinson <mdickinson@enthought.com>
parents: 68257
diff changeset
187
34887
7c2780c9e51b Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents: 33353
diff changeset
188 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
189 self.check_suite("class foo():pass")
43862
d4f9706cb46b Patch 1144 by David Binger, fix for parser module. With unittest.
Guido van Rossum <guido@python.org>
parents: 42312
diff changeset
190 self.check_suite("class foo(object):pass")
62774
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
191 self.check_suite("@class_decorator\n"
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
192 "class foo():pass")
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
193 self.check_suite("@class_decorator(arg)\n"
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
194 "class foo():pass")
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
195 self.check_suite("@decorator1\n"
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
196 "@decorator2\n"
18282039c5c9 Merged revisions 82537 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62647
diff changeset
197 "class foo():pass")
34920
67a89b43dcc7 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 34887
diff changeset
198
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
199 def test_import_from_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 self.check_suite(
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
211 "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
212 self.check_suite(
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
213 "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
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 as my_dirname, basename,)")
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
216 self.check_suite(
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
217 "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
218 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
219 "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
220 self.check_suite(
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32888
diff changeset
221 "from sys.path import (dirname, basename as my_basename,)")
49633
bd0e9a9cd283 Merged revisions 67028,67040,67044,67046,67052,67065,67070,67077,67082 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49624
diff changeset
222 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
223
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
224 def test_basic_import_statement(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
225 self.check_suite("import sys")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
226 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
227 self.check_suite("import sys, math")
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
228 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
229 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
230
62789
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
231 def test_relative_imports(self):
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
232 self.check_suite("from . import name")
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
233 self.check_suite("from .. import name")
62791
3aa22428582a Merged revisions 82555 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62789
diff changeset
234 # check all the way up to '....', since '...' is tokenized
3aa22428582a Merged revisions 82555 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62789
diff changeset
235 # differently from '.' (it's an ellipsis token).
3aa22428582a Merged revisions 82555 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62789
diff changeset
236 self.check_suite("from ... import name")
3aa22428582a Merged revisions 82555 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62789
diff changeset
237 self.check_suite("from .... import name")
62789
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
238 self.check_suite("from .pkg import name")
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
239 self.check_suite("from ..pkg import name")
62791
3aa22428582a Merged revisions 82555 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62789
diff changeset
240 self.check_suite("from ...pkg import name")
3aa22428582a Merged revisions 82555 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62789
diff changeset
241 self.check_suite("from ....pkg import name")
62789
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
242
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
243 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
244 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
245 "pass\n")
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
246
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
247 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
248 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
249
49908
ed8adfef26c6 Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49633
diff changeset
250 def test_with(self):
ed8adfef26c6 Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49633
diff changeset
251 self.check_suite("with open('x'): pass\n")
ed8adfef26c6 Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49633
diff changeset
252 self.check_suite("with open('x') as f: pass\n")
54338
287ce30d08b5 Merged revisions 72924 via svnmerge from
Georg Brandl <georg@python.org>
parents: 51244
diff changeset
253 self.check_suite("with open('x') as f, open('y') as g: pass\n")
49908
ed8adfef26c6 Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 49633
diff changeset
254
50079
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
255 def test_try_stmt(self):
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
256 self.check_suite("try: pass\nexcept: pass\n")
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
257 self.check_suite("try: pass\nfinally: pass\n")
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
258 self.check_suite("try: pass\nexcept A: pass\nfinally: pass\n")
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
259 self.check_suite("try: pass\nexcept A: pass\nexcept: pass\n"
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
260 "finally: pass\n")
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
261 self.check_suite("try: pass\nexcept: pass\nelse: pass\n")
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
262 self.check_suite("try: pass\nexcept: pass\nelse: pass\n"
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
263 "finally: pass\n")
a86cdf49b821 Manual merge of r67639 from py3k branch:
Georg Brandl <georg@python.org>
parents: 49908
diff changeset
264
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
265 def test_position(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
266 # An absolutely minimal test of position information. Better
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
267 # tests would be a big project.
57678
a769a9b34fbc Merged revisions 76052,76522,76591,76689,76697,76733 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 57206
diff changeset
268 code = "def f(x):\n return x + 1"
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
269 st1 = parser.suite(code)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
270 st2 = st1.totuple(line_info=1, col_info=1)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
271
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
272 def walk(tree):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
273 node_type = tree[0]
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
274 next = tree[1]
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
275 if isinstance(next, tuple):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
276 for elt in tree[1:]:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
277 for x in walk(elt):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
278 yield x
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
279 else:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
280 yield tree
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
281
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
282 terminals = list(walk(st2))
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
283 self.assertEqual([
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
284 (1, 'def', 1, 0),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
285 (1, 'f', 1, 4),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
286 (7, '(', 1, 5),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
287 (1, 'x', 1, 6),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
288 (8, ')', 1, 7),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
289 (11, ':', 1, 8),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
290 (4, '', 1, 9),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
291 (5, '', 2, -1),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
292 (1, 'return', 2, 4),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
293 (1, 'x', 2, 11),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
294 (14, '+', 2, 13),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
295 (2, '1', 2, 15),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
296 (4, '', 2, 16),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
297 (6, '', 2, -1),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
298 (4, '', 2, -1),
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
299 (0, '', 2, -1)],
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
300 terminals)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
301
56237
7ee140b7ef93 fix an ambiguity in the grammar from the implementation of extended unpacking
Benjamin Peterson <benjamin@python.org>
parents: 55003
diff changeset
302 def test_extended_unpacking(self):
7ee140b7ef93 fix an ambiguity in the grammar from the implementation of extended unpacking
Benjamin Peterson <benjamin@python.org>
parents: 55003
diff changeset
303 self.check_suite("*a = y")
7ee140b7ef93 fix an ambiguity in the grammar from the implementation of extended unpacking
Benjamin Peterson <benjamin@python.org>
parents: 55003
diff changeset
304 self.check_suite("x, *b, = m")
7ee140b7ef93 fix an ambiguity in the grammar from the implementation of extended unpacking
Benjamin Peterson <benjamin@python.org>
parents: 55003
diff changeset
305 self.check_suite("[*a, *b] = y")
7ee140b7ef93 fix an ambiguity in the grammar from the implementation of extended unpacking
Benjamin Peterson <benjamin@python.org>
parents: 55003
diff changeset
306 self.check_suite("for [*x, b] in x: pass")
7ee140b7ef93 fix an ambiguity in the grammar from the implementation of extended unpacking
Benjamin Peterson <benjamin@python.org>
parents: 55003
diff changeset
307
76818
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
308 def test_raise_statement(self):
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
309 self.check_suite("raise\n")
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
310 self.check_suite("raise e\n")
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
311 self.check_suite("try:\n"
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
312 " suite\n"
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
313 "except Exception as e:\n"
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
314 " raise ValueError from e\n")
fc17f70292f6 Issue #14701: Add missing support for 'raise ... from' in parser module.
Mark Dickinson <mdickinson@enthought.com>
parents: 76647
diff changeset
315
76822
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
316 def test_set_displays(self):
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
317 self.check_expr('{2}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
318 self.check_expr('{2,}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
319 self.check_expr('{2, 3}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
320 self.check_expr('{2, 3,}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
321
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
322 def test_dict_displays(self):
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
323 self.check_expr('{}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
324 self.check_expr('{a:b}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
325 self.check_expr('{a:b,}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
326 self.check_expr('{a:b, c:d}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
327 self.check_expr('{a:b, c:d,}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
328
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
329 def test_set_comprehensions(self):
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
330 self.check_expr('{x for x in seq}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
331 self.check_expr('{f(x) for x in seq}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
332 self.check_expr('{f(x) for x in seq if condition(x)}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
333
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
334 def test_dict_comprehensions(self):
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
335 self.check_expr('{x:x for x in seq}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
336 self.check_expr('{x**2:x[3] for x in seq if condition(x)}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
337 self.check_expr('{x:x for x in seq1 for y in seq2 if condition(x, y)}')
129289144dfb Issue #14697: Fix missing parser module support for set displays and set comprehensions.
Mark Dickinson <mdickinson@enthought.com>
parents: 76818
diff changeset
338
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39782
diff changeset
339
14111
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
340 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
341 # 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
342 # rejections for them.
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
343 #
87b8f0ea50e8 Add a minimal test suite for the parser module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
344
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
345 class IllegalSyntaxTestCase(unittest.TestCase):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
346
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
347 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
348 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
349 parser.sequence2st(tree)
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
350 except parser.ParserError:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
351 pass
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
352 else:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
353 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
354
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
355 def test_junk(self):
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
356 # not even remotely valid:
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
357 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
358
18647
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
359 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
360 # 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
361 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
362 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
363 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
364 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
365 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
366 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
367 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
368 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
369 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
370 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
371 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
372 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
373 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
374 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
375 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
376 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
377 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
378 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
379 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
380 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
381 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
382 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
383 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
384 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
385 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
386 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
387 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
388 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
389 (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
390 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
391 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
392 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
393 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
394 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
395 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
396 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
397 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
398 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
399 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
400 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
401 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
402 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
403 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
404 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
405 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
406 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
407 (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
408 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
409 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
410 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
411 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
412 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
413
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
414 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
415 # 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
416 tree = \
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
417 (257,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
418 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
419 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
420 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
421 (278,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
422 (1, 'from'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
423 (281, (1, '__future__')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
424 (1, 'import'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
425 (279, (1, 'generators')))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
426 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
427 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
428 (285,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
429 (259,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
430 (1, 'def'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
431 (1, 'f'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
432 (260, (7, '('), (8, ')')),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
433 (11, ':'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
434 (291,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
435 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
436 (5, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
437 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
438 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
439 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
440 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
441 (275,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
442 (1, 'return'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
443 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
444 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
445 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
446 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
447 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
448 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
449 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
450 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
451 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
452 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
453 (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
454 (264,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
455 (265,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
456 (266,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
457 (272,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
458 (276,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
459 (1, 'yield'),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
460 (313,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
461 (292,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
462 (293,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
463 (294,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
464 (295,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
465 (297,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
466 (298,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
467 (299,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
468 (300,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
469 (301,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
470 (302,
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
471 (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
472 (4, ''))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
473 (6, ''))))),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
474 (4, ''),
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
475 (0, ''))))
ad82cafe45ac Added tests for the new yield support in the parser module.
Fred Drake <fdrake@acm.org>
parents: 18027
diff changeset
476 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
477
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
478 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
479 # Illegal input: a,,c
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
480 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
481 (258,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
482 (311,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
483 (290,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
484 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
485 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
486 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
487 (295,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
488 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
489 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
490 (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
491 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
492 (12, ','),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
493 (290,
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 (295,
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, (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
501 (4, ''),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
502 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
503 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
504
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
505 def test_illegal_operator(self):
24957
dc66eb4cd17a Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
506 # Illegal input: a $= b
18027
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
507 tree = \
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
508 (257,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
509 (264,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
510 (265,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
511 (266,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
512 (267,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
513 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
514 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
515 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
516 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
517 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
518 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
519 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
520 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
521 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
522 (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
523 (268, (37, '$=')),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
524 (312,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
525 (291,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
526 (292,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
527 (293,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
528 (294,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
529 (296,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
530 (297,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
531 (298,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
532 (299,
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
533 (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
534 (4, ''))),
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
535 (0, ''))
5391b9d022ac Convert the parser module test to use PyUnit.
Fred Drake <fdrake@acm.org>
parents: 15966
diff changeset
536 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
537
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
538 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
539 #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
540 tree = (257,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
541 (264,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
542 (265,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
543 (266,
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
544 (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
545 (4, ''),
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27777
diff changeset
546 (0, ''))
27777
5f6931b8352e Add tests and news entry about parser errors from bug #678518.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27517
diff changeset
547 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
548
62789
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
549 def test_missing_import_source(self):
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
550 # from import fred
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
551 tree = \
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
552 (257,
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
553 (268,
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
554 (269,
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
555 (270,
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
556 (282,
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
557 (284, (1, 'from'), (1, 'import'),
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
558 (287, (285, (1, 'fred')))))),
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
559 (4, ''))),
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
560 (4, ''), (0, ''))
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
561 self.check_bad_tree(tree, "from import fred")
692b7989cd92 Merged revisions 82552-82553 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 62774
diff changeset
562
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
563
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
564 class CompileTestCase(unittest.TestCase):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
565
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
566 # These tests are very minimal. :-(
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
567
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
568 def test_compile_expr(self):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
569 st = parser.expr('2 + 3')
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
570 code = parser.compilest(st)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
571 self.assertEqual(eval(code), 5)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
572
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
573 def test_compile_suite(self):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
574 st = parser.suite('x = 2; y = x + 3')
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
575 code = parser.compilest(st)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
576 globs = {}
39782
c94f37054f19 Patch #1550800: make exec a function.
Georg Brandl <georg@python.org>
parents: 37623
diff changeset
577 exec(code, globs)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
578 self.assertEqual(globs['y'], 5)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
579
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
580 def test_compile_error(self):
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
581 st = parser.suite('1 = 3 + 4')
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
582 self.assertRaises(SyntaxError, parser.compilest, st)
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
583
42309
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
584 def test_compile_badunicode(self):
42312
007ed6cdd1f7 Make test_parser pass after merge.
Guido van Rossum <guido@python.org>
parents: 42309
diff changeset
585 st = parser.suite('a = "\\U12345678"')
42309
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
586 self.assertRaises(SyntaxError, parser.compilest, st)
42312
007ed6cdd1f7 Make test_parser pass after merge.
Guido van Rossum <guido@python.org>
parents: 42309
diff changeset
587 st = parser.suite('a = "\\u1"')
42309
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
588 self.assertRaises(SyntaxError, parser.compilest, st)
bd6acfdb47d2 Merged revisions 56301-56442 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40788
diff changeset
589
62373
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
590 def test_issue_9011(self):
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
591 # Issue 9011: compilation of an unary minus expression changed
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
592 # the meaning of the ST, so that a second compilation produced
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
593 # incorrect results.
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
594 st = parser.expr('-3')
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
595 code1 = parser.compilest(st)
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
596 self.assertEqual(eval(code1), -3)
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
597 code2 = parser.compilest(st)
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
598 self.assertEqual(eval(code2), -3)
cb4997b6aa8b Issue #9011: Remove buggy and unnecessary ST->AST compilation code
Mark Dickinson <dickinsm@gmail.com>
parents: 59615
diff changeset
599
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
600 class ParserStackLimitTestCase(unittest.TestCase):
62374
2cc09f06950b Merged revisions 82043 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 55593
diff changeset
601 """try to push the parser to/over its limits.
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
602 see http://bugs.python.org/issue1881 for a discussion
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
603 """
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
604 def _nested_expression(self, level):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
605 return "["*level+"]"*level
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
606
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
607 def test_deeply_nested_list(self):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
608 # XXX used to be 99 levels in 2.x
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
609 e = self._nested_expression(93)
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
610 st = parser.expr(e)
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
611 st.compile()
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
612
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
613 def test_trigger_memory_error(self):
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
614 e = self._nested_expression(100)
82575
10a82140f36d #11963: avoid printing messages in test_parser. Initial patch by Éric Araujo.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 78397
diff changeset
615 rc, out, err = assert_python_failure('-c', e)
10a82140f36d #11963: avoid printing messages in test_parser. Initial patch by Éric Araujo.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 78397
diff changeset
616 # parsing the expression will result in an error message
10a82140f36d #11963: avoid printing messages in test_parser. Initial patch by Éric Araujo.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 78397
diff changeset
617 # followed by a MemoryError (see #11963)
82579
64b87578c071 #11963: fix Windows buildbots.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 82575
diff changeset
618 self.assertIn(b's_push: parser stack overflow', err)
64b87578c071 #11963: fix Windows buildbots.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 82575
diff changeset
619 self.assertIn(b'MemoryError', err)
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
620
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
621 class STObjectTestCase(unittest.TestCase):
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
622 """Test operations on ST objects themselves"""
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
623
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
624 def test_comparisons(self):
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
625 # ST objects should support order and equality comparisons
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
626 st1 = parser.expr('2 + 3')
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
627 st2 = parser.suite('x = 2; y = x + 3')
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
628 st3 = parser.expr('list(x**3 for x in range(20))')
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
629 st1_copy = parser.expr('2 + 3')
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
630 st2_copy = parser.suite('x = 2; y = x + 3')
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
631 st3_copy = parser.expr('list(x**3 for x in range(20))')
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
632
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
633 # exercise fast path for object identity
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
634 self.assertEqual(st1 == st1, True)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
635 self.assertEqual(st2 == st2, True)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
636 self.assertEqual(st3 == st3, True)
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
637 # slow path equality
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
638 self.assertEqual(st1, st1_copy)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
639 self.assertEqual(st2, st2_copy)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
640 self.assertEqual(st3, st3_copy)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
641 self.assertEqual(st1 == st2, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
642 self.assertEqual(st1 == st3, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
643 self.assertEqual(st2 == st3, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
644 self.assertEqual(st1 != st1, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
645 self.assertEqual(st2 != st2, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
646 self.assertEqual(st3 != st3, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
647 self.assertEqual(st1 != st1_copy, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
648 self.assertEqual(st2 != st2_copy, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
649 self.assertEqual(st3 != st3_copy, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
650 self.assertEqual(st2 != st1, True)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
651 self.assertEqual(st1 != st3, True)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
652 self.assertEqual(st3 != st2, True)
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
653 # we don't particularly care what the ordering is; just that
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
654 # it's usable and self-consistent
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
655 self.assertEqual(st1 < st2, not (st2 <= st1))
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
656 self.assertEqual(st1 < st3, not (st3 <= st1))
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
657 self.assertEqual(st2 < st3, not (st3 <= st2))
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
658 self.assertEqual(st1 < st2, st2 > st1)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
659 self.assertEqual(st1 < st3, st3 > st1)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
660 self.assertEqual(st2 < st3, st3 > st2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
661 self.assertEqual(st1 <= st2, st2 >= st1)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
662 self.assertEqual(st3 <= st1, st1 >= st3)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
663 self.assertEqual(st2 <= st3, st3 >= st2)
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
664 # transitivity
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
665 bottom = min(st1, st2, st3)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
666 top = max(st1, st2, st3)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
667 mid = sorted([st1, st2, st3])[1]
55593
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
668 self.assertTrue(bottom < mid)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
669 self.assertTrue(bottom < top)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
670 self.assertTrue(mid < top)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
671 self.assertTrue(bottom <= mid)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
672 self.assertTrue(bottom <= top)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
673 self.assertTrue(mid <= top)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
674 self.assertTrue(bottom <= bottom)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
675 self.assertTrue(mid <= mid)
0bb232078b8c Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54338
diff changeset
676 self.assertTrue(top <= top)
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
677 # interaction with other types
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
678 self.assertEqual(st1 == 1588.602459, False)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62791
diff changeset
679 self.assertEqual('spanish armada' != st2, True)
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
680 self.assertRaises(TypeError, operator.ge, st3, None)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
681 self.assertRaises(TypeError, operator.le, False, st1)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
682 self.assertRaises(TypeError, operator.lt, st1, 1815)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
683 self.assertRaises(TypeError, operator.gt, b'waterloo', st2)
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
684
78391
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
685 check_sizeof = support.check_sizeof
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
686
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
687 @support.cpython_only
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
688 def test_sizeof(self):
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
689 def XXXROUNDUP(n):
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
690 if n <= 1:
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
691 return n
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
692 if n <= 128:
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
693 return (n + 3) & ~3
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
694 return 1 << (n - 1).bit_length()
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
695
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
696 basesize = support.calcobjsize('Pii')
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
697 nodesize = struct.calcsize('hP3iP0h')
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
698 def sizeofchildren(node):
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
699 if node is None:
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
700 return 0
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
701 res = 0
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
702 hasstr = len(node) > 1 and isinstance(node[-1], str)
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
703 if hasstr:
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
704 res += len(node[-1]) + 1
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
705 children = node[1:-1] if hasstr else node[1:]
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
706 if children:
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
707 res += XXXROUNDUP(len(children)) * nodesize
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
708 for child in children:
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
709 res += sizeofchildren(child)
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
710 return res
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
711
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
712 def check_st_sizeof(st):
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
713 self.check_sizeof(st, basesize + nodesize +
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
714 sizeofchildren(st.totuple()))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
715
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
716 check_st_sizeof(parser.expr('2 + 3'))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
717 check_st_sizeof(parser.expr('2 + 3 + 4'))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
718 check_st_sizeof(parser.suite('x = 2 + 3'))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
719 check_st_sizeof(parser.suite(''))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
720 check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-'))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
721 check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']'))
91884d04de06 Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents: 76824
diff changeset
722
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
723
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
724 # XXX tests for pickling and unpickling of ST objects should go here
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
725
70638
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
726 class OtherParserCase(unittest.TestCase):
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
727
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
728 def test_two_args_to_expr(self):
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
729 # See bug #12264
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
730 with self.assertRaises(TypeError):
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
731 parser.expr("a", "b")
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
732
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
733 def test_main():
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45852
diff changeset
734 support.run_unittest(
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
735 RoundtripLegalSyntaxTestCase,
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
736 IllegalSyntaxTestCase,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35298
diff changeset
737 CompileTestCase,
45446
5e0772ed20d1 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43862
diff changeset
738 ParserStackLimitTestCase,
51244
e9675d72e3e3 Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50079
diff changeset
739 STObjectTestCase,
70638
3ffd8dea77bf only clear the parser error if it's set (closes #12264)
Benjamin Peterson <benjamin@python.org>
parents: 68257
diff changeset
740 OtherParserCase,
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27963
diff changeset
741 )
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
742
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
743
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18670
diff changeset
744 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
745 test_main()