annotate Lib/test/test_transformer.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents b6e875aa508b
children c94f37054f19 7caf54ce529e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32633
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
1 import unittest
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
2 from test import test_support
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
3 from compiler import transformer, ast
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
4 from compiler import compile
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
5
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
6 class Tests(unittest.TestCase):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
7
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
8 def testMultipleLHS(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
9 """ Test multiple targets on the left hand side. """
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
10
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
11 snippets = ['a, b = 1, 2',
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
12 '(a, b) = 1, 2',
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
13 '((a, b), c) = (1, 2), 3']
32633
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
14
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
15 for s in snippets:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
16 a = transformer.parse(s)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
17 assert isinstance(a, ast.Module)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
18 child1 = a.getChildNodes()[0]
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
19 assert isinstance(child1, ast.Stmt)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
20 child2 = child1.getChildNodes()[0]
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
21 assert isinstance(child2, ast.Assign)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
22
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
23 # This actually tests the compiler, but it's a way to assure the ast
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
24 # is correct
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
25 c = compile(s, '<string>', 'single')
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
26 vals = {}
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
27 exec c in vals
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
28 assert vals['a'] == 1
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32633
diff changeset
29 assert vals['b'] == 2
32633
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
30
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
31 def test_main():
33421
b6e875aa508b compiler.transformer: correct lineno attribute when possible
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 32736
diff changeset
32 test_support.run_unittest(Tests)
32633
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
33
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
34 if __name__ == "__main__":
c9869a18e621 this is patch
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
35 test_main()