Michael W. Hudson | 3f06189 | 2004-07-12 13:15:56 +0000 | [diff] [blame] | 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): |
Michael W. Hudson | 3f06189 | 2004-07-12 13:15:56 +0000 | [diff] [blame] | 7 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 8 | def testMultipleLHS(self): |
| 9 | """ Test multiple targets on the left hand side. """ |
| 10 | |
| 11 | snippets = ['a, b = 1, 2', |
| 12 | '(a, b) = 1, 2', |
| 13 | '((a, b), c) = (1, 2), 3'] |
| 14 | |
| 15 | for s in snippets: |
| 16 | a = transformer.parse(s) |
| 17 | assert isinstance(a, ast.Module) |
| 18 | child1 = a.getChildNodes()[0] |
| 19 | assert isinstance(child1, ast.Stmt) |
| 20 | child2 = child1.getChildNodes()[0] |
| 21 | assert isinstance(child2, ast.Assign) |
| 22 | |
| 23 | # This actually tests the compiler, but it's a way to assure the ast |
| 24 | # is correct |
| 25 | c = compile(s, '<string>', 'single') |
| 26 | vals = {} |
| 27 | exec c in vals |
| 28 | assert vals['a'] == 1 |
| 29 | assert vals['b'] == 2 |
Michael W. Hudson | 3f06189 | 2004-07-12 13:15:56 +0000 | [diff] [blame] | 30 | |
| 31 | def test_main(): |
Jeremy Hylton | 566d934 | 2004-09-07 15:28:01 +0000 | [diff] [blame^] | 32 | test_support.run_unittest(Tests) |
Michael W. Hudson | 3f06189 | 2004-07-12 13:15:56 +0000 | [diff] [blame] | 33 | |
| 34 | if __name__ == "__main__": |
| 35 | test_main() |