summaryrefslogtreecommitdiff
path: root/astroid/test_utils.py
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-07-11 18:12:18 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-07-11 18:12:18 +0300
commitd254c649801657c214058b6db743d87fd38741e7 (patch)
tree8a0a30190457b025684ed6edd35903c43ae57253 /astroid/test_utils.py
parent05952baeddee1a7d0224beb416dc042f72feaa9d (diff)
downloadastroid-d254c649801657c214058b6db743d87fd38741e7.tar.gz
Add a new convenience API, `astroid.parse`.
This API can be used to retrieve an astroid AST from a source code string, similar to how ast.parse can be used to obtain a Python AST from a source string. This is the test_utils.build_module promoted to a public API.
Diffstat (limited to 'astroid/test_utils.py')
-rw-r--r--astroid/test_utils.py17
1 files changed, 1 insertions, 16 deletions
diff --git a/astroid/test_utils.py b/astroid/test_utils.py
index 19bd7b9..e45177a 100644
--- a/astroid/test_utils.py
+++ b/astroid/test_utils.py
@@ -152,7 +152,7 @@ def extract_node(code, module_name=''):
if line.strip().endswith(_STATEMENT_SELECTOR):
requested_lines.append(idx + 1)
- tree = build_module(code, module_name=module_name)
+ tree = builder.parse(code, module_name=module_name)
extracted = []
if requested_lines:
for line in requested_lines:
@@ -171,21 +171,6 @@ def extract_node(code, module_name=''):
return extracted
-def build_module(code, module_name='', path=None):
- """Parses a string module with a builder.
- :param code: The code for the module.
- :type code: str
- :param module_name: The name for the module
- :type module_name: str
- :param path: The path for the module
- :type module_name: str
- :returns: The module AST.
- :rtype: astroid.bases.NodeNG
- """
- code = textwrap.dedent(code)
- return builder.AstroidBuilder(None).string_build(code, modname=module_name, path=path)
-
-
def require_version(minver=None, maxver=None):
""" Compare version of python interpreter to the given one. Skip the test
if older.