Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1 | import sys, unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 2 | from test import support |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 3 | import ast |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 4 | |
| 5 | def to_tuple(t): |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 6 | if t is None or isinstance(t, (str, int, complex)): |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 7 | return t |
| 8 | elif isinstance(t, list): |
| 9 | return [to_tuple(e) for e in t] |
| 10 | result = [t.__class__.__name__] |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 11 | if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): |
| 12 | result.append((t.lineno, t.col_offset)) |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 13 | if t._fields is None: |
| 14 | return tuple(result) |
| 15 | for f in t._fields: |
| 16 | result.append(to_tuple(getattr(t, f))) |
| 17 | return tuple(result) |
| 18 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 19 | |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 20 | # These tests are compiled through "exec" |
| 21 | # There should be atleast one test per statement |
| 22 | exec_tests = [ |
| 23 | # FunctionDef |
| 24 | "def f(): pass", |
| 25 | # ClassDef |
| 26 | "class C:pass", |
| 27 | # Return |
| 28 | "def f():return 1", |
| 29 | # Delete |
| 30 | "del v", |
| 31 | # Assign |
| 32 | "v = 1", |
| 33 | # AugAssign |
| 34 | "v += 1", |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 35 | # For |
| 36 | "for v in v:pass", |
| 37 | # While |
| 38 | "while v:pass", |
| 39 | # If |
| 40 | "if v:pass", |
| 41 | # Raise |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 42 | "raise Exception('string')", |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 43 | # TryExcept |
| 44 | "try:\n pass\nexcept Exception:\n pass", |
| 45 | # TryFinally |
| 46 | "try:\n pass\nfinally:\n pass", |
| 47 | # Assert |
| 48 | "assert v", |
| 49 | # Import |
| 50 | "import sys", |
| 51 | # ImportFrom |
| 52 | "from sys import v", |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 53 | # Global |
| 54 | "global v", |
| 55 | # Expr |
| 56 | "1", |
| 57 | # Pass, |
| 58 | "pass", |
| 59 | # Break |
| 60 | "break", |
| 61 | # Continue |
| 62 | "continue", |
Benjamin Peterson | 2e4b0e1 | 2009-09-11 22:36:20 +0000 | [diff] [blame] | 63 | # for statements with naked tuples (see http://bugs.python.org/issue6704) |
| 64 | "for a,b in c: pass", |
| 65 | "[(a,b) for a,b in c]", |
| 66 | "((a,b) for a,b in c)", |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 67 | ] |
| 68 | |
| 69 | # These are compiled through "single" |
| 70 | # because of overlap with "eval", it just tests what |
| 71 | # can't be tested with "eval" |
| 72 | single_tests = [ |
| 73 | "1+2" |
| 74 | ] |
| 75 | |
| 76 | # These are compiled through "eval" |
| 77 | # It should test all expressions |
| 78 | eval_tests = [ |
| 79 | # BoolOp |
| 80 | "a and b", |
| 81 | # BinOp |
| 82 | "a + b", |
| 83 | # UnaryOp |
| 84 | "not v", |
| 85 | # Lambda |
| 86 | "lambda:None", |
| 87 | # Dict |
| 88 | "{ 1:2 }", |
| 89 | # ListComp |
| 90 | "[a for b in c if d]", |
| 91 | # GeneratorExp |
| 92 | "(a for b in c if d)", |
| 93 | # Yield - yield expressions can't work outside a function |
| 94 | # |
| 95 | # Compare |
| 96 | "1 < 2 < 3", |
| 97 | # Call |
| 98 | "f(1,2,c=3,*d,**e)", |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 99 | # Num |
Guido van Rossum | e2a383d | 2007-01-15 16:59:06 +0000 | [diff] [blame] | 100 | "10", |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 101 | # Str |
| 102 | "'string'", |
| 103 | # Attribute |
| 104 | "a.b", |
| 105 | # Subscript |
| 106 | "a[b:c]", |
| 107 | # Name |
| 108 | "v", |
| 109 | # List |
| 110 | "[1,2,3]", |
| 111 | # Tuple |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 112 | "1,2,3", |
| 113 | # Combination |
| 114 | "a.b.c.d(a.b[1:2])", |
| 115 | |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 116 | ] |
| 117 | |
| 118 | # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension |
| 119 | # excepthandler, arguments, keywords, alias |
| 120 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 121 | class AST_Tests(unittest.TestCase): |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 122 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 123 | def _assertTrueorder(self, ast_node, parent_pos): |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 124 | if not isinstance(ast_node, ast.AST) or ast_node._fields is None: |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 125 | return |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 126 | if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)): |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 127 | node_pos = (ast_node.lineno, ast_node.col_offset) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 128 | self.assertTrue(node_pos >= parent_pos) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 129 | parent_pos = (ast_node.lineno, ast_node.col_offset) |
| 130 | for name in ast_node._fields: |
| 131 | value = getattr(ast_node, name) |
| 132 | if isinstance(value, list): |
| 133 | for child in value: |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 134 | self._assertTrueorder(child, parent_pos) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 135 | elif value is not None: |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 136 | self._assertTrueorder(value, parent_pos) |
Tim Peters | 5ddfe41 | 2006-03-01 23:02:57 +0000 | [diff] [blame] | 137 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 138 | def test_snippets(self): |
| 139 | for input, output, kind in ((exec_tests, exec_results, "exec"), |
| 140 | (single_tests, single_results, "single"), |
| 141 | (eval_tests, eval_results, "eval")): |
| 142 | for i, o in zip(input, output): |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 143 | ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 144 | self.assertEquals(to_tuple(ast_tree), o) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 145 | self._assertTrueorder(ast_tree, (0, 0)) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 146 | |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 147 | def test_slice(self): |
| 148 | slc = ast.parse("x[::]").body[0].value.slice |
| 149 | self.assertIsNone(slc.upper) |
| 150 | self.assertIsNone(slc.lower) |
| 151 | self.assertIsNone(slc.step) |
| 152 | |
| 153 | def test_from_import(self): |
| 154 | im = ast.parse("from . import y").body[0] |
| 155 | self.assertIsNone(im.module) |
| 156 | |
Benjamin Peterson | a0dfa82 | 2009-11-13 02:25:08 +0000 | [diff] [blame] | 157 | def test_base_classes(self): |
| 158 | self.assertTrue(issubclass(ast.For, ast.stmt)) |
| 159 | self.assertTrue(issubclass(ast.Name, ast.expr)) |
| 160 | self.assertTrue(issubclass(ast.stmt, ast.AST)) |
| 161 | self.assertTrue(issubclass(ast.expr, ast.AST)) |
| 162 | self.assertTrue(issubclass(ast.comprehension, ast.AST)) |
| 163 | self.assertTrue(issubclass(ast.Gt, ast.AST)) |
| 164 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 165 | def test_nodeclasses(self): |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 166 | x = ast.BinOp(1, 2, 3, lineno=0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 167 | self.assertEquals(x.left, 1) |
| 168 | self.assertEquals(x.op, 2) |
| 169 | self.assertEquals(x.right, 3) |
| 170 | self.assertEquals(x.lineno, 0) |
| 171 | |
| 172 | # node raises exception when not given enough arguments |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 173 | self.assertRaises(TypeError, ast.BinOp, 1, 2) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 174 | |
| 175 | # can set attributes through kwargs too |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 176 | x = ast.BinOp(left=1, op=2, right=3, lineno=0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 177 | self.assertEquals(x.left, 1) |
| 178 | self.assertEquals(x.op, 2) |
| 179 | self.assertEquals(x.right, 3) |
| 180 | self.assertEquals(x.lineno, 0) |
| 181 | |
| 182 | # this used to fail because Sub._fields was None |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 183 | x = ast.Sub() |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 184 | |
| 185 | def test_pickling(self): |
| 186 | import pickle |
| 187 | mods = [pickle] |
| 188 | try: |
| 189 | import cPickle |
| 190 | mods.append(cPickle) |
| 191 | except ImportError: |
| 192 | pass |
| 193 | protocols = [0, 1, 2] |
| 194 | for mod in mods: |
| 195 | for protocol in protocols: |
| 196 | for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests): |
| 197 | ast2 = mod.loads(mod.dumps(ast, protocol)) |
| 198 | self.assertEquals(to_tuple(ast2), to_tuple(ast)) |
| 199 | |
Benjamin Peterson | 5b06681 | 2010-11-20 01:38:49 +0000 | [diff] [blame] | 200 | def test_invalid_sum(self): |
| 201 | pos = dict(lineno=2, col_offset=3) |
| 202 | m = ast.Module([ast.Expr(ast.expr(**pos), **pos)]) |
| 203 | with self.assertRaises(TypeError) as cm: |
| 204 | compile(m, "<test>", "exec") |
| 205 | self.assertIn("but got <_ast.expr", str(cm.exception)) |
| 206 | |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 207 | |
| 208 | class ASTHelpers_Test(unittest.TestCase): |
| 209 | |
| 210 | def test_parse(self): |
| 211 | a = ast.parse('foo(1 + 1)') |
| 212 | b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST) |
| 213 | self.assertEqual(ast.dump(a), ast.dump(b)) |
| 214 | |
| 215 | def test_dump(self): |
| 216 | node = ast.parse('spam(eggs, "and cheese")') |
| 217 | self.assertEqual(ast.dump(node), |
| 218 | "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), " |
| 219 | "args=[Name(id='eggs', ctx=Load()), Str(s='and cheese')], " |
| 220 | "keywords=[], starargs=None, kwargs=None))])" |
| 221 | ) |
| 222 | self.assertEqual(ast.dump(node, annotate_fields=False), |
| 223 | "Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), " |
| 224 | "Str('and cheese')], [], None, None))])" |
| 225 | ) |
| 226 | self.assertEqual(ast.dump(node, include_attributes=True), |
| 227 | "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), " |
| 228 | "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), " |
| 229 | "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, " |
| 230 | "col_offset=11)], keywords=[], starargs=None, kwargs=None, " |
| 231 | "lineno=1, col_offset=0), lineno=1, col_offset=0)])" |
| 232 | ) |
| 233 | |
| 234 | def test_copy_location(self): |
| 235 | src = ast.parse('1 + 1', mode='eval') |
| 236 | src.body.right = ast.copy_location(ast.Num(2), src.body.right) |
| 237 | self.assertEqual(ast.dump(src, include_attributes=True), |
| 238 | 'Expression(body=BinOp(left=Num(n=1, lineno=1, col_offset=0), ' |
| 239 | 'op=Add(), right=Num(n=2, lineno=1, col_offset=4), lineno=1, ' |
| 240 | 'col_offset=0))' |
| 241 | ) |
| 242 | |
| 243 | def test_fix_missing_locations(self): |
| 244 | src = ast.parse('write("spam")') |
| 245 | src.body.append(ast.Expr(ast.Call(ast.Name('spam', ast.Load()), |
| 246 | [ast.Str('eggs')], [], None, None))) |
| 247 | self.assertEqual(src, ast.fix_missing_locations(src)) |
| 248 | self.assertEqual(ast.dump(src, include_attributes=True), |
| 249 | "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), " |
| 250 | "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, " |
| 251 | "col_offset=6)], keywords=[], starargs=None, kwargs=None, " |
| 252 | "lineno=1, col_offset=0), lineno=1, col_offset=0), " |
| 253 | "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, " |
| 254 | "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], " |
| 255 | "keywords=[], starargs=None, kwargs=None, lineno=1, " |
| 256 | "col_offset=0), lineno=1, col_offset=0)])" |
| 257 | ) |
| 258 | |
| 259 | def test_increment_lineno(self): |
| 260 | src = ast.parse('1 + 1', mode='eval') |
| 261 | self.assertEqual(ast.increment_lineno(src, n=3), src) |
| 262 | self.assertEqual(ast.dump(src, include_attributes=True), |
| 263 | 'Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), ' |
| 264 | 'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, ' |
| 265 | 'col_offset=0))' |
| 266 | ) |
| 267 | |
| 268 | def test_iter_fields(self): |
| 269 | node = ast.parse('foo()', mode='eval') |
| 270 | d = dict(ast.iter_fields(node.body)) |
| 271 | self.assertEqual(d.pop('func').id, 'foo') |
| 272 | self.assertEqual(d, {'keywords': [], 'kwargs': None, |
| 273 | 'args': [], 'starargs': None}) |
| 274 | |
| 275 | def test_iter_child_nodes(self): |
| 276 | node = ast.parse("spam(23, 42, eggs='leek')", mode='eval') |
| 277 | self.assertEqual(len(list(ast.iter_child_nodes(node.body))), 4) |
| 278 | iterator = ast.iter_child_nodes(node.body) |
| 279 | self.assertEqual(next(iterator).id, 'spam') |
| 280 | self.assertEqual(next(iterator).n, 23) |
| 281 | self.assertEqual(next(iterator).n, 42) |
| 282 | self.assertEqual(ast.dump(next(iterator)), |
| 283 | "keyword(arg='eggs', value=Str(s='leek'))" |
| 284 | ) |
| 285 | |
| 286 | def test_get_docstring(self): |
| 287 | node = ast.parse('def foo():\n """line one\n line two"""') |
| 288 | self.assertEqual(ast.get_docstring(node.body[0]), |
| 289 | 'line one\nline two') |
| 290 | |
| 291 | def test_literal_eval(self): |
| 292 | self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3]) |
| 293 | self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42}) |
| 294 | self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None)) |
Benjamin Peterson | 3e74289 | 2010-07-11 12:59:24 +0000 | [diff] [blame] | 295 | self.assertEqual(ast.literal_eval('{1, 2, 3}'), {1, 2, 3}) |
Benjamin Peterson | 5ef96e5 | 2010-07-11 23:06:06 +0000 | [diff] [blame] | 296 | self.assertEqual(ast.literal_eval('b"hi"'), b"hi") |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 297 | self.assertRaises(ValueError, ast.literal_eval, 'foo()') |
Raymond Hettinger | bc95973 | 2010-10-08 00:47:45 +0000 | [diff] [blame] | 298 | self.assertEqual(ast.literal_eval('-6'), -6) |
| 299 | self.assertEqual(ast.literal_eval('-6j+3'), 3-6j) |
| 300 | self.assertEqual(ast.literal_eval('3.25'), 3.25) |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 301 | |
Benjamin Peterson | 058e31e | 2009-01-16 03:54:08 +0000 | [diff] [blame] | 302 | def test_literal_eval_issue4907(self): |
| 303 | self.assertEqual(ast.literal_eval('2j'), 2j) |
| 304 | self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j) |
| 305 | self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j) |
Benjamin Peterson | 058e31e | 2009-01-16 03:54:08 +0000 | [diff] [blame] | 306 | |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 307 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 308 | def test_main(): |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 309 | support.run_unittest(AST_Tests, ASTHelpers_Test) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 310 | |
| 311 | def main(): |
| 312 | if __name__ != '__main__': |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 313 | return |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 314 | if sys.argv[1:] == ['-g']: |
| 315 | for statements, kind in ((exec_tests, "exec"), (single_tests, "single"), |
| 316 | (eval_tests, "eval")): |
| 317 | print(kind+"_results = [") |
| 318 | for s in statements: |
| 319 | print(repr(to_tuple(compile(s, "?", kind, 0x400)))+",") |
| 320 | print("]") |
| 321 | print("main()") |
| 322 | raise SystemExit |
| 323 | test_main() |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 324 | |
| 325 | #### EVERYTHING BELOW IS GENERATED ##### |
| 326 | exec_results = [ |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 327 | ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Pass', (1, 9))], [], None)]), |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 328 | ('Module', [('ClassDef', (1, 0), 'C', [], [], None, None, [('Pass', (1, 8))], [])]), |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 329 | ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]), |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 330 | ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), |
| 331 | ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 332 | ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]), |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 333 | ('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]), |
| 334 | ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), |
| 335 | ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 336 | ('Module', [('Raise', (1, 0), ('Call', (1, 6), ('Name', (1, 6), 'Exception', ('Load',)), [('Str', (1, 16), 'string')], [], None, None), None)]), |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 337 | ('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [])]), |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 338 | ('Module', [('TryFinally', (1, 0), [('Pass', (2, 2))], [('Pass', (4, 2))])]), |
| 339 | ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), |
| 340 | ('Module', [('Import', (1, 0), [('alias', 'sys', None)])]), |
| 341 | ('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]), |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 342 | ('Module', [('Global', (1, 0), ['v'])]), |
| 343 | ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), |
| 344 | ('Module', [('Pass', (1, 0))]), |
| 345 | ('Module', [('Break', (1, 0))]), |
| 346 | ('Module', [('Continue', (1, 0))]), |
Benjamin Peterson | 2e4b0e1 | 2009-09-11 22:36:20 +0000 | [diff] [blame] | 347 | ('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)), ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load',)), [('Pass', (1, 14))], [])]), |
| 348 | ('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), |
| 349 | ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 350 | ] |
| 351 | single_results = [ |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 352 | ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 353 | ] |
| 354 | eval_results = [ |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 355 | ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])), |
| 356 | ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))), |
| 357 | ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 358 | ('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, [], None, None, [], []), ('Name', (1, 7), 'None', ('Load',)))), |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 359 | ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), |
| 360 | ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), |
| 361 | ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), |
| 362 | ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])), |
| 363 | ('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 364 | ('Expression', ('Num', (1, 0), 10)), |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 365 | ('Expression', ('Str', (1, 0), 'string')), |
| 366 | ('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))), |
| 367 | ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), |
| 368 | ('Expression', ('Name', (1, 0), 'v', ('Load',))), |
| 369 | ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), |
| 370 | ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))), |
| 371 | ('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), |
Tim Peters | 400cbc3 | 2006-02-28 18:44:41 +0000 | [diff] [blame] | 372 | ] |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 373 | main() |