PyXR

c:\python24\lib \ test \ test_transformer.py



0001 import unittest
0002 from test import test_support
0003 from compiler import transformer, ast
0004 from compiler import compile
0005 
0006 class Tests(unittest.TestCase):
0007 
0008     def testMultipleLHS(self):
0009         """ Test multiple targets on the left hand side. """
0010 
0011         snippets = ['a, b = 1, 2',
0012                     '(a, b) = 1, 2',
0013                     '((a, b), c) = (1, 2), 3']
0014 
0015         for s in snippets:
0016             a = transformer.parse(s)
0017             assert isinstance(a, ast.Module)
0018             child1 = a.getChildNodes()[0]
0019             assert isinstance(child1, ast.Stmt)
0020             child2 = child1.getChildNodes()[0]
0021             assert isinstance(child2, ast.Assign)
0022 
0023             # This actually tests the compiler, but it's a way to assure the ast
0024             # is correct
0025             c = compile(s, '<string>', 'single')
0026             vals = {}
0027             exec c in vals
0028             assert vals['a'] == 1
0029             assert vals['b'] == 2
0030 
0031 def test_main():
0032     test_support.run_unittest(Tests)
0033 
0034 if __name__ == "__main__":
0035     test_main()
0036 

Generated by PyXR 0.9.4
SourceForge.net Logo