summaryrefslogtreecommitdiff
path: root/astroid/test_utils.py
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2015-07-11 17:02:33 -0400
committerCeridwen <ceridwenv@gmail.com>2015-07-11 17:02:33 -0400
commit9318df87f26269a30a2f5c734e36d7df6bff1c18 (patch)
tree28a06a8a6ec0090d7f74a4985320d2a9403c88ea /astroid/test_utils.py
parent41f07a39030b31eaf7e2a262618bf32014deb7b7 (diff)
parentd3b9b7b8e06de3d56c4d479cd996bd97c901924f (diff)
downloadastroid-9318df87f26269a30a2f5c734e36d7df6bff1c18.tar.gz
Merge logilab/astroid again
Diffstat (limited to 'astroid/test_utils.py')
-rw-r--r--astroid/test_utils.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/astroid/test_utils.py b/astroid/test_utils.py
index d5cc5c3..c1d63f1 100644
--- a/astroid/test_utils.py
+++ b/astroid/test_utils.py
@@ -13,7 +13,6 @@ _TRANSIENT_FUNCTION = '__'
# when calling extract_node.
_STATEMENT_SELECTOR = '#@'
-
def _extract_expressions(node):
"""Find expressions in a call to _TRANSIENT_FUNCTION and extract them.
@@ -27,7 +26,7 @@ def _extract_expressions(node):
:yields: The sequence of wrapped expressions on the modified tree
expression can be found.
"""
- if (isinstance(node, nodes.CallFunc)
+ if (isinstance(node, nodes.Call)
and isinstance(node.func, nodes.Name)
and node.func.name == _TRANSIENT_FUNCTION):
real_expr = node.args[0]
@@ -47,6 +46,7 @@ def _extract_expressions(node):
setattr(node.parent, name, real_expr)
yield real_expr
else:
+ # print(as_string.dump(node))
for child in node.get_children():
for result in _extract_expressions(child):
yield result
@@ -67,7 +67,7 @@ def _find_statement_by_line(node, line):
can be found.
:rtype: astroid.bases.NodeNG or None
"""
- if isinstance(node, (nodes.Class, nodes.Function)):
+ if isinstance(node, (nodes.ClassDef, nodes.FunctionDef)):
# This is an inaccuracy in the AST: the nodes that can be
# decorated do not carry explicit information on which line
# the actual definition (class/def), but .fromline seems to
@@ -79,7 +79,12 @@ def _find_statement_by_line(node, line):
if node_line == line:
return node
+ # print(as_string.dump(node))
for child in node.get_children():
+ # print(type(child))
+ # if isinstance(child, tuple):
+ # # print(as_string.dump(node))
+ # print(node.names)
result = _find_statement_by_line(child, line)
if result:
return result
@@ -141,7 +146,7 @@ def extract_node(code, module_name=''):
:rtype: astroid.bases.NodeNG, or a list of nodes.
"""
def _extract(node):
- if isinstance(node, nodes.Discard):
+ if isinstance(node, nodes.Expr):
return node.value
else:
return node
@@ -153,6 +158,7 @@ def extract_node(code, module_name=''):
tree = builder.parse(code, module_name=module_name)
extracted = []
+ # print(as_string.dump(tree))
if requested_lines:
for line in requested_lines:
extracted.append(_find_statement_by_line(tree, line))