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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years 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
« no previous file with comments | « Lib/test/test_array.py ('k') | Lib/test/test_asyncore.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import sys 2 import sys
3 import unittest 3 import unittest
4 import ast 4 import ast
5 import weakref 5 import weakref
6 6
7 from test import support 7 from test import support
8 8
9 def to_tuple(t): 9 def to_tuple(t):
10 if t is None or isinstance(t, (str, int, complex)): 10 if t is None or isinstance(t, (str, int, complex)):
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension 178 # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension
179 # excepthandler, arguments, keywords, alias 179 # excepthandler, arguments, keywords, alias
180 180
181 class AST_Tests(unittest.TestCase): 181 class AST_Tests(unittest.TestCase):
182 182
183 def _assertTrueorder(self, ast_node, parent_pos): 183 def _assertTrueorder(self, ast_node, parent_pos):
184 if not isinstance(ast_node, ast.AST) or ast_node._fields is None: 184 if not isinstance(ast_node, ast.AST) or ast_node._fields is None:
185 return 185 return
186 if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)): 186 if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)):
187 node_pos = (ast_node.lineno, ast_node.col_offset) 187 node_pos = (ast_node.lineno, ast_node.col_offset)
188 self.assertTrue(node_pos >= parent_pos) 188 self.assertGreaterEqual(node_pos, parent_pos)
189 parent_pos = (ast_node.lineno, ast_node.col_offset) 189 parent_pos = (ast_node.lineno, ast_node.col_offset)
190 for name in ast_node._fields: 190 for name in ast_node._fields:
191 value = getattr(ast_node, name) 191 value = getattr(ast_node, name)
192 if isinstance(value, list): 192 if isinstance(value, list):
193 for child in value: 193 for child in value:
194 self._assertTrueorder(child, parent_pos) 194 self._assertTrueorder(child, parent_pos)
195 elif value is not None: 195 elif value is not None:
196 self._assertTrueorder(value, parent_pos) 196 self._assertTrueorder(value, parent_pos)
197 197
198 def test_AST_objects(self): 198 def test_AST_objects(self):
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))), 1024 ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))),
1025 ('Expression', ('Name', (1, 0), 'v', ('Load',))), 1025 ('Expression', ('Name', (1, 0), 'v', ('Load',))),
1026 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), 1026 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))),
1027 ('Expression', ('List', (1, 0), [], ('Load',))), 1027 ('Expression', ('List', (1, 0), [], ('Load',))),
1028 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))), 1028 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))),
1029 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))), 1029 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))),
1030 ('Expression', ('Tuple', (1, 0), [], ('Load',))), 1030 ('Expression', ('Tuple', (1, 0), [], ('Load',))),
1031 ('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)), 1031 ('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)),
1032 ] 1032 ]
1033 main() 1033 main()
OLDNEW
« no previous file with comments | « Lib/test/test_array.py ('k') | Lib/test/test_asyncore.py » ('j') | no next file with comments »

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