summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnubhav <35621759+anubh-v@users.noreply.github.com>2020-03-11 21:04:40 +0800
committerGitHub <noreply@github.com>2020-03-11 14:04:40 +0100
commit3a075c0205a717bbd68562da5017992c430549d3 (patch)
tree0d44747ebf5dccf23f10e105495acb1fd7887c9c /tests
parentf2c75754dbaafbe2d9800eb8d3fc38383414dad1 (diff)
downloadastroid-git-3a075c0205a717bbd68562da5017992c430549d3.tar.gz
Add a new ast_from_string method to AstroidManager
Close #725
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_manager.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/unittest_manager.py b/tests/unittest_manager.py
index b56a0580..f22414c4 100644
--- a/tests/unittest_manager.py
+++ b/tests/unittest_manager.py
@@ -67,6 +67,17 @@ class AstroidManagerTest(
exceptions.AstroidBuildingError, self.manager.ast_from_file, "unhandledName"
)
+ def test_ast_from_string(self):
+ filepath = unittest.__file__
+ dirname = os.path.dirname(filepath)
+ modname = os.path.basename(dirname)
+ with open(filepath, "r") as file:
+ data = file.read()
+ ast = self.manager.ast_from_string(data, modname, filepath)
+ self.assertEqual(ast.name, "unittest")
+ self.assertEqual(ast.file, filepath)
+ self.assertIn("unittest", self.manager.astroid_cache)
+
def test_do_not_expose_main(self):
obj = self.manager.ast_from_module_name("__main__")
self.assertEqual(obj.name, "__main__")