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
commit90ef70abfa57397ce34aab4e9b23a7623e48d66f (patch)
treef1614b9ea928b561d14ad725f6242fed40d79710 /astroid/test_utils.py
parentbd25fc260e6f66086746eec57ccfe87d6fd56aaa (diff)
downloadastroid-git-90ef70abfa57397ce34aab4e9b23a7623e48d66f.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 19bd7b96..e45177a4 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.