From 0a982d5ebd1cdb660d07e476aefa0d438e71fcb0 Mon Sep 17 00:00:00 2001 From: hkm Date: Wed, 25 Dec 2019 22:29:20 +0300 Subject: Old get_module_source API restored, new version moved to ModuleAnalyzer class, tests updated --- tests/test_pycode.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/test_pycode.py') diff --git a/tests/test_pycode.py b/tests/test_pycode.py index cd039070c..be61d9efb 100644 --- a/tests/test_pycode.py +++ b/tests/test_pycode.py @@ -10,12 +10,23 @@ import os import sys +import pytest import sphinx from sphinx.pycode import ModuleAnalyzer +from sphinx.errors import PycodeError SPHINX_MODULE_PATH = os.path.splitext(sphinx.__file__)[0] + '.py' +def test_ModuleAnalyzer_get_module_source(): + assert ModuleAnalyzer.get_module_source('sphinx') == (sphinx.__file__, sphinx.__loader__.get_source('sphinx')) + + # failed to obtain source information from builtin modules + with pytest.raises(PycodeError): + ModuleAnalyzer.get_module_source('builtins') + with pytest.raises(PycodeError): + ModuleAnalyzer.get_module_source('itertools') + def test_ModuleAnalyzer_for_string(): analyzer = ModuleAnalyzer.for_string('print("Hello world")', 'module_name') -- cgit v1.2.1