Old get_module_source API restored, new version moved to ModuleAnalyzer class, tests updated

This commit is contained in:
hkm
2019-12-25 22:29:20 +03:00
parent c4e60b5b9c
commit 0a982d5ebd
4 changed files with 81 additions and 24 deletions

View File

@@ -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')