OLD | NEW |
1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 """Implements a Checker object which can be used in place of `assert` to check | 5 """Implements a Checker object which can be used in place of `assert` to check |
6 conditions inside tests, but with much more debugging information, including | 6 conditions inside tests, but with much more debugging information, including |
7 a smart selection of local variables mentioned inside of the call to check.""" | 7 a smart selection of local variables mentioned inside of the call to check.""" |
8 | 8 |
9 import ast | 9 import ast |
10 import copy | 10 import copy |
11 import inspect | 11 import inspect |
12 import re | 12 import re |
13 import itertools | 13 import itertools |
14 | 14 |
15 from collections import OrderedDict, namedtuple, deque, defaultdict | 15 from collections import OrderedDict, deque, defaultdict |
16 | 16 |
17 from . import env | 17 from . import env |
18 import astunparse | 18 import astunparse |
19 from expect_tests.type_definitions import CheckFrame, Check | 19 from expect_tests.type_definitions import CheckFrame, Check |
20 | 20 |
21 | 21 |
22 class _resolved(ast.AST): | 22 class _resolved(ast.AST): |
23 """_resolved is a fake AST node which represents a resolved sub-expression. | 23 """_resolved is a fake AST node which represents a resolved sub-expression. |
24 It's used by _checkTransformer to replace portions of its AST with their | 24 It's used by _checkTransformer to replace portions of its AST with their |
25 resolved equivalents.""" | 25 resolved equivalents.""" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 417 |
418 | 418 |
419 def _nameOfCallable(c): | 419 def _nameOfCallable(c): |
420 if hasattr(c, '__call__'): | 420 if hasattr(c, '__call__'): |
421 return c.__class__.__name__+'.__call__' | 421 return c.__class__.__name__+'.__call__' |
422 if inspect.ismethod(c): | 422 if inspect.ismethod(c): |
423 return c.im_class.__name__+'.'+c.__name__ | 423 return c.im_class.__name__+'.'+c.__name__ |
424 if inspect.isfunction(c): | 424 if inspect.isfunction(c): |
425 return c.__name__ | 425 return c.__name__ |
426 return repr(c) | 426 return repr(c) |
OLD | NEW |