1edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Python test set -- part 1, grammar.
2edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# This just tests whether the parser accepts them all.
3edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
4edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom test.test_support import run_unittest, check_syntax_error, \
5edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                              check_py3k_warnings
6edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport unittest
7edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport sys
8edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# testing import *
9edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom sys import *
10edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
11edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
12edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass TokenTests(unittest.TestCase):
13edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
14edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testBackslash(self):
15edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Backslash means line continuation:
16edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 \
17edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        + 1
18edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, 2, 'backslash for line continuation')
19edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
20edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Backslash does not means continuation in comments :\
21edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0
22edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, 0, 'backslash ending comment')
23edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
24edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testPlainIntegers(self):
25edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(0xff, 255)
26edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(0377, 255)
27edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(2147483647, 017777777777)
28edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # "0x" is not a valid literal
29edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertRaises(SyntaxError, eval, "0x")
30edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from sys import maxint
31edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if maxint == 2147483647:
32edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(-2147483647-1, -020000000000)
33edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # XXX -2147483648
34edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertTrue(037777777777 > 0)
35edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertTrue(0xffffffff > 0)
36edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for s in '2147483648', '040000000000', '0x100000000':
37edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
38edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    x = eval(s)
39edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except OverflowError:
40edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.fail("OverflowError on huge integer literal %r" % s)
41edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif maxint == 9223372036854775807:
42edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(-9223372036854775807-1, -01000000000000000000000)
43edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertTrue(01777777777777777777777 > 0)
44edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertTrue(0xffffffffffffffff > 0)
45edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for s in '9223372036854775808', '02000000000000000000000', \
46edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                     '0x10000000000000000':
47edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
48edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    x = eval(s)
49edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except OverflowError:
50edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.fail("OverflowError on huge integer literal %r" % s)
51edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
52edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail('Weird maxint value %r' % maxint)
53edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
54edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testLongIntegers(self):
55edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0L
56edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0l
57edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0xffffffffffffffffL
58edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0xffffffffffffffffl
59edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 077777777777777777L
60edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 077777777777777777l
61edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 123456789012345678901234567890L
62edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 123456789012345678901234567890l
63edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
64edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testFloats(self):
65edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3.14
66edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 314.
67edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0.314
68edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # XXX x = 000.314
69edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = .314
70edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3e14
71edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3E14
72edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3e-14
73edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3e+14
74edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3.e14
75edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = .3e14
76edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 3.1e4
77edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
78edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testStringLiterals(self):
79edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = ''; y = ""; self.assertTrue(len(x) == 0 and x == y)
80edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = '\''; y = "'"; self.assertTrue(len(x) == 1 and x == y and ord(x) == 39)
81edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = '"'; y = "\""; self.assertTrue(len(x) == 1 and x == y and ord(x) == 34)
82edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = "doesn't \"shrink\" does it"
83edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y = 'doesn\'t "shrink" does it'
84edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertTrue(len(x) == 24 and x == y)
85edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = "does \"shrink\" doesn't it"
86edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y = 'does "shrink" doesn\'t it'
87edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertTrue(len(x) == 24 and x == y)
88edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = """
89edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepThe "quick"
90edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepbrown fox
91edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepjumps over
92edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepthe 'lazy' dog.
93edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""
94edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
95edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, y)
96edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y = '''
97edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepThe "quick"
98edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepbrown fox
99edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepjumps over
100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepthe 'lazy' dog.
101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep'''
102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, y)
103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y = "\n\
104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepThe \"quick\"\n\
105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepbrown fox\n\
106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepjumps over\n\
107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepthe 'lazy' dog.\n\
108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"
109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, y)
110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y = '\n\
111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepThe \"quick\"\n\
112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepbrown fox\n\
113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepjumps over\n\
114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepthe \'lazy\' dog.\n\
115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep'
116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, y)
117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass GrammarTests(unittest.TestCase):
120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX can't test in a script -- this rule is only used when interactive
123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # file_input: (NEWLINE | stmt)* ENDMARKER
125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Being tested as this very moment this very module
126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # expr_input: testlist NEWLINE
128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX Hard to test -- used only in calls to input()
129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testEvalInput(self):
131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # testlist ENDMARKER
132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = eval('1, 0 or 1')
133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testFuncdef(self):
135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### 'def' NAME parameters ':' suite
136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### parameters: '(' [varargslist] ')'
137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ###            | ('**'|'*' '*') NAME)
139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ###            | fpdef ['=' test] (',' fpdef ['=' test])* [',']
140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### fpdef: NAME | '(' fplist ')'
141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### fplist: fpdef (',' fpdef)* [',']
142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### argument: [test '='] test   # Really [keyword '='] test
144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def f1(): pass
145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f1()
146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f1(*())
147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f1(*(), **{})
148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def f2(one_argument): pass
149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def f3(two, arguments): pass
150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Silence Py3k warning
151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec('def f4(two, (compound, (argument, list))): pass')
152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec('def f5((compound, first), two): pass')
153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(f2.func_code.co_varnames, ('one_argument',))
154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(f3.func_code.co_varnames, ('two', 'arguments'))
155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if sys.platform.startswith('java'):
156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(f4.func_code.co_varnames,
157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   ('two', '(compound, (argument, list))', 'compound', 'argument',
158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                'list',))
159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(f5.func_code.co_varnames,
160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   ('(compound, first)', 'two', 'compound', 'first'))
161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(f4.func_code.co_varnames,
163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  ('two', '.1', 'compound', 'argument',  'list'))
164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(f5.func_code.co_varnames,
165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  ('.0', 'two', 'compound', 'first'))
166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def a1(one_arg,): pass
167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def a2(two, args,): pass
168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def v0(*rest): pass
169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def v1(a, *rest): pass
170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def v2(a, b, *rest): pass
171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Silence Py3k warning
172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec('def v3(a, (b, c), *rest): return a, b, c, rest')
173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f1()
175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f2(1)
176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f2(1,)
177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f3(1, 2)
178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f3(1, 2,)
179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f4(1, (2, (3, 4)))
180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v0()
181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v0(1)
182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v0(1,)
183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v0(1,2)
184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v0(1,2,3,4,5,6,7,8,9,0)
185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v1(1)
186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v1(1,)
187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v1(1,2)
188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v1(1,2,3)
189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v1(1,2,3,4,5,6,7,8,9,0)
190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v2(1,2)
191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v2(1,2,3)
192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v2(1,2,3,4)
193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v2(1,2,3,4,5,6,7,8,9,0)
194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v3(1,(2,3))
195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v3(1,(2,3),4)
196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        v3(1,(2,3),4,5,6,7,8,9,0)
197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # ceval unpacks the formal arguments into the first argcount names;
199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # thus, the names nested inside tuples must appear after these names.
200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if sys.platform.startswith('java'):
201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(v3.func_code.co_varnames, ('a', '(b, c)', 'rest', 'b', 'c'))
202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(v3.func_code.co_varnames, ('a', '.1', 'rest', 'b', 'c'))
204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(v3(1, (2, 3), 4), (1, 2, 3, (4,)))
205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d01(a=1): pass
206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01()
207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01(1)
208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01(*(1,))
209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01(**{'a':2})
210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d11(a, b=1): pass
211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d11(1)
212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d11(1, 2)
213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d11(1, **{'b':2})
214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d21(a, b, c=1): pass
215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21(1, 2)
216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21(1, 2, 3)
217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21(*(1, 2, 3))
218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21(1, *(2, 3))
219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21(1, 2, *(3,))
220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21(1, 2, **{'c':3})
221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d02(a=1, b=2): pass
222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02()
223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02(1)
224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02(1, 2)
225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02(*(1, 2))
226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02(1, *(2,))
227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02(1, **{'b':2})
228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02(**{'a': 1, 'b': 2})
229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d12(a, b=1, c=2): pass
230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12(1)
231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12(1, 2)
232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12(1, 2, 3)
233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d22(a, b, c=1, d=2): pass
234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22(1, 2)
235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22(1, 2, 3)
236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22(1, 2, 3, 4)
237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d01v(a=1, *rest): pass
238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01v()
239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01v(1)
240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01v(1, 2)
241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01v(*(1, 2, 3, 4))
242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01v(*(1,))
243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d01v(**{'a':2})
244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d11v(a, b=1, *rest): pass
245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d11v(1)
246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d11v(1, 2)
247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d11v(1, 2, 3)
248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d21v(a, b, c=1, *rest): pass
249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21v(1, 2)
250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21v(1, 2, 3)
251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21v(1, 2, 3, 4)
252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21v(*(1, 2, 3, 4))
253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d21v(1, 2, **{'c': 3})
254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d02v(a=1, b=2, *rest): pass
255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02v()
256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02v(1)
257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02v(1, 2)
258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02v(1, 2, 3)
259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02v(1, *(2, 3, 4))
260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d02v(**{'a': 1, 'b': 2})
261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d12v(a, b=1, c=2, *rest): pass
262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(1)
263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(1, 2)
264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(1, 2, 3)
265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(1, 2, 3, 4)
266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(*(1, 2, 3, 4))
267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(1, 2, *(3, 4, 5))
268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d12v(1, *(2,), **{'c': 3})
269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def d22v(a, b, c=1, d=2, *rest): pass
270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(1, 2)
271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(1, 2, 3)
272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(1, 2, 3, 4)
273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(1, 2, 3, 4, 5)
274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(*(1, 2, 3, 4))
275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(1, 2, *(3, 4, 5))
276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d22v(1, *(2, 3), **{'d': 4})
277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Silence Py3k warning
278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec('def d31v((x)): pass')
279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec('def d32v((x,)): pass')
280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d31v(1)
281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d32v((1,))
282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # keyword arguments after *arglist
284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def f(*args, **kwargs):
285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return args, kwargs
286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(f(1, x=2, *[3, 4], y=5), ((1, 3, 4),
287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                                    {'x':2, 'y':5}))
288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)")
289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)")
290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Check ast errors in *args and *kwargs
292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "f(*g(1=2))")
293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "f(**g(1=2))")
294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testLambdef(self):
296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### lambdef: 'lambda' [varargslist] ':' test
297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        l1 = lambda : 0
298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(l1(), 0)
299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        l2 = lambda : a[d] # XXX just testing the expression
300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        l3 = lambda : [2 < x for x in [-1, 3, 0L]]
301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(l3(), [0, 1, 0])
302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        l4 = lambda x = lambda y = lambda z=1 : z : y() : x()
303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(l4(), 1)
304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        l5 = lambda x, y, z=2: x + y + z
305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(l5(1, 2), 5)
306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(l5(1, 2, 3), 6)
307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "lambda x: x = 2")
308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "lambda (None,): None")
309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ### stmt: simple_stmt | compound_stmt
311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Tested below
312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testSimpleStmt(self):
314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### simple_stmt: small_stmt (';' small_stmt)* [';']
315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1; pass; del x
316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def foo():
317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # verify statements that end with semi-colons
318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x = 1; pass; del x;
319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        foo()
320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ### small_stmt: expr_stmt | print_stmt  | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Tested below
323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testExprStmt(self):
325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # (exprlist '=')* exprlist
326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        1
327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        1, 2, 3
328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1
329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1, 2, 3
330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = y = z = 1, 2, 3
331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x, y, z = 1, 2, 3
332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4)
333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "x + 1 = 1")
335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "a + 1 = b + 2")
336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testPrintStmt(self):
338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'print' (test ',')* [test]
339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import StringIO
340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Can't test printing to real stdout without comparing output
342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # which is not available in unittest.
343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        save_stdout = sys.stdout
344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sys.stdout = StringIO.StringIO()
345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print 1, 2, 3
347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print 1, 2, 3,
348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print
349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print 0 or 1, 0 or 1,
350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print 0 or 1
351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'print' '>>' test ','
353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> sys.stdout, 1, 2, 3
354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> sys.stdout, 1, 2, 3,
355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> sys.stdout
356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> sys.stdout, 0 or 1, 0 or 1,
357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> sys.stdout, 0 or 1
358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # test printing to an instance
360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class Gulp:
361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def write(self, msg): pass
362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        gulp = Gulp()
364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> gulp, 1, 2, 3
365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> gulp, 1, 2, 3,
366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> gulp
367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> gulp, 0 or 1, 0 or 1,
368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        print >> gulp, 0 or 1
369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # test print >> None
371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def driver():
372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            oldstdout = sys.stdout
373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sys.stdout = Gulp()
374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                tellme(Gulp())
376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                tellme()
377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            finally:
378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                sys.stdout = oldstdout
379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # we should see this once
381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def tellme(file=sys.stdout):
382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            print >> file, 'hello world'
383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        driver()
385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # we should not see this at all
387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def tellme(file=None):
388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            print >> file, 'goodbye universe'
389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        driver()
391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sys.stdout.getvalue(), '''\
393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep1 2 3
394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep1 2 3
395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep1 1 1
396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep1 2 3
397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep1 2 3
398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep1 1 1
399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoephello world
400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep''')
401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sys.stdout = save_stdout
402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # syntax errors
404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, 'print ,')
405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, 'print >> x,')
406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testDelStmt(self):
408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'del' exprlist
409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        abc = [1,2,3]
410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x, y, z = abc
411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        xyz = x, y, z
412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        del abc
414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        del x, y, (z, xyz)
415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testPassStmt(self):
417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'pass'
418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pass
419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Tested below
422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testBreakStmt(self):
424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'break'
425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while 1: break
426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testContinueStmt(self):
428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'continue'
429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        i = 1
430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while i: i = 0; continue
431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        msg = ""
433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while not msg:
434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            msg = "ok"
435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                continue
437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                msg = "continue failed to continue inside try"
438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except:
439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                msg = "continue inside try called except block"
440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if msg != "ok":
441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail(msg)
442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        msg = ""
444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while not msg:
445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            msg = "finally block not called"
446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                continue
448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            finally:
449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                msg = "ok"
450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if msg != "ok":
451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail(msg)
452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_break_continue_loop(self):
454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # This test warrants an explanation. It is a test specifically for SF bugs
455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # #463359 and #462937. The bug is that a 'break' statement executed or
456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # exception raised inside a try/except inside a loop, *after* a continue
457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # statement has been executed in that loop, will cause the wrong number of
458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # arguments to be popped off the stack and the instruction pointer reset to
459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # a very small number (usually 0.) Because of this, the following test
460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # *must* written as a function, and the tracking vars *must* be function
461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # arguments with default values. Otherwise, the test will loop and loop.
462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def test_inner(extra_burning_oil = 1, count=0):
464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            big_hippo = 2
465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            while big_hippo:
466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                count += 1
467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    if extra_burning_oil and big_hippo == 1:
469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        extra_burning_oil -= 1
470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        break
471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    big_hippo -= 1
472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    continue
473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                except:
474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    raise
475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if count > 2 or big_hippo != 1:
476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.fail("continue then break in try/except in loop broken!")
477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        test_inner()
478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testReturn(self):
480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'return' [testlist]
481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def g1(): return
482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def g2(): return 1
483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        g1()
484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = g2()
485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "class foo:return 1")
486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testYield(self):
488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "class foo:yield 1")
489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testRaise(self):
491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'raise' test [',' test]
492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: raise RuntimeError, 'just testing'
493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except RuntimeError: pass
494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: raise KeyboardInterrupt
495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except KeyboardInterrupt: pass
496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testImport(self):
498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'import' dotted_as_names
499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import sys
500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import time, sys
501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'from' dotted_name 'import' ('*' | '(' import_as_names ')' | import_as_names)
502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from time import time
503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from time import (time)
504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # not testable inside a function, but already done at top of the module
505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # from sys import *
506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from sys import path, argv
507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from sys import (path, argv)
508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        from sys import (path, argv,)
509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testGlobal(self):
511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'global' NAME (',' NAME)*
512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        global a
513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        global a, b
514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        global one, two, three, four, five, six, seven, eight, nine, ten
515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testExec(self):
517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'exec' expr ['in' expr [',' expr]]
518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        z = None
519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        del z
520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec 'z=1+1\n'
521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if z != 2: self.fail('exec \'z=1+1\'\\n')
522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        del z
523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec 'z=1+1'
524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if z != 2: self.fail('exec \'z=1+1\'')
525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        z = None
526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        del z
527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import types
528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if hasattr(types, "UnicodeType"):
529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exec r"""if 1:
530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exec u'z=1+1\n'
531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if z != 2: self.fail('exec u\'z=1+1\'\\n')
532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            del z
533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exec u'z=1+1'
534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if z != 2: self.fail('exec u\'z=1+1\'')"""
535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        g = {}
536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec 'z = 1' in g
537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if '__builtins__' in g: del g['__builtins__']
538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if g != {'z': 1}: self.fail('exec \'z = 1\' in g')
539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        g = {}
540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        l = {}
541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec 'global a; a = 1; b = 2' in g, l
543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if '__builtins__' in g: del g['__builtins__']
544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if '__builtins__' in l: del l['__builtins__']
545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if (g, l) != ({'a':1}, {'b':2}):
546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail('exec ... in g (%s), l (%s)' %(g,l))
547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testAssert(self):
549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # assertTruestmt: 'assert' test [',' test]
550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        assert 1
551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        assert 1, 1
552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        assert lambda x:x
553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        assert 1, lambda x:x+1
554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            assert True
557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AssertionError as e:
558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail("'assert True' should not have raised an AssertionError")
559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            assert True, 'this should always pass'
562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AssertionError as e:
563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail("'assert True, msg' should not have "
564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                      "raised an AssertionError")
565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # these tests fail if python is run with -O, so check __debug__
567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    @unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testAssert2(self):
569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            assert 0, "msg"
571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AssertionError, e:
572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(e.args[0], "msg")
573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail("AssertionError not raised by assert 0")
575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            assert False
578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AssertionError as e:
579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual(len(e.args), 0)
580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail("AssertionError not raised by 'assert False'")
582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Tested below
586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testIf(self):
588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1: pass
590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1: pass
591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else: pass
592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 0: pass
593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif 0: pass
594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 0: pass
595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif 0: pass
596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif 0: pass
597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif 0: pass
598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else: pass
599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testWhile(self):
601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'while' test ':' suite ['else' ':' suite]
602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while 0: pass
603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while 0: pass
604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else: pass
605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Issue1920: "while 0" is optimized away,
607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # ensure that the "else" clause is still present.
608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 0
609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while 0:
610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x = 1
611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x = 2
613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, 2)
614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testFor(self):
616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i in 1, 2, 3: pass
618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i, j, k in (): pass
619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else: pass
620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class Squares:
621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __init__(self, max):
622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.max = max
623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.sofar = []
624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __len__(self): return len(self.sofar)
625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __getitem__(self, i):
626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if not 0 <= i < self.max: raise IndexError
627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                n = len(self.sofar)
628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                while n <= i:
629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.sofar.append(n*n)
630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    n = n+1
631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return self.sofar[i]
632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        n = 0
633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for x in Squares(10): n = n+x
634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if n != 285:
635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail('for over growing sequence')
636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        result = []
638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for x, in [(1,), (2,), (3,)]:
639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            result.append(x)
640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(result, [1, 2, 3])
641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testTry(self):
643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ###         | 'try' ':' suite 'finally' ':' suite
645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### except_clause: 'except' [expr [('as' | ',') expr]]
646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            1/0
648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except ZeroDivisionError:
649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: 1/0
653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except EOFError: pass
654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except TypeError as msg: pass
655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except RuntimeError, msg: pass
656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except: pass
657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else: pass
658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: 1/0
659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except (EOFError, TypeError, ZeroDivisionError): pass
660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: 1/0
661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except (EOFError, TypeError, ZeroDivisionError), msg: pass
662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: pass
663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        finally: pass
664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testSuite(self):
666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1: pass
668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1:
669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1:
671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            #
672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            #
673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            #
674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            #
677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            #
679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testTest(self):
681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### and_test ('or' and_test)*
682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### and_test: not_test ('and' not_test)*
683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### not_test: 'not' not_test | comparison
684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not 1: pass
685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 and 1: pass
686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 or 1: pass
687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not not not 1: pass
688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not 1 and 1 and 1: pass
689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass
690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testComparison(self):
692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### comparison: expr (comp_op expr)*
693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1: pass
695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = (1 == 1)
696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 == 1: pass
697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 != 1: pass
698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 < 1: pass
699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 > 1: pass
700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 <= 1: pass
701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 >= 1: pass
702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 is 1: pass
703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 is not 1: pass
704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 in (): pass
705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 not in (): pass
706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 in 1 not in 1 is 1 is not 1: pass
707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Silence Py3k warning
708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if eval('1 <> 1'): pass
709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if eval('1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1'): pass
710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testBinaryMaskOps(self):
712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 & 1
713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 ^ 1
714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 | 1
715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testShiftOps(self):
717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 << 1
718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 >> 1
719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 << 1 >> 1
720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testAdditiveOps(self):
722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1
723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 + 1
724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 - 1 - 1
725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 - 1 + 1 - 1 + 1
726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testMultiplicativeOps(self):
728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 * 1
729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 / 1
730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 % 1
731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 1 / 1 * 1 % 1
732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testUnaryOps(self):
734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = +1
735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = -1
736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = ~1
737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = -1*1/1 + 1*1 - ---1*1
739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testSelectors(self):
741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME
742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### subscript: expr | [expr] ':' [expr]
743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import sys, time
745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        c = sys.path[0]
746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = time.time()
747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = sys.modules['time'].time()
748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = '01234'
749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        c = a[0]
750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        c = a[-1]
751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[0:5]
752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[:5]
753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[0:]
754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[:]
755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[-5:]
756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[:-1]
757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        s = a[-4:-3]
758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # A rough test of SF bug 1333982.  http://python.org/sf/1333982
759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # The testing here is fairly incomplete.
760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Test cases should include: commas with 1 and 2 colons
761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d = {}
762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d[1] = 1
763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d[1,] = 2
764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d[1,2] = 3
765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        d[1,2,3] = 4
766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        L = list(d)
767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        L.sort()
768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(str(L), '[1, (1,), (1, 2), (1, 2, 3)]')
769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testAtoms(self):
771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING
772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ### dictorsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [','])
773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = (1)
775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = (1 or 2 or 3)
776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = (1 or 2 or 3, 2, 3)
777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = []
779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = [1]
780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = [1 or 2 or 3]
781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = [1 or 2 or 3, 2, 3]
782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = []
783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {}
785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one': 1}
786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one': 1,}
787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one' or 'two': 1 or 2}
788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one': 1, 'two': 2}
789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one': 1, 'two': 2,}
790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}
791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one'}
793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one', 1,}
794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {'one', 'two', 'three'}
795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = {2, 3, 4,}
796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Silence Py3k warning
798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = eval('`x`')
799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = eval('`1 or 2 or 3`')
800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(eval('`1,2`'), '(1, 2)')
801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = x
803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 'x'
804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 123
805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ### exprlist: expr (',' expr)* [',']
807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ### testlist: test (',' test)* [',']
808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These have been exercised enough above
809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testClassdef(self):
811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'class' NAME ['(' [testlist] ')'] ':' suite
812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class B: pass
813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class B2(): pass
814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class C1(B): pass
815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class C2(B): pass
816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class D(C1, C2, B): pass
817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class C:
818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def meth1(self): pass
819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def meth2(self, arg): pass
820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def meth3(self, a1, a2): pass
821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # decorators: decorator+
823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # decorated: decorators (classdef | funcdef)
824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def class_decorator(x):
825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x.decorated = True
826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return x
827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        @class_decorator
828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class G:
829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(G.decorated, True)
831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testDictcomps(self):
833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # dictorsetmaker: ( (test ':' test (comp_for |
834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        #                                   (',' test ':' test)* [','])) |
835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        #                   (test (comp_for | (',' test)* [','])) )
836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        nums = [1, 2, 3]
837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual({i:i+1 for i in nums}, {1: 2, 2: 3, 3: 4})
838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testListcomps(self):
840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # list comprehension tests
841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        nums = [1, 2, 3, 4, 5]
842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        strs = ["Apple", "Banana", "Coconut"]
843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        spcs = ["  Apple", " Banana ", "Coco  nut  "]
844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([s.strip() for s in spcs], ['Apple', 'Banana', 'Coco  nut'])
846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([3 * x for x in nums], [3, 6, 9, 12, 15])
847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([x for x in nums if x > 2], [3, 4, 5])
848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([(i, s) for i in nums for s in strs],
849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                         [(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'),
850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'),
851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'),
852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'),
853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')])
854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([(i, s) for i in nums for s in [f for f in strs if "n" in f]],
855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                         [(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'),
856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'),
857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          (5, 'Banana'), (5, 'Coconut')])
858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([(lambda a:[a**i for i in range(a+1)])(j) for j in range(5)],
859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                         [[1], [1, 1], [1, 2, 4], [1, 3, 9, 27], [1, 4, 16, 64, 256]])
860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def test_in_func(l):
862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return [None < x < 3 for x in l if x > 2]
863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(test_in_func(nums), [False, False, False])
865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def test_nested_front():
867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.assertEqual([[y for y in [x, x + 1]] for x in [1,3,5]],
868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                             [[1, 2], [3, 4], [5, 6]])
869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        test_nested_front()
871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "[i, s for i in nums for s in strs]")
873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "[x if y]")
874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        suppliers = [
876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (1, "Boeing"),
877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (2, "Ford"),
878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (3, "Macdonalds")
879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ]
880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        parts = [
882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (10, "Airliner"),
883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (20, "Engine"),
884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (30, "Cheeseburger")
885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ]
886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        suppart = [
888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (1, 10), (1, 20), (2, 20), (3, 30)
889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ]
890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = [
892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep          (sname, pname)
893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for (sno, sname) in suppliers
894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              for (pno, pname) in parts
895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                for (sp_sno, sp_pno) in suppart
896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  if sno == sp_sno and pno == sp_pno
897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ]
898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(x, [('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'),
900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                             ('Macdonalds', 'Cheeseburger')])
901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testGenexps(self):
903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # generator expression tests
904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        g = ([x for x in range(10)] for x in range(1))
905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(g.next(), [x for x in range(10)])
906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            g.next()
908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail('should produce StopIteration exception')
909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except StopIteration:
910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = 1
913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            g = (a for d in a)
915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            g.next()
916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.fail('should produce TypeError')
917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except TypeError:
918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(list((x, y) for x in 'abcd' for y in 'abcd'), [(x, y) for x in 'abcd' for y in 'abcd'])
921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(list((x, y) for x in 'ab' for y in 'xy'), [(x, y) for x in 'ab' for y in 'xy'])
922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a = [x for x in range(10)]
924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        b = (x for x in (y for y in a))
925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(b), sum([x for x in range(10)]))
926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x**2 for x in range(10)), sum([x**2 for x in range(10)]))
928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x*x for x in range(10) if x%2), sum([x*x for x in range(10) if x%2]))
929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x for x in (y for y in range(10))), sum([x for x in range(10)]))
930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x for x in (y for y in (z for z in range(10)))), sum([x for x in range(10)]))
931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x for x in [y for y in (z for z in range(10))]), sum([x for x in range(10)]))
932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x for x in (y for y in (z for z in range(10) if True)) if True), sum([x for x in range(10)]))
933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(sum(x for x in (y for y in (z for z in range(10) if True) if False) if True), 0)
934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "foo(x for x in range(10), 100)")
935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        check_syntax_error(self, "foo(100, x for x in range(10))")
936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testComprehensionSpecials(self):
938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # test for outmost iterable precomputation
939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 10; g = (i for i in range(x)); x = 5
940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(len(list(g)), 10)
941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # This should hold, since we're only precomputing outmost iterable.
943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 10; t = False; g = ((i,j) for i in range(x) if t for j in range(x))
944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x = 5; t = True;
945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([(i,j) for i in range(10) for j in range(5)], list(g))
946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Grammar allows multiple adjacent 'if's in listcomps and genexps,
948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # even though it's silly. Make sure it works (ifelse broke this.)
949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([ x for x in range(10) if x % 2 if x % 3 ], [1, 5, 7])
950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(list(x for x in range(10) if x % 2 if x % 3), [1, 5, 7])
951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # verify unpacking single element tuples in listcomp/genexp.
953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6])
954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9])
955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_with_statement(self):
957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class manager(object):
958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __enter__(self):
959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return (1, 2)
960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def __exit__(self, *args):
961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with manager():
964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with manager() as x:
966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with manager() as (x, y):
968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with manager(), manager():
970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with manager() as x, manager() as y:
972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with manager() as x, manager():
974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def testIfElseExpr(self):
977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Test ifelse expressions in various cases
978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def _checkeval(msg, ret):
979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            "helper to check that evaluation of expressions is done correctly"
980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            print x
981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return ret
982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([ x() for x in lambda: True, lambda: False if x() ], [True])
984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([ x() for x in (lambda: True, lambda: False) if x() ], [True])
985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual([ x(False) for x in (lambda x: False if x else True, lambda x: True if x else False) if x(False) ], [True])
986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((5 if 1 else _checkeval("check 1", 0)), 5)
987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((_checkeval("check 2", 0) if 0 else 5), 5)
988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((5 and 6 if 0 else 1), 1)
989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(((5 and 6) if 0 else 1), 1)
990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((5 and (6 if 1 else 1)), 6)
991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((0 or _checkeval("check 3", 2) if 0 else 3), 3)
992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((1 or _checkeval("check 4", 2) if 1 else _checkeval("check 5", 3)), 1)
993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((0 or 5 if 1 else _checkeval("check 6", 3)), 5)
994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((not 5 if 1 else 1), False)
995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((not 5 if 0 else 1), 1)
996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((6 + 1 if 1 else 2), 7)
997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((6 - 1 if 1 else 2), 5)
998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((6 * 2 if 1 else 4), 12)
999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((6 / 2 if 1 else 3), 3)
1000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((6 < 4 if 0 else 2), 2)
1001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def test_paren_evaluation(self):
1003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(16 // (4 // 2), 8)
1004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual((16 // 4) // 2, 2)
1005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertEqual(16 // 4 // 2, 2)
1006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertTrue(False is (2 is 3))
1007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertFalse((False is 2) is 3)
1008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.assertFalse(False is 2 is 3)
1009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef test_main():
1012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    with check_py3k_warnings(
1013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            ("backquote not supported", SyntaxWarning),
1014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            ("tuple parameter unpacking has been removed", SyntaxWarning),
1015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            ("parenthesized argument names are invalid", SyntaxWarning),
1016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            ("classic int division", DeprecationWarning),
1017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (".+ not supported in 3.x", DeprecationWarning)):
1018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        run_unittest(TokenTests, GrammarTests)
1019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif __name__ == '__main__':
1021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    test_main()
1022