diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-01 11:39:46 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-01 11:39:46 +0900 |
| commit | e628afd5cd0c565f1e33abb01cac26180455182f (patch) | |
| tree | 3b7cddfe175c444588a0b8d9e80430faeb994b8c /tests/test_pycode.py | |
| parent | 9458d631d0393956005754ed8137809e15635467 (diff) | |
| parent | c5b653433d3fbdca47396f17161685f50d994320 (diff) | |
| download | sphinx-git-e628afd5cd0c565f1e33abb01cac26180455182f.tar.gz | |
Merge branch '2.0'
Diffstat (limited to 'tests/test_pycode.py')
| -rw-r--r-- | tests/test_pycode.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/tests/test_pycode.py b/tests/test_pycode.py index 5eccad0db..458e813f6 100644 --- a/tests/test_pycode.py +++ b/tests/test_pycode.py @@ -10,33 +10,50 @@ 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') assert analyzer.modname == 'module_name' assert analyzer.srcname == '<string>' - assert analyzer.encoding is None def test_ModuleAnalyzer_for_file(): analyzer = ModuleAnalyzer.for_string(SPHINX_MODULE_PATH, 'sphinx') assert analyzer.modname == 'sphinx' assert analyzer.srcname == '<string>' - assert analyzer.encoding is None -def test_ModuleAnalyzer_for_module(): +def test_ModuleAnalyzer_for_module(rootdir): analyzer = ModuleAnalyzer.for_module('sphinx') assert analyzer.modname == 'sphinx' assert analyzer.srcname in (SPHINX_MODULE_PATH, os.path.abspath(SPHINX_MODULE_PATH)) - assert analyzer.encoding == 'utf-8' + + path = rootdir / 'test-pycode' + sys.path.insert(0, path) + try: + analyzer = ModuleAnalyzer.for_module('cp_1251_coded') + docs = analyzer.find_attr_docs() + assert docs == {('', 'X'): ['It MUST look like X="\u0425"', '']} + finally: + sys.path.pop(0) def test_ModuleAnalyzer_for_file_in_egg(rootdir): |
