Move env.doc2path() and env.path2doc() to Project class

This commit is contained in:
Takeshi KOMIYA committed 2018-10-16 10:34:59 +09:00
1 parent 491d0406df
commit 84e1eeb8a2
4 files changed
+130 -29

No files matched your search

+35
View File
@@ -9,6 +9,8 @@
:license: BSD, see LICENSE for details.
"""
from collections import OrderedDict
import pytest
from sphinx.project import Project
@@ -47,3 +49,36 @@ def test_project_discovery(rootdir):
'_templates/contentssb'}
assert project.discovery(['_templates']) == set()
@pytest.mark.sphinx(testroot='basic')
def test_project_path2doc(app):
project = Project(app.srcdir, app.config.source_suffix)
assert project.path2doc('index.rst') == 'index'
assert project.path2doc('index.foo') is None # unknown extension
assert project.path2doc('index.foo.rst') == 'index.foo'
assert project.path2doc('index') is None
assert project.path2doc('/path/to/index.rst') == '/path/to/index'
assert project.path2doc(app.srcdir / '/to/index.rst') == '/to/index'
@pytest.mark.sphinx(srcdir='project_doc2path', testroot='basic')
def test_project_doc2path(app):
source_suffix = OrderedDict([('.rst', 'restructuredtext'),
('.txt', 'restructuredtext')])
project = Project(app.srcdir, source_suffix)
assert project.doc2path('index') == (app.srcdir / 'index.rst')
# first source_suffix is used for missing file
assert project.doc2path('foo') == (app.srcdir / 'foo.rst')
# matched source_suffix is used if exists
(app.srcdir / 'foo.txt').write_text('')
assert project.doc2path('foo') == (app.srcdir / 'foo.txt')
# absolute path
assert project.doc2path('index', basedir=True) == (app.srcdir / 'index.rst')
# relative path
assert project.doc2path('index', basedir=False) == 'index.rst'