Home | History | Annotate | Download | only in test
      1 import unittest
      2 from test import test_support
      3 
      4 # Silence Py3k warning
      5 test_support.import_module('compiler', deprecated=True)
      6 from compiler import transformer, ast
      7 from compiler import compile
      8 
      9 class Tests(unittest.TestCase):
     10 
     11     def testMultipleLHS(self):
     12         """ Test multiple targets on the left hand side. """
     13 
     14         snippets = ['a, b = 1, 2',
     15                     '(a, b) = 1, 2',
     16                     '((a, b), c) = (1, 2), 3']
     17 
     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)
     25 
     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
     33 
     34 def test_main():
     35     test_support.run_unittest(Tests)
     36 
     37 if __name__ == "__main__":
     38     test_main()
     39