Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(49229)

Side by Side Diff: Lib/test/test_ast.py

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 import os 1 import os
2 import sys 2 import sys
3 import unittest 3 import unittest
4 from test import support 4 from test import support
5 import ast 5 import ast
6 6
7 def to_tuple(t): 7 def to_tuple(t):
8 if t is None or isinstance(t, (str, int, complex)): 8 if t is None or isinstance(t, (str, int, complex)):
9 return t 9 return t
10 elif isinstance(t, list): 10 elif isinstance(t, list):
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 c = ast.DictComp(ast.Name("x", ast.Load()), 806 c = ast.DictComp(ast.Name("x", ast.Load()),
807 ast.Name("y", ast.Store()), [g]) 807 ast.Name("y", ast.Store()), [g])
808 self.expr(c, "must have Load context") 808 self.expr(c, "must have Load context")
809 def factory(comps): 809 def factory(comps):
810 k = ast.Name("x", ast.Load()) 810 k = ast.Name("x", ast.Load())
811 v = ast.Name("y", ast.Load()) 811 v = ast.Name("y", ast.Load())
812 return ast.DictComp(k, v, comps) 812 return ast.DictComp(k, v, comps)
813 self._check_comprehension(factory) 813 self._check_comprehension(factory)
814 814
815 def test_yield(self): 815 def test_yield(self):
816 self.expr(ast.Yield(ast.Name("x", ast.Store())), "must have Load") 816 self.expr(ast.Yield(0, ast.Name("x", ast.Store())), "must have Load")
817 self.expr(ast.Yield(1, ast.Name("x", ast.Store())), "must have Load")
817 818
818 def test_compare(self): 819 def test_compare(self):
819 left = ast.Name("x", ast.Load()) 820 left = ast.Name("x", ast.Load())
820 comp = ast.Compare(left, [ast.In()], []) 821 comp = ast.Compare(left, [ast.In()], [])
821 self.expr(comp, "no comparators") 822 self.expr(comp, "no comparators")
822 comp = ast.Compare(left, [ast.In()], [ast.Num(4), ast.Num(5)]) 823 comp = ast.Compare(left, [ast.In()], [ast.Num(4), ast.Num(5)])
823 self.expr(comp, "different number of comparators and operands") 824 self.expr(comp, "different number of comparators and operands")
824 comp = ast.Compare(ast.Num("blah"), [ast.In()], [left]) 825 comp = ast.Compare(ast.Num("blah"), [ast.In()], [left])
825 self.expr(comp, "non-numeric", exc=TypeError) 826 self.expr(comp, "non-numeric", exc=TypeError)
826 comp = ast.Compare(left, [ast.In()], [ast.Num("blah")]) 827 comp = ast.Compare(left, [ast.In()], [ast.Num("blah")])
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))), 989 ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))),
989 ('Expression', ('Name', (1, 0), 'v', ('Load',))), 990 ('Expression', ('Name', (1, 0), 'v', ('Load',))),
990 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), 991 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))),
991 ('Expression', ('List', (1, 0), [], ('Load',))), 992 ('Expression', ('List', (1, 0), [], ('Load',))),
992 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))), 993 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))),
993 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))), 994 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))),
994 ('Expression', ('Tuple', (1, 0), [], ('Load',))), 995 ('Expression', ('Tuple', (1, 0), [], ('Load',))),
995 ('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('At tribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load ',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1 , 14), 2), None), ('Load',))], [], None, None)), 996 ('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('At tribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load ',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1 , 14), 2), None), ('Load',))], [], None, None)),
996 ] 997 ]
997 main() 998 main()
OLDNEW
« no previous file with comments | « Lib/opcode.py ('k') | Lib/test/test_generators.py » ('j') | Modules/parsermodule.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+