annotate Lib/test/test_compile.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents ee5350f1d0c2
children fd9c9579050d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
1 import unittest
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
2 import sys
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
3 import _ast
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
4 from test import test_support
63641
657ae877c0bf Merged revisions 79187-79189 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47977
diff changeset
5 import textwrap
20939
13df8b6c2b80 Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19621
diff changeset
6
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
7 class TestSpecifics(unittest.TestCase):
20939
13df8b6c2b80 Fix SF buf #480096: Assign to __debug__ still allowed
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19621
diff changeset
8
57204
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
9 def test_no_ending_newline(self):
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
10 compile("hi", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
11 compile("hi\r", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
12
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
13 def test_empty(self):
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
14 compile("", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
15
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
16 def test_other_newlines(self):
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
17 compile("\r\n", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
18 compile("\r", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
19 compile("hi\r\nstuff\r\ndef f():\n pass\r", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
20 compile("this_is\rreally_old_mac\rdef f():\n pass", "<test>", "exec")
89f42938d5cc fix several compile() issues by translating newlines in the tokenizer
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
21
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
22 def test_debug_assignment(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
23 # catch assignments to __debug__
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
24 self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single')
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
25 import __builtin__
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
26 prev = __builtin__.__debug__
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
27 setattr(__builtin__, '__debug__', 'sure')
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
28 setattr(__builtin__, '__debug__', prev)
13714
c9d039196db6 added test case for fixed duplicate arguments bug in Python/compile.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
diff changeset
29
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
30 def test_argument_handling(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
31 # detect duplicate positional and keyword arguments
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
32 self.assertRaises(SyntaxError, eval, 'lambda a,a:0')
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
33 self.assertRaises(SyntaxError, eval, 'lambda a,a=1:0')
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
34 self.assertRaises(SyntaxError, eval, 'lambda a=1,a=1:0')
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
35 try:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
36 exec 'def f(a, a): pass'
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
37 self.fail("duplicate arguments")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
38 except SyntaxError:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
39 pass
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
40 try:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
41 exec 'def f(a = 0, a = 1): pass'
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
42 self.fail("duplicate keyword arguments")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
43 except SyntaxError:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
44 pass
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
45 try:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
46 exec 'def f(a): global a; a = 1'
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
47 self.fail("variable is global and local")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
48 except SyntaxError:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
49 pass
24159
cb728141ae12 Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents: 20968
diff changeset
50
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
51 def test_syntax_error(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
52 self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
16700
d2a8414a1eab SF patch #103749: implicit tuple + default arg
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16018
diff changeset
53
41975
c2ac22c6f98d Disallow function calls like foo(None=1).
Georg Brandl <georg@python.org>
parents: 39040
diff changeset
54 def test_none_keyword_arg(self):
c2ac22c6f98d Disallow function calls like foo(None=1).
Georg Brandl <georg@python.org>
parents: 39040
diff changeset
55 self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec")
c2ac22c6f98d Disallow function calls like foo(None=1).
Georg Brandl <georg@python.org>
parents: 39040
diff changeset
56
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
57 def test_duplicate_global_local(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
58 try:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
59 exec 'def f(a): global a; a = 1'
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
60 self.fail("variable is global and local")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
61 except SyntaxError:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
62 pass
16700
d2a8414a1eab SF patch #103749: implicit tuple + default arg
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16018
diff changeset
63
32890
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
64 def test_exec_with_general_mapping_for_locals(self):
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
65
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
66 class M:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
67 "Test mapping interface versus possible calls from eval()."
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
68 def __getitem__(self, key):
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
69 if key == 'a':
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
70 return 12
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
71 raise KeyError
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
72 def __setitem__(self, key, value):
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
73 self.results = (key, value)
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
74 def keys(self):
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
75 return list('xyz')
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
76
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
77 m = M()
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
78 g = globals()
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
79 exec 'z = a' in g, m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
80 self.assertEqual(m.results, ('z', 12))
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
81 try:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
82 exec 'z = b' in g, m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
83 except NameError:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
84 pass
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
85 else:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
86 self.fail('Did not detect a KeyError')
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
87 exec 'z = dir()' in g, m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
88 self.assertEqual(m.results, ('z', list('xyz')))
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
89 exec 'z = globals()' in g, m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
90 self.assertEqual(m.results, ('z', g))
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
91 exec 'z = locals()' in g, m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
92 self.assertEqual(m.results, ('z', m))
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
93 try:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
94 exec 'z = b' in m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
95 except TypeError:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
96 pass
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
97 else:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
98 self.fail('Did not validate globals as a real dict')
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
99
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
100 class A:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
101 "Non-mapping"
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
102 pass
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
103 m = A()
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
104 try:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
105 exec 'z = a' in g, m
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
106 except TypeError:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
107 pass
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
108 else:
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
109 self.fail('Did not validate locals as a mapping')
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
110
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
111 # Verify that dict subclasses work as well
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
112 class D(dict):
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
113 def __getitem__(self, key):
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
114 if key == 'a':
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
115 return 12
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
116 return dict.__getitem__(self, key)
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
117 d = D()
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
118 exec 'z = a' in g, d
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
119 self.assertEqual(d['z'], 12)
b8c2aa2be19a Completed the patch for Bug #215126.
Raymond Hettinger <python@rcn.com>
parents: 32723
diff changeset
120
35792
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
121 def test_extended_arg(self):
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
122 longexpr = 'x = x or ' + '-x' * 2500
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
123 code = '''
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
124 def f(x):
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
125 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
126 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
127 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
128 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
129 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
130 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
131 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
132 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
133 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
134 %s
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
135 # the expressions above have no effect, x == argument
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
136 while x:
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
137 x -= 1
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
138 # EXTENDED_ARG/JUMP_ABSOLUTE here
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
139 return x
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
140 ''' % ((longexpr,)*10)
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
141 exec code
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
142 self.assertEqual(f(5), 0)
b8b13b1ffe75 Fix problem handling EXTENDED_ARGs from SF bug # 1333982
Neal Norwitz <nnorwitz@gmail.com>
parents: 33822
diff changeset
143
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
144 def test_complex_args(self):
16700
d2a8414a1eab SF patch #103749: implicit tuple + default arg
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16018
diff changeset
145
59807
dd68e04ee2e8 Silence some py3k SyntaxWarning using check_py3k_warnings() with "exec" statements.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 59672
diff changeset
146 with test_support.check_py3k_warnings(
63641
657ae877c0bf Merged revisions 79187-79189 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47977
diff changeset
147 ("tuple parameter unpacking has been removed", SyntaxWarning)):
657ae877c0bf Merged revisions 79187-79189 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47977
diff changeset
148 exec textwrap.dedent('''
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
149 def comp_args((a, b)):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
150 return a,b
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
151 self.assertEqual(comp_args((1, 2)), (1, 2))
16700
d2a8414a1eab SF patch #103749: implicit tuple + default arg
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16018
diff changeset
152
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
153 def comp_args((a, b)=(3, 4)):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
154 return a, b
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
155 self.assertEqual(comp_args((1, 2)), (1, 2))
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
156 self.assertEqual(comp_args(), (3, 4))
16700
d2a8414a1eab SF patch #103749: implicit tuple + default arg
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16018
diff changeset
157
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
158 def comp_args(a, (b, c)):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
159 return a, b, c
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
160 self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3))
16700
d2a8414a1eab SF patch #103749: implicit tuple + default arg
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16018
diff changeset
161
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
162 def comp_args(a=2, (b, c)=(3, 4)):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
163 return a, b, c
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
164 self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3))
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
165 self.assertEqual(comp_args(), (2, 3, 4))
63641
657ae877c0bf Merged revisions 79187-79189 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47977
diff changeset
166 ''')
19501
ce4f1e98ba7e SF bug [#455775] float parsing discrepancy.
Tim Peters <tim.peters@gmail.com>
parents: 16723
diff changeset
167
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
168 def test_argument_order(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
169 try:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
170 exec 'def f(a=1, (b, c)): pass'
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
171 self.fail("non-default args after default")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
172 except SyntaxError:
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
173 pass
19501
ce4f1e98ba7e SF bug [#455775] float parsing discrepancy.
Tim Peters <tim.peters@gmail.com>
parents: 16723
diff changeset
174
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
175 def test_float_literals(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
176 # testing bad float literals
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
177 self.assertRaises(SyntaxError, eval, "2e")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
178 self.assertRaises(SyntaxError, eval, "2.0e+")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
179 self.assertRaises(SyntaxError, eval, "1e-")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
180 self.assertRaises(SyntaxError, eval, "3-4e/21")
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19501
diff changeset
181
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
182 def test_indentation(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
183 # testing compile() of indented block w/o trailing newline"
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
184 s = """
27878
be7683a6f521 - Finally fixed the bug in compile() and exec where a string ending
Guido van Rossum <guido@python.org>
parents: 27846
diff changeset
185 if 1:
be7683a6f521 - Finally fixed the bug in compile() and exec where a string ending
Guido van Rossum <guido@python.org>
parents: 27846
diff changeset
186 if 2:
be7683a6f521 - Finally fixed the bug in compile() and exec where a string ending
Guido van Rossum <guido@python.org>
parents: 27846
diff changeset
187 pass"""
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
188 compile(s, "<string>", "exec")
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
189
39040
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
190 # This test is probably specific to CPython and may not generalize
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
191 # to other implementations. We are trying to ensure that when
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
192 # the first line of code starts after 256, correct line numbers
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
193 # in tracebacks are still produced.
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
194 def test_leading_newlines(self):
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
195 s256 = "".join(["\n"] * 256 + ["spam"])
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
196 co = compile(s256, 'fn', 'exec')
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
197 self.assertEqual(co.co_firstlineno, 257)
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
198 self.assertEqual(co.co_lnotab, '')
ca3d9a67126b Bug #1512814, Fix incorrect lineno's when code at module scope
Neal Norwitz <nnorwitz@gmail.com>
parents: 39039
diff changeset
199
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
200 def test_literals_with_leading_zeroes(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
201 for arg in ["077787", "0xj", "0x.", "0e", "090000000000000",
45791
62ef0ea034f4 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Eric Smith <eric@trueblade.com>
parents: 41974
diff changeset
202 "080000000000000", "000000000000009", "000000000000008",
62ef0ea034f4 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Eric Smith <eric@trueblade.com>
parents: 41974
diff changeset
203 "0b42", "0BADCAFE", "0o123456789", "0b1.1", "0o4.2",
46545
459083c6be15 Issue2681: the literal 0o8 was wrongly accepted, and evaluated as float(0.0).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46193
diff changeset
204 "0b101j2", "0o153j2", "0b100e1", "0o777e1", "0o8", "0o78"]:
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
205 self.assertRaises(SyntaxError, eval, arg)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
206
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
207 self.assertEqual(eval("0777"), 511)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
208 self.assertEqual(eval("0777L"), 511)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
209 self.assertEqual(eval("000777"), 511)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
210 self.assertEqual(eval("0xff"), 255)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
211 self.assertEqual(eval("0xffL"), 255)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
212 self.assertEqual(eval("0XfF"), 255)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
213 self.assertEqual(eval("0777."), 777)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
214 self.assertEqual(eval("0777.0"), 777)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
215 self.assertEqual(eval("000000000000000000000000000000000000000000000000000777e0"), 777)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
216 self.assertEqual(eval("0777e1"), 7770)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
217 self.assertEqual(eval("0e0"), 0)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
218 self.assertEqual(eval("0000E-012"), 0)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
219 self.assertEqual(eval("09.5"), 9.5)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
220 self.assertEqual(eval("0777j"), 777j)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
221 self.assertEqual(eval("00j"), 0j)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
222 self.assertEqual(eval("00.0"), 0)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
223 self.assertEqual(eval("0e3"), 0)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
224 self.assertEqual(eval("090000000000000."), 90000000000000.)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
225 self.assertEqual(eval("090000000000000.0000000000000000000000"), 90000000000000.)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
226 self.assertEqual(eval("090000000000000e0"), 90000000000000.)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
227 self.assertEqual(eval("090000000000000e-0"), 90000000000000.)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
228 self.assertEqual(eval("090000000000000j"), 90000000000000j)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
229 self.assertEqual(eval("000000000000007"), 7)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
230 self.assertEqual(eval("000000000000008."), 8.)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
231 self.assertEqual(eval("000000000000009."), 9.)
45791
62ef0ea034f4 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Eric Smith <eric@trueblade.com>
parents: 41974
diff changeset
232 self.assertEqual(eval("0b101010"), 42)
62ef0ea034f4 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Eric Smith <eric@trueblade.com>
parents: 41974
diff changeset
233 self.assertEqual(eval("-0b000000000010"), -2)
62ef0ea034f4 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Eric Smith <eric@trueblade.com>
parents: 41974
diff changeset
234 self.assertEqual(eval("0o777"), 511)
62ef0ea034f4 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Eric Smith <eric@trueblade.com>
parents: 41974
diff changeset
235 self.assertEqual(eval("-0o0000010"), -8)
47978
ca0d620cd63b Issue #3360: Fix incorrect parsing of '020000000000.0'.
Mark Dickinson <dickinsm@gmail.com>
parents: 46171
diff changeset
236 self.assertEqual(eval("020000000000.0"), 20000000000.0)
ca0d620cd63b Issue #3360: Fix incorrect parsing of '020000000000.0'.
Mark Dickinson <dickinsm@gmail.com>
parents: 46171
diff changeset
237 self.assertEqual(eval("037777777777e0"), 37777777777.0)
ca0d620cd63b Issue #3360: Fix incorrect parsing of '020000000000.0'.
Mark Dickinson <dickinsm@gmail.com>
parents: 46171
diff changeset
238 self.assertEqual(eval("01000000000000000000000.0"),
ca0d620cd63b Issue #3360: Fix incorrect parsing of '020000000000.0'.
Mark Dickinson <dickinsm@gmail.com>
parents: 46171
diff changeset
239 1000000000000000000000.0)
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
240
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
241 def test_unary_minus(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
242 # Verify treatment of unary minus on negative numbers SF bug #660455
31042
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
243 if sys.maxint == 2147483647:
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
244 # 32-bit machine
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
245 all_one_bits = '0xffffffff'
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
246 self.assertEqual(eval(all_one_bits), 4294967295L)
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
247 self.assertEqual(eval("-" + all_one_bits), -4294967295L)
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
248 elif sys.maxint == 9223372036854775807:
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
249 # 64-bit machine
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
250 all_one_bits = '0xffffffffffffffff'
31042
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
251 self.assertEqual(eval(all_one_bits), 18446744073709551615L)
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
252 self.assertEqual(eval("-" + all_one_bits), -18446744073709551615L)
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
253 else:
9c846c3df6f3 - Removed FutureWarnings related to hex/oct literals and conversions
Guido van Rossum <guido@python.org>
parents: 29583
diff changeset
254 self.fail("How many bits *does* this machine have???")
68503
ee5350f1d0c2 #11515: fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 68256
diff changeset
255 # Verify treatment of constant folding on -(sys.maxint+1)
39038
64ccd745ea92 Fix SF bug 1441486: bad unary minus folding in compiler.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 39035
diff changeset
256 # i.e. -2147483648 on 32 bit platforms. Should return int, not long.
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
257 self.assertIsInstance(eval("%s" % (-sys.maxint - 1)), int)
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
258 self.assertIsInstance(eval("%s" % (-sys.maxint - 2)), long)
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
259
39039
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
260 if sys.maxint == 9223372036854775807:
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
261 def test_32_63_bit_values(self):
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
262 a = +4294967296 # 1 << 32
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
263 b = -4294967296 # 1 << 32
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
264 c = +281474976710656 # 1 << 48
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
265 d = -281474976710656 # 1 << 48
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
266 e = +4611686018427387904 # 1 << 62
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
267 f = -4611686018427387904 # 1 << 62
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
268 g = +9223372036854775807 # 1 << 63 - 1
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
269 h = -9223372036854775807 # 1 << 63 - 1
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
270
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
271 for variable in self.test_32_63_bit_values.func_code.co_consts:
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
272 if variable is not None:
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
273 self.assertIsInstance(variable, int)
39039
95f9e0184555 On 64 bit systems, int literals that use less than 64 bits are now ints
Neal Norwitz <nnorwitz@gmail.com>
parents: 39038
diff changeset
274
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
275 def test_sequence_unpacking_error(self):
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
276 # Verify sequence packing/unpacking with "or". SF bug #757818
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
277 i,j = (1, -1) or (-1, 1)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
278 self.assertEqual(i, 1)
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
279 self.assertEqual(j, -1)
27878
be7683a6f521 - Finally fixed the bug in compile() and exec where a string ending
Guido van Rossum <guido@python.org>
parents: 27846
diff changeset
280
32723
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
281 def test_none_assignment(self):
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
282 stmts = [
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
283 'None = 0',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
284 'None += 0',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
285 '__builtins__.None = 0',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
286 'def None(): pass',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
287 'class None: pass',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
288 '(a, None) = 0, 0',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
289 'for None in range(10): pass',
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
290 'def f(None): pass',
54728
788e1397ce77 prevent import statements from assigning to None
Benjamin Peterson <benjamin@python.org>
parents: 47977
diff changeset
291 'import None',
788e1397ce77 prevent import statements from assigning to None
Benjamin Peterson <benjamin@python.org>
parents: 47977
diff changeset
292 'import x as None',
788e1397ce77 prevent import statements from assigning to None
Benjamin Peterson <benjamin@python.org>
parents: 47977
diff changeset
293 'from x import None',
788e1397ce77 prevent import statements from assigning to None
Benjamin Peterson <benjamin@python.org>
parents: 47977
diff changeset
294 'from x import y as None'
32723
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
295 ]
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
296 for stmt in stmts:
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
297 stmt += "\n"
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
298 self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single')
efca55bbba0a Upgrade None assignment SyntaxWarning to a SyntaxError.
Raymond Hettinger <python@rcn.com>
parents: 31042
diff changeset
299 self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
54728
788e1397ce77 prevent import statements from assigning to None
Benjamin Peterson <benjamin@python.org>
parents: 47977
diff changeset
300 # This is ok.
788e1397ce77 prevent import statements from assigning to None
Benjamin Peterson <benjamin@python.org>
parents: 47977
diff changeset
301 compile("from None import x", "tmp", "exec")
54732
04ccec0441b2 allow importing from a module named None if it has an 'as' clause
Benjamin Peterson <benjamin@python.org>
parents: 54728
diff changeset
302 compile("from x import None as y", "tmp", "exec")
04ccec0441b2 allow importing from a module named None if it has an 'as' clause
Benjamin Peterson <benjamin@python.org>
parents: 54728
diff changeset
303 compile("import None as x", "tmp", "exec")
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19501
diff changeset
304
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
305 def test_import(self):
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
306 succeed = [
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
307 'import sys',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
308 'import os, sys',
39034
066aa42ce5f2 Fix SF bug #1519018: 'as' is now validated properly in import statements
Neal Norwitz <nnorwitz@gmail.com>
parents: 37162
diff changeset
309 'import os as bar',
066aa42ce5f2 Fix SF bug #1519018: 'as' is now validated properly in import statements
Neal Norwitz <nnorwitz@gmail.com>
parents: 37162
diff changeset
310 'import os.path as bar',
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
311 'from __future__ import nested_scopes, generators',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
312 'from __future__ import (nested_scopes,\ngenerators)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
313 'from __future__ import (nested_scopes,\ngenerators,)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
314 'from sys import stdin, stderr, stdout',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
315 'from sys import (stdin, stderr,\nstdout)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
316 'from sys import (stdin, stderr,\nstdout,)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
317 'from sys import (stdin\n, stderr, stdout)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
318 'from sys import (stdin\n, stderr, stdout,)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
319 'from sys import stdin as si, stdout as so, stderr as se',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
320 'from sys import (stdin as si, stdout as so, stderr as se)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
321 'from sys import (stdin as si, stdout as so, stderr as se,)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
322 ]
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
323 fail = [
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
324 'import (os, sys)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
325 'import (os), (sys)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
326 'import ((os), (sys))',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
327 'import (sys',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
328 'import sys)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
329 'import (os,)',
39034
066aa42ce5f2 Fix SF bug #1519018: 'as' is now validated properly in import statements
Neal Norwitz <nnorwitz@gmail.com>
parents: 37162
diff changeset
330 'import os As bar',
066aa42ce5f2 Fix SF bug #1519018: 'as' is now validated properly in import statements
Neal Norwitz <nnorwitz@gmail.com>
parents: 37162
diff changeset
331 'import os.path a bar',
39035
abb2c76a5e05 Add an additional test for bug #1519018.
Georg Brandl <georg@python.org>
parents: 39034
diff changeset
332 'from sys import stdin As stdout',
abb2c76a5e05 Add an additional test for bug #1519018.
Georg Brandl <georg@python.org>
parents: 39034
diff changeset
333 'from sys import stdin a stdout',
33353
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
334 'from (sys) import stdin',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
335 'from __future__ import (nested_scopes',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
336 'from __future__ import nested_scopes)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
337 'from __future__ import nested_scopes,\ngenerators',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
338 'from sys import (stdin',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
339 'from sys import stdin)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
340 'from sys import stdin, stdout,\nstderr',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
341 'from sys import stdin si',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
342 'from sys import stdin,'
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
343 'from sys import (*)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
344 'from sys import (stdin,, stdout, stderr)',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
345 'from sys import (stdin, stdout),',
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
346 ]
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
347 for stmt in succeed:
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
348 compile(stmt, 'tmp', 'exec')
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
349 for stmt in fail:
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
350 self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
f7474d31ba3f SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32890
diff changeset
351
33822
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
352 def test_for_distinct_code_objects(self):
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
353 # SF bug 1048870
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
354 def f():
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
355 f1 = lambda x=1: x
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
356 f2 = lambda x=2: x
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
357 return f1, f2
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
358 f1, f2 = f()
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
359 self.assertNotEqual(id(f1.func_code), id(f2.func_code))
bf18caca0730 SF bug #1048870: call arg of lambda not updating
Raymond Hettinger <python@rcn.com>
parents: 33353
diff changeset
360
59672
b879209c202f prevent lambda functions from having docstrings #8164
Benjamin Peterson <benjamin@python.org>
parents: 58472
diff changeset
361 def test_lambda_doc(self):
b879209c202f prevent lambda functions from having docstrings #8164
Benjamin Peterson <benjamin@python.org>
parents: 58472
diff changeset
362 l = lambda: "foo"
b879209c202f prevent lambda functions from having docstrings #8164
Benjamin Peterson <benjamin@python.org>
parents: 58472
diff changeset
363 self.assertIsNone(l.__doc__)
b879209c202f prevent lambda functions from having docstrings #8164
Benjamin Peterson <benjamin@python.org>
parents: 58472
diff changeset
364
37162
b4d92ef2f338 Forward port MvL's fix in 43227:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36965
diff changeset
365 def test_unicode_encoding(self):
b4d92ef2f338 Forward port MvL's fix in 43227:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36965
diff changeset
366 code = u"# -*- coding: utf-8 -*-\npass\n"
b4d92ef2f338 Forward port MvL's fix in 43227:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36965
diff changeset
367 self.assertRaises(SyntaxError, compile, code, "tmp", "exec")
b4d92ef2f338 Forward port MvL's fix in 43227:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36965
diff changeset
368
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
369 def test_subscripts(self):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
370 # SF bug 1448804
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
371 # Class to make testing subscript results easy
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
372 class str_map(object):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
373 def __init__(self):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
374 self.data = {}
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
375 def __getitem__(self, key):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
376 return self.data[str(key)]
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
377 def __setitem__(self, key, value):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
378 self.data[str(key)] = value
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
379 def __delitem__(self, key):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
380 del self.data[str(key)]
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
381 def __contains__(self, key):
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
382 return str(key) in self.data
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
383 d = str_map()
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
384 # Index
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
385 d[1] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
386 self.assertEqual(d[1], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
387 d[1] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
388 self.assertEqual(d[1], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
389 del d[1]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
390 self.assertNotIn(1, d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
391 # Tuple of indices
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
392 d[1, 1] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
393 self.assertEqual(d[1, 1], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
394 d[1, 1] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
395 self.assertEqual(d[1, 1], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
396 del d[1, 1]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
397 self.assertNotIn((1, 1), d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
398 # Simple slice
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
399 d[1:2] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
400 self.assertEqual(d[1:2], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
401 d[1:2] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
402 self.assertEqual(d[1:2], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
403 del d[1:2]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
404 self.assertNotIn(slice(1, 2), d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
405 # Tuple of simple slices
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
406 d[1:2, 1:2] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
407 self.assertEqual(d[1:2, 1:2], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
408 d[1:2, 1:2] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
409 self.assertEqual(d[1:2, 1:2], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
410 del d[1:2, 1:2]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
411 self.assertNotIn((slice(1, 2), slice(1, 2)), d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
412 # Extended slice
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
413 d[1:2:3] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
414 self.assertEqual(d[1:2:3], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
415 d[1:2:3] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
416 self.assertEqual(d[1:2:3], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
417 del d[1:2:3]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
418 self.assertNotIn(slice(1, 2, 3), d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
419 # Tuple of extended slices
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
420 d[1:2:3, 1:2:3] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
421 self.assertEqual(d[1:2:3, 1:2:3], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
422 d[1:2:3, 1:2:3] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
423 self.assertEqual(d[1:2:3, 1:2:3], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
424 del d[1:2:3, 1:2:3]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
425 self.assertNotIn((slice(1, 2, 3), slice(1, 2, 3)), d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
426 # Ellipsis
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
427 d[...] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
428 self.assertEqual(d[...], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
429 d[...] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
430 self.assertEqual(d[...], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
431 del d[...]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
432 self.assertNotIn(Ellipsis, d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
433 # Tuple of Ellipses
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
434 d[..., ...] = 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
435 self.assertEqual(d[..., ...], 1)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
436 d[..., ...] += 1
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
437 self.assertEqual(d[..., ...], 2)
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
438 del d[..., ...]
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
439 self.assertNotIn((Ellipsis, Ellipsis), d)
36965
9a08724110d0 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly
Nick Coghlan <ncoghlan@gmail.com>
parents: 35792
diff changeset
440
40960
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
441 def test_mangling(self):
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
442 class A:
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
443 def f():
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
444 __mangled = 1
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
445 __not_mangled__ = 2
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
446 import __mangled_mod
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
447 import __package__.module
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
448
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
449 self.assertIn("_A__mangled", A.f.func_code.co_varnames)
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
450 self.assertIn("__not_mangled__", A.f.func_code.co_varnames)
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
451 self.assertIn("_A__mangled_mod", A.f.func_code.co_varnames)
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
452 self.assertIn("__package__", A.f.func_code.co_varnames)
40960
541a8b1b5da7 Fix long-standing bug in name mangling for package imports
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 40453
diff changeset
453
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
454 def test_compile_ast(self):
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
455 fname = __file__
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
456 if fname.lower().endswith(('pyc', 'pyo')):
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
457 fname = fname[:-1]
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
458 with open(fname, 'r') as f:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
459 fcontents = f.read()
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
460 sample_code = [
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
461 ['<assign>', 'x = 5'],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
462 ['<print1>', 'print 1'],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
463 ['<printv>', 'print v'],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
464 ['<printTrue>', 'print True'],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
465 ['<printList>', 'print []'],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
466 ['<ifblock>', """if True:\n pass\n"""],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
467 ['<forblock>', """for n in [1, 2, 3]:\n print n\n"""],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
468 ['<deffunc>', """def foo():\n pass\nfoo()\n"""],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
469 [fname, fcontents],
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
470 ]
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
471
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
472 for fname, code in sample_code:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
473 co1 = compile(code, '%s1' % fname, 'exec')
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
474 ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 54732
diff changeset
475 self.assertTrue(type(ast) == _ast.Module)
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
476 co2 = compile(ast, '%s3' % fname, 'exec')
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
477 self.assertEqual(co1, co2)
46193
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
478 # the code object's filename comes from the second compilation step
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
479 self.assertEqual(co2.co_filename, '%s3' % fname)
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
480
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
481 # raise exception when node type doesn't match with compile mode
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
482 co1 = compile('print 1', '<string>', 'exec', _ast.PyCF_ONLY_AST)
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
483 self.assertRaises(TypeError, compile, co1, '<ast>', 'eval')
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
484
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
485 # raise exception when node type is no start node
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
486 self.assertRaises(TypeError, compile, _ast.If(), '<ast>', 'exec')
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
487
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
488 # raise exception when node has invalid children
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
489 ast = _ast.Module()
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
490 ast.body = [_ast.BoolOp()]
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46162
diff changeset
491 self.assertRaises(TypeError, compile, ast, '<ast>', 'exec')
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45791
diff changeset
492
46171
c77cc23e394f Fix a reference leak found by Georg, when compiling a class nested in another class.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 41975
diff changeset
493
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
494 def test_main():
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
495 test_support.run_unittest(TestSpecifics)
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19501
diff changeset
496
29583
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
497 if __name__ == "__main__":
7fe4e9f16634 SF patch #736962. Converted test_compile to unittest format.
Raymond Hettinger <python@rcn.com>
parents: 29561
diff changeset
498 test_main()