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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 10 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
« no previous file with comments | « Lib/test/test_abc.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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return True 190 return True
191 if isinstance(parent, (ast.Attribute, ast.Subscript)): 191 if isinstance(parent, (ast.Attribute, ast.Subscript)):
192 return True 192 return True
193 return False 193 return False
194 194
195 if not isinstance(ast_node, ast.AST) or ast_node._fields is None: 195 if not isinstance(ast_node, ast.AST) or ast_node._fields is None:
196 return 196 return
197 if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)): 197 if isinstance(ast_node, (ast.expr, ast.stmt, ast.excepthandler)):
198 node_pos = (ast_node.lineno, ast_node.col_offset) 198 node_pos = (ast_node.lineno, ast_node.col_offset)
199 if reverse_check: 199 if reverse_check:
200 self.assertTrue(node_pos <= parent_pos) 200 self.assertLessEqual(node_pos, parent_pos)
201 else: 201 else:
202 self.assertTrue(node_pos >= parent_pos) 202 self.assertGreaterEqual(node_pos, parent_pos)
203 parent_pos = (ast_node.lineno, ast_node.col_offset) 203 parent_pos = (ast_node.lineno, ast_node.col_offset)
204 for name in ast_node._fields: 204 for name in ast_node._fields:
205 value = getattr(ast_node, name) 205 value = getattr(ast_node, name)
206 if isinstance(value, list): 206 if isinstance(value, list):
207 for child in value: 207 for child in value:
208 self._assertTrueorder(child, parent_pos, 208 self._assertTrueorder(child, parent_pos,
209 should_reverse_check(ast_node, child)) 209 should_reverse_check(ast_node, child))
210 elif value is not None: 210 elif value is not None:
211 self._assertTrueorder(value, parent_pos, 211 self._assertTrueorder(value, parent_pos,
212 should_reverse_check(ast_node, value)) 212 should_reverse_check(ast_node, value))
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 ('Expression', ('Subscript', (1, 2), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))), 1029 ('Expression', ('Subscript', (1, 2), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Lo ad',))),
1030 ('Expression', ('Name', (1, 0), 'v', ('Load',))), 1030 ('Expression', ('Name', (1, 0), 'v', ('Load',))),
1031 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), 1031 ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))),
1032 ('Expression', ('List', (1, 0), [], ('Load',))), 1032 ('Expression', ('List', (1, 0), [], ('Load',))),
1033 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))), 1033 ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num' , (1, 4), 3)], ('Load',))),
1034 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))), 1034 ('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num' , (1, 5), 3)], ('Load',))),
1035 ('Expression', ('Tuple', (1, 0), [], ('Load',))), 1035 ('Expression', ('Tuple', (1, 0), [], ('Load',))),
1036 ('Expression', ('Call', (1, 7), ('Attribute', (1, 6), ('Attribute', (1, 4), ('At tribute', (1, 2), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load ',)), 'd', ('Load',)), [('Subscript', (1, 12), ('Attribute', (1, 10), ('Name', ( 1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), 1036 ('Expression', ('Call', (1, 7), ('Attribute', (1, 6), ('Attribute', (1, 4), ('At tribute', (1, 2), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load ',)), 'd', ('Load',)), [('Subscript', (1, 12), ('Attribute', (1, 10), ('Name', ( 1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)),
1037 ] 1037 ]
1038 main() 1038 main()
OLDNEW
« no previous file with comments | « Lib/test/test_abc.py ('k') | Lib/test/test_asyncore.py » ('j') | no next file with comments »

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