test_ast.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. import sys, itertools, unittest
  2. from test import test_support
  3. import ast
  4. def to_tuple(t):
  5. if t is None or isinstance(t, (basestring, int, long, complex)):
  6. return t
  7. elif isinstance(t, list):
  8. return [to_tuple(e) for e in t]
  9. result = [t.__class__.__name__]
  10. if hasattr(t, 'lineno') and hasattr(t, 'col_offset'):
  11. result.append((t.lineno, t.col_offset))
  12. if t._fields is None:
  13. return tuple(result)
  14. for f in t._fields:
  15. result.append(to_tuple(getattr(t, f)))
  16. return tuple(result)
  17. # These tests are compiled through "exec"
  18. # There should be at least one test per statement
  19. exec_tests = [
  20. # None
  21. "None",
  22. # FunctionDef
  23. "def f(): pass",
  24. # FunctionDef with arg
  25. "def f(a): pass",
  26. # FunctionDef with arg and default value
  27. "def f(a=0): pass",
  28. # FunctionDef with varargs
  29. "def f(*args): pass",
  30. # FunctionDef with kwargs
  31. "def f(**kwargs): pass",
  32. # FunctionDef with all kind of args
  33. "def f(a, b=1, c=None, d=[], e={}, *args, **kwargs): pass",
  34. # ClassDef
  35. "class C:pass",
  36. # ClassDef, new style class
  37. "class C(object): pass",
  38. # Return
  39. "def f():return 1",
  40. # Delete
  41. "del v",
  42. # Assign
  43. "v = 1",
  44. # AugAssign
  45. "v += 1",
  46. # Print
  47. "print >>f, 1, ",
  48. # For
  49. "for v in v:pass",
  50. # While
  51. "while v:pass",
  52. # If
  53. "if v:pass",
  54. # Raise
  55. "raise Exception, 'string'",
  56. # TryExcept
  57. "try:\n pass\nexcept Exception:\n pass",
  58. # TryFinally
  59. "try:\n pass\nfinally:\n pass",
  60. # Assert
  61. "assert v",
  62. # Import
  63. "import sys",
  64. # ImportFrom
  65. "from sys import v",
  66. # Exec
  67. "exec 'v'",
  68. # Global
  69. "global v",
  70. # Expr
  71. "1",
  72. # Pass,
  73. "pass",
  74. # Break
  75. "break",
  76. # Continue
  77. "continue",
  78. # for statements with naked tuples (see http://bugs.python.org/issue6704)
  79. "for a,b in c: pass",
  80. "[(a,b) for a,b in c]",
  81. "((a,b) for a,b in c)",
  82. "((a,b) for (a,b) in c)",
  83. # Multiline generator expression (test for .lineno & .col_offset)
  84. """(
  85. (
  86. Aa
  87. ,
  88. Bb
  89. )
  90. for
  91. Aa
  92. ,
  93. Bb in Cc
  94. )""",
  95. # dictcomp
  96. "{a : b for w in x for m in p if g}",
  97. # dictcomp with naked tuple
  98. "{a : b for v,w in x}",
  99. # setcomp
  100. "{r for l in x if g}",
  101. # setcomp with naked tuple
  102. "{r for l,m in x}",
  103. ]
  104. # These are compiled through "single"
  105. # because of overlap with "eval", it just tests what
  106. # can't be tested with "eval"
  107. single_tests = [
  108. "1+2"
  109. ]
  110. # These are compiled through "eval"
  111. # It should test all expressions
  112. eval_tests = [
  113. # None
  114. "None",
  115. # BoolOp
  116. "a and b",
  117. # BinOp
  118. "a + b",
  119. # UnaryOp
  120. "not v",
  121. # Lambda
  122. "lambda:None",
  123. # Dict
  124. "{ 1:2 }",
  125. # Empty dict
  126. "{}",
  127. # Set
  128. "{None,}",
  129. # Multiline dict (test for .lineno & .col_offset)
  130. """{
  131. 1
  132. :
  133. 2
  134. }""",
  135. # ListComp
  136. "[a for b in c if d]",
  137. # GeneratorExp
  138. "(a for b in c if d)",
  139. # Yield - yield expressions can't work outside a function
  140. #
  141. # Compare
  142. "1 < 2 < 3",
  143. # Call
  144. "f(1,2,c=3,*d,**e)",
  145. # Repr
  146. "`v`",
  147. # Num
  148. "10L",
  149. # Str
  150. "'string'",
  151. # Attribute
  152. "a.b",
  153. # Subscript
  154. "a[b:c]",
  155. # Name
  156. "v",
  157. # List
  158. "[1,2,3]",
  159. # Empty list
  160. "[]",
  161. # Tuple
  162. "1,2,3",
  163. # Tuple
  164. "(1,2,3)",
  165. # Empty tuple
  166. "()",
  167. # Combination
  168. "a.b.c.d(a.b[1:2])",
  169. ]
  170. # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension
  171. # excepthandler, arguments, keywords, alias
  172. class AST_Tests(unittest.TestCase):
  173. def _assertTrueorder(self, ast_node, parent_pos):
  174. if not isinstance(ast_node, ast.AST) or ast_node._fields is None:
  175. return
  176. if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)):
  177. node_pos = (ast_node.lineno, ast_node.col_offset)
  178. self.assertTrue(node_pos >= parent_pos)
  179. parent_pos = (ast_node.lineno, ast_node.col_offset)
  180. for name in ast_node._fields:
  181. value = getattr(ast_node, name)
  182. if isinstance(value, list):
  183. for child in value:
  184. self._assertTrueorder(child, parent_pos)
  185. elif value is not None:
  186. self._assertTrueorder(value, parent_pos)
  187. def test_AST_objects(self):
  188. x = ast.AST()
  189. self.assertEqual(x._fields, ())
  190. with self.assertRaises(AttributeError):
  191. x.vararg
  192. with self.assertRaises(AttributeError):
  193. x.foobar = 21
  194. with self.assertRaises(AttributeError):
  195. ast.AST(lineno=2)
  196. with self.assertRaises(TypeError):
  197. # "_ast.AST constructor takes 0 positional arguments"
  198. ast.AST(2)
  199. def test_snippets(self):
  200. for input, output, kind in ((exec_tests, exec_results, "exec"),
  201. (single_tests, single_results, "single"),
  202. (eval_tests, eval_results, "eval")):
  203. for i, o in itertools.izip(input, output):
  204. ast_tree = compile(i, "?", kind, ast.PyCF_ONLY_AST)
  205. self.assertEqual(to_tuple(ast_tree), o)
  206. self._assertTrueorder(ast_tree, (0, 0))
  207. def test_slice(self):
  208. slc = ast.parse("x[::]").body[0].value.slice
  209. self.assertIsNone(slc.upper)
  210. self.assertIsNone(slc.lower)
  211. self.assertIsInstance(slc.step, ast.Name)
  212. self.assertEqual(slc.step.id, "None")
  213. def test_from_import(self):
  214. im = ast.parse("from . import y").body[0]
  215. self.assertIsNone(im.module)
  216. def test_non_interned_future_from_ast(self):
  217. mod = ast.parse("from __future__ import division")
  218. self.assertIsInstance(mod.body[0], ast.ImportFrom)
  219. mod.body[0].module = " __future__ ".strip()
  220. compile(mod, "<test>", "exec")
  221. def test_base_classes(self):
  222. self.assertTrue(issubclass(ast.For, ast.stmt))
  223. self.assertTrue(issubclass(ast.Name, ast.expr))
  224. self.assertTrue(issubclass(ast.stmt, ast.AST))
  225. self.assertTrue(issubclass(ast.expr, ast.AST))
  226. self.assertTrue(issubclass(ast.comprehension, ast.AST))
  227. self.assertTrue(issubclass(ast.Gt, ast.AST))
  228. def test_field_attr_existence(self):
  229. for name, item in ast.__dict__.iteritems():
  230. if isinstance(item, type) and name != 'AST' and name[0].isupper():
  231. x = item()
  232. if isinstance(x, ast.AST):
  233. self.assertEqual(type(x._fields), tuple)
  234. def test_arguments(self):
  235. x = ast.arguments()
  236. self.assertEqual(x._fields, ('args', 'vararg', 'kwarg', 'defaults'))
  237. with self.assertRaises(AttributeError):
  238. x.vararg
  239. x = ast.arguments(1, 2, 3, 4)
  240. self.assertEqual(x.vararg, 2)
  241. def test_field_attr_writable(self):
  242. x = ast.Num()
  243. # We can assign to _fields
  244. x._fields = 666
  245. self.assertEqual(x._fields, 666)
  246. def test_classattrs(self):
  247. x = ast.Num()
  248. self.assertEqual(x._fields, ('n',))
  249. with self.assertRaises(AttributeError):
  250. x.n
  251. x = ast.Num(42)
  252. self.assertEqual(x.n, 42)
  253. with self.assertRaises(AttributeError):
  254. x.lineno
  255. with self.assertRaises(AttributeError):
  256. x.foobar
  257. x = ast.Num(lineno=2)
  258. self.assertEqual(x.lineno, 2)
  259. x = ast.Num(42, lineno=0)
  260. self.assertEqual(x.lineno, 0)
  261. self.assertEqual(x._fields, ('n',))
  262. self.assertEqual(x.n, 42)
  263. self.assertRaises(TypeError, ast.Num, 1, 2)
  264. self.assertRaises(TypeError, ast.Num, 1, 2, lineno=0)
  265. def test_module(self):
  266. body = [ast.Num(42)]
  267. x = ast.Module(body)
  268. self.assertEqual(x.body, body)
  269. def test_nodeclasses(self):
  270. # Zero arguments constructor explicitely allowed
  271. x = ast.BinOp()
  272. self.assertEqual(x._fields, ('left', 'op', 'right'))
  273. # Random attribute allowed too
  274. x.foobarbaz = 5
  275. self.assertEqual(x.foobarbaz, 5)
  276. n1 = ast.Num(1)
  277. n3 = ast.Num(3)
  278. addop = ast.Add()
  279. x = ast.BinOp(n1, addop, n3)
  280. self.assertEqual(x.left, n1)
  281. self.assertEqual(x.op, addop)
  282. self.assertEqual(x.right, n3)
  283. x = ast.BinOp(1, 2, 3)
  284. self.assertEqual(x.left, 1)
  285. self.assertEqual(x.op, 2)
  286. self.assertEqual(x.right, 3)
  287. x = ast.BinOp(1, 2, 3, lineno=0)
  288. self.assertEqual(x.left, 1)
  289. self.assertEqual(x.op, 2)
  290. self.assertEqual(x.right, 3)
  291. self.assertEqual(x.lineno, 0)
  292. # node raises exception when not given enough arguments
  293. self.assertRaises(TypeError, ast.BinOp, 1, 2)
  294. # node raises exception when given too many arguments
  295. self.assertRaises(TypeError, ast.BinOp, 1, 2, 3, 4)
  296. # node raises exception when not given enough arguments
  297. self.assertRaises(TypeError, ast.BinOp, 1, 2, lineno=0)
  298. # node raises exception when given too many arguments
  299. self.assertRaises(TypeError, ast.BinOp, 1, 2, 3, 4, lineno=0)
  300. # can set attributes through kwargs too
  301. x = ast.BinOp(left=1, op=2, right=3, lineno=0)
  302. self.assertEqual(x.left, 1)
  303. self.assertEqual(x.op, 2)
  304. self.assertEqual(x.right, 3)
  305. self.assertEqual(x.lineno, 0)
  306. # Random kwargs also allowed
  307. x = ast.BinOp(1, 2, 3, foobarbaz=42)
  308. self.assertEqual(x.foobarbaz, 42)
  309. def test_no_fields(self):
  310. # this used to fail because Sub._fields was None
  311. x = ast.Sub()
  312. self.assertEqual(x._fields, ())
  313. def test_pickling(self):
  314. import pickle
  315. mods = [pickle]
  316. try:
  317. import cPickle
  318. mods.append(cPickle)
  319. except ImportError:
  320. pass
  321. protocols = [0, 1, 2]
  322. for mod in mods:
  323. for protocol in protocols:
  324. for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests):
  325. ast2 = mod.loads(mod.dumps(ast, protocol))
  326. self.assertEqual(to_tuple(ast2), to_tuple(ast))
  327. def test_invalid_identitifer(self):
  328. m = ast.Module([ast.Expr(ast.Name(u"x", ast.Load()))])
  329. ast.fix_missing_locations(m)
  330. with self.assertRaises(TypeError) as cm:
  331. compile(m, "<test>", "exec")
  332. self.assertIn("identifier must be of type str", str(cm.exception))
  333. def test_invalid_string(self):
  334. m = ast.Module([ast.Expr(ast.Str(43))])
  335. ast.fix_missing_locations(m)
  336. with self.assertRaises(TypeError) as cm:
  337. compile(m, "<test>", "exec")
  338. self.assertIn("string must be of type str or uni", str(cm.exception))
  339. class ASTHelpers_Test(unittest.TestCase):
  340. def test_parse(self):
  341. a = ast.parse('foo(1 + 1)')
  342. b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST)
  343. self.assertEqual(ast.dump(a), ast.dump(b))
  344. def test_dump(self):
  345. node = ast.parse('spam(eggs, "and cheese")')
  346. self.assertEqual(ast.dump(node),
  347. "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), "
  348. "args=[Name(id='eggs', ctx=Load()), Str(s='and cheese')], "
  349. "keywords=[], starargs=None, kwargs=None))])"
  350. )
  351. self.assertEqual(ast.dump(node, annotate_fields=False),
  352. "Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), "
  353. "Str('and cheese')], [], None, None))])"
  354. )
  355. self.assertEqual(ast.dump(node, include_attributes=True),
  356. "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), "
  357. "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), "
  358. "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, "
  359. "col_offset=11)], keywords=[], starargs=None, kwargs=None, "
  360. "lineno=1, col_offset=0), lineno=1, col_offset=0)])"
  361. )
  362. def test_copy_location(self):
  363. src = ast.parse('1 + 1', mode='eval')
  364. src.body.right = ast.copy_location(ast.Num(2), src.body.right)
  365. self.assertEqual(ast.dump(src, include_attributes=True),
  366. 'Expression(body=BinOp(left=Num(n=1, lineno=1, col_offset=0), '
  367. 'op=Add(), right=Num(n=2, lineno=1, col_offset=4), lineno=1, '
  368. 'col_offset=0))'
  369. )
  370. def test_fix_missing_locations(self):
  371. src = ast.parse('write("spam")')
  372. src.body.append(ast.Expr(ast.Call(ast.Name('spam', ast.Load()),
  373. [ast.Str('eggs')], [], None, None)))
  374. self.assertEqual(src, ast.fix_missing_locations(src))
  375. self.assertEqual(ast.dump(src, include_attributes=True),
  376. "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), "
  377. "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, "
  378. "col_offset=6)], keywords=[], starargs=None, kwargs=None, "
  379. "lineno=1, col_offset=0), lineno=1, col_offset=0), "
  380. "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, "
  381. "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], "
  382. "keywords=[], starargs=None, kwargs=None, lineno=1, "
  383. "col_offset=0), lineno=1, col_offset=0)])"
  384. )
  385. def test_increment_lineno(self):
  386. src = ast.parse('1 + 1', mode='eval')
  387. self.assertEqual(ast.increment_lineno(src, n=3), src)
  388. self.assertEqual(ast.dump(src, include_attributes=True),
  389. 'Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), '
  390. 'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, '
  391. 'col_offset=0))'
  392. )
  393. # issue10869: do not increment lineno of root twice
  394. src = ast.parse('1 + 1', mode='eval')
  395. self.assertEqual(ast.increment_lineno(src.body, n=3), src.body)
  396. self.assertEqual(ast.dump(src, include_attributes=True),
  397. 'Expression(body=BinOp(left=Num(n=1, lineno=4, col_offset=0), '
  398. 'op=Add(), right=Num(n=1, lineno=4, col_offset=4), lineno=4, '
  399. 'col_offset=0))'
  400. )
  401. def test_iter_fields(self):
  402. node = ast.parse('foo()', mode='eval')
  403. d = dict(ast.iter_fields(node.body))
  404. self.assertEqual(d.pop('func').id, 'foo')
  405. self.assertEqual(d, {'keywords': [], 'kwargs': None,
  406. 'args': [], 'starargs': None})
  407. def test_iter_child_nodes(self):
  408. node = ast.parse("spam(23, 42, eggs='leek')", mode='eval')
  409. self.assertEqual(len(list(ast.iter_child_nodes(node.body))), 4)
  410. iterator = ast.iter_child_nodes(node.body)
  411. self.assertEqual(next(iterator).id, 'spam')
  412. self.assertEqual(next(iterator).n, 23)
  413. self.assertEqual(next(iterator).n, 42)
  414. self.assertEqual(ast.dump(next(iterator)),
  415. "keyword(arg='eggs', value=Str(s='leek'))"
  416. )
  417. def test_get_docstring(self):
  418. node = ast.parse('def foo():\n """line one\n line two"""')
  419. self.assertEqual(ast.get_docstring(node.body[0]),
  420. 'line one\nline two')
  421. def test_literal_eval(self):
  422. self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
  423. self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
  424. self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None))
  425. self.assertRaises(ValueError, ast.literal_eval, 'foo()')
  426. def test_literal_eval_issue4907(self):
  427. self.assertEqual(ast.literal_eval('2j'), 2j)
  428. self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j)
  429. self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j)
  430. self.assertRaises(ValueError, ast.literal_eval, '2 + (3 + 4j)')
  431. def test_main():
  432. with test_support.check_py3k_warnings(("backquote not supported",
  433. SyntaxWarning)):
  434. test_support.run_unittest(AST_Tests, ASTHelpers_Test)
  435. def main():
  436. if __name__ != '__main__':
  437. return
  438. if sys.argv[1:] == ['-g']:
  439. for statements, kind in ((exec_tests, "exec"), (single_tests, "single"),
  440. (eval_tests, "eval")):
  441. print kind+"_results = ["
  442. for s in statements:
  443. print repr(to_tuple(compile(s, "?", kind, 0x400)))+","
  444. print "]"
  445. print "main()"
  446. raise SystemExit
  447. test_main()
  448. #### EVERYTHING BELOW IS GENERATED #####
  449. exec_results = [
  450. ('Module', [('Expr', (1, 0), ('Name', (1, 0), 'None', ('Load',)))]),
  451. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Pass', (1, 9))], [])]),
  452. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('Name', (1, 6), 'a', ('Param',))], None, None, []), [('Pass', (1, 10))], [])]),
  453. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('Name', (1, 6), 'a', ('Param',))], None, None, [('Num', (1, 8), 0)]), [('Pass', (1, 12))], [])]),
  454. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], 'args', None, []), [('Pass', (1, 14))], [])]),
  455. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, 'kwargs', []), [('Pass', (1, 17))], [])]),
  456. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('Name', (1, 6), 'a', ('Param',)), ('Name', (1, 9), 'b', ('Param',)), ('Name', (1, 14), 'c', ('Param',)), ('Name', (1, 22), 'd', ('Param',)), ('Name', (1, 28), 'e', ('Param',))], 'args', 'kwargs', [('Num', (1, 11), 1), ('Name', (1, 16), 'None', ('Load',)), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])]), [('Pass', (1, 52))], [])]),
  457. ('Module', [('ClassDef', (1, 0), 'C', [], [('Pass', (1, 8))], [])]),
  458. ('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [('Pass', (1, 17))], [])]),
  459. ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Return', (1, 8), ('Num', (1, 15), 1))], [])]),
  460. ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]),
  461. ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]),
  462. ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]),
  463. ('Module', [('Print', (1, 0), ('Name', (1, 8), 'f', ('Load',)), [('Num', (1, 11), 1)], False)]),
  464. ('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]),
  465. ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]),
  466. ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]),
  467. ('Module', [('Raise', (1, 0), ('Name', (1, 6), 'Exception', ('Load',)), ('Str', (1, 17), 'string'), None)]),
  468. ('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [])]),
  469. ('Module', [('TryFinally', (1, 0), [('Pass', (2, 2))], [('Pass', (4, 2))])]),
  470. ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]),
  471. ('Module', [('Import', (1, 0), [('alias', 'sys', None)])]),
  472. ('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]),
  473. ('Module', [('Exec', (1, 0), ('Str', (1, 5), 'v'), None, None)]),
  474. ('Module', [('Global', (1, 0), ['v'])]),
  475. ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]),
  476. ('Module', [('Pass', (1, 0))]),
  477. ('Module', [('Break', (1, 0))]),
  478. ('Module', [('Continue', (1, 0))]),
  479. ('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))], [])]),
  480. ('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',)), [])]))]),
  481. ('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',)), [])]))]),
  482. ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [])]))]),
  483. ('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name', (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', (10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [])]))]),
  484. ('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Name', (1, 11), 'w', ('Store',)), ('Name', (1, 16), 'x', ('Load',)), []), ('comprehension', ('Name', (1, 22), 'm', ('Store',)), ('Name', (1, 27), 'p', ('Load',)), [('Name', (1, 32), 'g', ('Load',))])]))]),
  485. ('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',)), ('Name', (1, 18), 'x', ('Load',)), [])]))]),
  486. ('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 12), 'x', ('Load',)), [('Name', (1, 17), 'g', ('Load',))])]))]),
  487. ('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [])]))]),
  488. ]
  489. single_results = [
  490. ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]),
  491. ]
  492. eval_results = [
  493. ('Expression', ('Name', (1, 0), 'None', ('Load',))),
  494. ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])),
  495. ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))),
  496. ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))),
  497. ('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, []), ('Name', (1, 7), 'None', ('Load',)))),
  498. ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])),
  499. ('Expression', ('Dict', (1, 0), [], [])),
  500. ('Expression', ('Set', (1, 0), [('Name', (1, 1), 'None', ('Load',))])),
  501. ('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])),
  502. ('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',))])])),
  503. ('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',))])])),
  504. ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])),
  505. ('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',)))),
  506. ('Expression', ('Repr', (1, 0), ('Name', (1, 1), 'v', ('Load',)))),
  507. ('Expression', ('Num', (1, 0), 10L)),
  508. ('Expression', ('Str', (1, 0), 'string')),
  509. ('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))),
  510. ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))),
  511. ('Expression', ('Name', (1, 0), 'v', ('Load',))),
  512. ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))),
  513. ('Expression', ('List', (1, 0), [], ('Load',))),
  514. ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))),
  515. ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))),
  516. ('Expression', ('Tuple', (1, 0), [], ('Load',))),
  517. ('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)),
  518. ]
  519. main()