Mercurial > cpython-lru_cache-weakref
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 |
| rev | line source |
|---|---|
| 32633 | 1 import unittest |
| 2 from test import test_support | |
| 3 from compiler import transformer, ast | |
| 4 from compiler import compile | |
| 5 | |
| 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 | 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 | 30 |
| 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 | 33 |
| 34 if __name__ == "__main__": | |
| 35 test_main() |
