move sections
[python/dscho.git] / Lib / test / test_transformer.py
blob1891ac486e6f0a86444279929504e538f5718fa2
1 import unittest
2 from test import test_support
4 # Silence Py3k warning
5 test_support.import_module('compiler', deprecated=True)
6 from compiler import transformer, ast
7 from compiler import compile
9 class Tests(unittest.TestCase):
11 def testMultipleLHS(self):
12 """ Test multiple targets on the left hand side. """
14 snippets = ['a, b = 1, 2',
15 '(a, b) = 1, 2',
16 '((a, b), c) = (1, 2), 3']
18 for s in snippets:
19 a = transformer.parse(s)
20 self.assertIsInstance(a, ast.Module)
21 child1 = a.getChildNodes()[0]
22 self.assertIsInstance(child1, ast.Stmt)
23 child2 = child1.getChildNodes()[0]
24 self.assertIsInstance(child2, ast.Assign)
26 # This actually tests the compiler, but it's a way to assure the ast
27 # is correct
28 c = compile(s, '<string>', 'single')
29 vals = {}
30 exec c in vals
31 assert vals['a'] == 1
32 assert vals['b'] == 2
34 def test_main():
35 test_support.run_unittest(Tests)
37 if __name__ == "__main__":
38 test_main()