/Lib/test/test_transformer.py

http://unladen-swallow.googlecode.com/ · Python · 35 lines · 25 code · 7 blank · 3 comment · 2 complexity · 458ea3aaa4d3c66f485691f7fc3cb0e0 MD5 · raw file

  1. import unittest
  2. from test import test_support
  3. from compiler import transformer, ast
  4. from compiler import compile
  5. class Tests(unittest.TestCase):
  6. def testMultipleLHS(self):
  7. """ Test multiple targets on the left hand side. """
  8. snippets = ['a, b = 1, 2',
  9. '(a, b) = 1, 2',
  10. '((a, b), c) = (1, 2), 3']
  11. for s in snippets:
  12. a = transformer.parse(s)
  13. assert isinstance(a, ast.Module)
  14. child1 = a.getChildNodes()[0]
  15. assert isinstance(child1, ast.Stmt)
  16. child2 = child1.getChildNodes()[0]
  17. assert isinstance(child2, ast.Assign)
  18. # This actually tests the compiler, but it's a way to assure the ast
  19. # is correct
  20. c = compile(s, '<string>', 'single')
  21. vals = {}
  22. exec c in vals
  23. assert vals['a'] == 1
  24. assert vals['b'] == 2
  25. def test_main():
  26. test_support.run_unittest(Tests)
  27. if __name__ == "__main__":
  28. test_main()