diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:25:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:25:40 +0000 |
commit | cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch) | |
tree | 18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/test_project.py | |
parent | Initial commit. (diff) | |
download | sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip |
Adding upstream version 7.2.6.upstream/7.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_project.py')
-rw-r--r-- | tests/test_project.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_project.py b/tests/test_project.py new file mode 100644 index 0000000..45ae7c8 --- /dev/null +++ b/tests/test_project.py @@ -0,0 +1,78 @@ +"""Tests project module.""" + +import pytest + +from sphinx.project import Project + +DOCNAMES = {'autodoc', 'bom', 'extapi', 'extensions', 'footnote', 'images', + 'includes', 'index', 'lists', 'markup', 'math', 'objects', + 'subdir/excluded', 'subdir/images', 'subdir/includes'} +SUBDIR_DOCNAMES = {'subdir/excluded', 'subdir/images', 'subdir/includes'} + + +def test_project_discover_basic(rootdir): + # basic case + project = Project(rootdir / 'test-root', ['.txt']) + assert project.discover() == DOCNAMES + + +def test_project_discover_exclude_patterns(rootdir): + project = Project(rootdir / 'test-root', ['.txt']) + + # exclude_paths option + assert project.discover(['subdir/*']) == DOCNAMES - SUBDIR_DOCNAMES + assert project.discover(['.txt', 'subdir/*']) == DOCNAMES - SUBDIR_DOCNAMES + + +def test_project_discover_multiple_suffixes(rootdir): + # multiple source_suffixes + project = Project(rootdir / 'test-root', ['.txt', '.foo']) + assert project.discover() == DOCNAMES | {'otherext'} + + +def test_project_discover_complicated_suffix(rootdir): + # complicated source_suffix + project = Project(rootdir / 'test-root', ['.foo.png']) + assert project.discover() == {'img'} + + +def test_project_discover_templates_path(rootdir): + # templates_path + project = Project(rootdir / 'test-root', ['.html']) + assert project.discover() == {'_templates/layout', + '_templates/customsb', + '_templates/contentssb'} + + assert project.discover(['_templates']) == set() + + +def test_project_path2doc(rootdir): + project = Project(rootdir / 'test-basic', {'.rst': 'restructuredtext'}) + 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(rootdir / 'test-basic' / 'to/index.rst') == 'to/index' + + +@pytest.mark.sphinx(srcdir='project_doc2path', testroot='basic') +def test_project_doc2path(app): + source_suffix = {'.rst': 'restructuredtext', '.txt': 'restructuredtext'} + + project = Project(app.srcdir, source_suffix) + project.discover() + + # absolute path + assert project.doc2path('index', absolute=True) == str(app.srcdir / 'index.rst') + + # relative path + assert project.doc2path('index', absolute=False) == 'index.rst' + + # first source_suffix is used for missing file + assert project.doc2path('foo', absolute=False) == 'foo.rst' + + # matched source_suffix is used if exists + (app.srcdir / 'bar.txt').touch() + project.discover() + assert project.doc2path('bar', absolute=False) == 'bar.txt' |