summaryrefslogtreecommitdiffstats
path: root/tests/test_environment
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:20:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:20:58 +0000
commit5bb0bb4be543fd5eca41673696a62ed80d493591 (patch)
treead2c464f140e86c7f178a6276d7ea4a93e3e6c92 /tests/test_environment
parentAdding upstream version 7.2.6. (diff)
downloadsphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.tar.xz
sphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.zip
Adding upstream version 7.3.7.upstream/7.3.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_environment')
-rw-r--r--tests/test_environment/__init__.py0
-rw-r--r--tests/test_environment/test_environment.py145
-rw-r--r--tests/test_environment/test_environment_indexentries.py166
-rw-r--r--tests/test_environment/test_environment_record_dependencies.py10
-rw-r--r--tests/test_environment/test_environment_toctree.py396
5 files changed, 717 insertions, 0 deletions
diff --git a/tests/test_environment/__init__.py b/tests/test_environment/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/test_environment/__init__.py
diff --git a/tests/test_environment/test_environment.py b/tests/test_environment/test_environment.py
new file mode 100644
index 0000000..8a34457
--- /dev/null
+++ b/tests/test_environment/test_environment.py
@@ -0,0 +1,145 @@
+"""Test the BuildEnvironment class."""
+import os
+import shutil
+from pathlib import Path
+
+import pytest
+
+from sphinx.builders.html import StandaloneHTMLBuilder
+from sphinx.builders.latex import LaTeXBuilder
+from sphinx.environment import CONFIG_CHANGED, CONFIG_EXTENSIONS_CHANGED, CONFIG_NEW, CONFIG_OK
+
+
+@pytest.mark.sphinx('dummy', testroot='basic')
+def test_config_status(make_app, app_params):
+ args, kwargs = app_params
+
+ # clean build
+ app1 = make_app(*args, freshenv=True, **kwargs)
+ assert app1.env.config_status == CONFIG_NEW
+ app1.build()
+ assert '[new config] 1 added' in app1._status.getvalue()
+
+ # incremental build (no config changed)
+ app2 = make_app(*args, **kwargs)
+ assert app2.env.config_status == CONFIG_OK
+ app2.build()
+ assert "0 added, 0 changed, 0 removed" in app2._status.getvalue()
+
+ # incremental build (config entry changed)
+ app3 = make_app(*args, confoverrides={'root_doc': 'indexx'}, **kwargs)
+ fname = os.path.join(app3.srcdir, 'index.rst')
+ assert os.path.isfile(fname)
+ shutil.move(fname, fname[:-4] + 'x.rst')
+ assert app3.env.config_status == CONFIG_CHANGED
+ app3.build()
+ shutil.move(fname[:-4] + 'x.rst', fname)
+ assert "[config changed ('root_doc')] 1 added" in app3._status.getvalue()
+
+ # incremental build (extension changed)
+ app4 = make_app(*args, confoverrides={'extensions': ['sphinx.ext.autodoc']}, **kwargs)
+ assert app4.env.config_status == CONFIG_EXTENSIONS_CHANGED
+ app4.build()
+ want_str = "[extensions changed ('sphinx.ext.autodoc')] 1 added"
+ assert want_str in app4._status.getvalue()
+
+
+@pytest.mark.sphinx('dummy')
+def test_images(app):
+ app.build()
+
+ tree = app.env.get_doctree('images')
+ htmlbuilder = StandaloneHTMLBuilder(app, app.env)
+ htmlbuilder.init()
+ htmlbuilder.imgpath = 'dummy'
+ htmlbuilder.post_process_images(tree)
+ assert set(htmlbuilder.images.keys()) == \
+ {'subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg', 'img.foo.png'}
+ assert set(htmlbuilder.images.values()) == \
+ {'img.png', 'img1.png', 'simg.png', 'svgimg.svg', 'img.foo.png'}
+
+ latexbuilder = LaTeXBuilder(app, app.env)
+ latexbuilder.init()
+ latexbuilder.post_process_images(tree)
+ assert set(latexbuilder.images.keys()) == \
+ {'subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf',
+ 'svgimg.pdf', 'img.foo.png'}
+ assert set(latexbuilder.images.values()) == \
+ {'img.pdf', 'img.png', 'img1.png', 'simg.png',
+ 'svgimg.pdf', 'img.foo.png'}
+
+
+@pytest.mark.sphinx('dummy')
+def test_object_inventory(app):
+ app.build()
+ refs = app.env.domaindata['py']['objects']
+
+ assert 'func_without_module' in refs
+ assert refs['func_without_module'] == ('objects', 'func_without_module', 'function', False)
+ assert 'func_without_module2' in refs
+ assert 'mod.func_in_module' in refs
+ assert 'mod.Cls' in refs
+ assert 'mod.Cls.meth1' in refs
+ assert 'mod.Cls.meth2' in refs
+ assert 'mod.Cls.meths' in refs
+
+ assert 'mod.Error' not in refs
+ assert 'errmod.Error' in refs
+
+ assert 'func_in_module' not in refs
+ assert 'func_noindex' not in refs
+
+ assert app.env.domaindata['py']['modules']['mod'] == \
+ ('objects', 'module-mod', 'Module synopsis.', 'UNIX', False)
+
+ assert app.env.domains['py'].data is app.env.domaindata['py']
+ assert app.env.domains['c'].data is app.env.domaindata['c']
+
+
+@pytest.mark.sphinx('dummy', testroot='basic')
+def test_env_relfn2path(app):
+ # relative filename and root document
+ relfn, absfn = app.env.relfn2path('logo.jpg', 'index')
+ assert relfn == 'logo.jpg'
+ assert absfn == str(app.srcdir / 'logo.jpg')
+
+ # absolute filename and root document
+ relfn, absfn = app.env.relfn2path('/logo.jpg', 'index')
+ assert relfn == 'logo.jpg'
+ assert absfn == str(app.srcdir / 'logo.jpg')
+
+ # relative filename and a document in subdir
+ relfn, absfn = app.env.relfn2path('logo.jpg', 'subdir/index')
+ assert Path(relfn) == Path('subdir/logo.jpg')
+ assert absfn == str(app.srcdir / 'subdir' / 'logo.jpg')
+
+ # absolute filename and a document in subdir
+ relfn, absfn = app.env.relfn2path('/logo.jpg', 'subdir/index')
+ assert relfn == 'logo.jpg'
+ assert absfn == str(app.srcdir / 'logo.jpg')
+
+ # relative filename having subdir
+ relfn, absfn = app.env.relfn2path('images/logo.jpg', 'index')
+ assert relfn == 'images/logo.jpg'
+ assert absfn == str(app.srcdir / 'images' / 'logo.jpg')
+
+ # relative path traversal
+ relfn, absfn = app.env.relfn2path('../logo.jpg', 'index')
+ assert relfn == '../logo.jpg'
+ assert absfn == str(app.srcdir.parent / 'logo.jpg')
+
+ # relative path traversal
+ relfn, absfn = app.env.relfn2path('subdir/../logo.jpg', 'index')
+ assert relfn == 'logo.jpg'
+ assert absfn == str(app.srcdir / 'logo.jpg')
+
+ # omit docname (w/ current docname)
+ app.env.temp_data['docname'] = 'subdir/document'
+ relfn, absfn = app.env.relfn2path('images/logo.jpg')
+ assert Path(relfn) == Path('subdir/images/logo.jpg')
+ assert absfn == str(app.srcdir / 'subdir' / 'images' / 'logo.jpg')
+
+ # omit docname (w/o current docname)
+ app.env.temp_data.clear()
+ with pytest.raises(KeyError):
+ app.env.relfn2path('images/logo.jpg')
diff --git a/tests/test_environment/test_environment_indexentries.py b/tests/test_environment/test_environment_indexentries.py
new file mode 100644
index 0000000..4cfdc28
--- /dev/null
+++ b/tests/test_environment/test_environment_indexentries.py
@@ -0,0 +1,166 @@
+"""Test the sphinx.environment.adapters.indexentries."""
+
+import pytest
+
+from sphinx.environment.adapters.indexentries import IndexEntries
+from sphinx.testing import restructuredtext
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_single_index(app):
+ text = (".. index:: docutils\n"
+ ".. index:: Python\n"
+ ".. index:: pip; install\n"
+ ".. index:: pip; upgrade\n"
+ ".. index:: Sphinx\n"
+ ".. index:: Ель\n"
+ ".. index:: ёлка\n"
+ ".. index:: \N{RIGHT-TO-LEFT MARK}\u05e2\u05d1\u05e8\u05d9\u05ea\N{LEFT-TO-RIGHT MARK}\n"
+ ".. index:: 9-symbol\n"
+ ".. index:: &-symbol\n"
+ ".. index:: £100\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 6
+ assert index[0] == ('Symbols', [('&-symbol', [[('', '#index-9')], [], None]),
+ ('9-symbol', [[('', '#index-8')], [], None]),
+ ('£100', [[('', '#index-10')], [], None])])
+ assert index[1] == ('D', [('docutils', [[('', '#index-0')], [], None])])
+ assert index[2] == ('P', [('pip', [[], [('install', [('', '#index-2')]),
+ ('upgrade', [('', '#index-3')])], None]),
+ ('Python', [[('', '#index-1')], [], None])])
+ assert index[3] == ('S', [('Sphinx', [[('', '#index-4')], [], None])])
+ assert index[4] == ('Е',
+ [('ёлка', [[('', '#index-6')], [], None]),
+ ('Ель', [[('', '#index-5')], [], None])])
+ # Here the word starts with U+200F RIGHT-TO-LEFT MARK, which should be
+ # ignored when getting the first letter.
+ assert index[5] == ('\u05e2', [(
+ '\N{RIGHT-TO-LEFT MARK}\u05e2\u05d1\u05e8\u05d9\u05ea\N{LEFT-TO-RIGHT MARK}',
+ [[('', '#index-7')], [], None],
+ )])
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_pair_index(app):
+ text = (".. index:: pair: docutils; reStructuredText\n"
+ ".. index:: pair: Python; interpreter\n"
+ ".. index:: pair: Sphinx; documentation tool\n"
+ ".. index:: pair: Sphinx; :+1:\n"
+ ".. index:: pair: Sphinx; Ель\n"
+ ".. index:: pair: Sphinx; ёлка\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 7
+ assert index[0] == ('Symbols', [(':+1:', [[], [('Sphinx', [('', '#index-3')])], None])])
+ assert index[1] == ('D',
+ [('documentation tool', [[], [('Sphinx', [('', '#index-2')])], None]),
+ ('docutils', [[], [('reStructuredText', [('', '#index-0')])], None])])
+ assert index[2] == ('I', [('interpreter', [[], [('Python', [('', '#index-1')])], None])])
+ assert index[3] == ('P', [('Python', [[], [('interpreter', [('', '#index-1')])], None])])
+ assert index[4] == ('R',
+ [('reStructuredText', [[], [('docutils', [('', '#index-0')])], None])])
+ assert index[5] == ('S',
+ [('Sphinx', [[],
+ [(':+1:', [('', '#index-3')]),
+ ('documentation tool', [('', '#index-2')]),
+ ('ёлка', [('', '#index-5')]),
+ ('Ель', [('', '#index-4')])],
+ None])])
+ assert index[6] == ('Е',
+ [('ёлка', [[], [('Sphinx', [('', '#index-5')])], None]),
+ ('Ель', [[], [('Sphinx', [('', '#index-4')])], None])])
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_triple_index(app):
+ text = (".. index:: triple: foo; bar; baz\n"
+ ".. index:: triple: Python; Sphinx; reST\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 5
+ assert index[0] == ('B', [('bar', [[], [('baz, foo', [('', '#index-0')])], None]),
+ ('baz', [[], [('foo bar', [('', '#index-0')])], None])])
+ assert index[1] == ('F', [('foo', [[], [('bar baz', [('', '#index-0')])], None])])
+ assert index[2] == ('P', [('Python', [[], [('Sphinx reST', [('', '#index-1')])], None])])
+ assert index[3] == ('R', [('reST', [[], [('Python Sphinx', [('', '#index-1')])], None])])
+ assert index[4] == ('S', [('Sphinx', [[], [('reST, Python', [('', '#index-1')])], None])])
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_see_index(app):
+ text = (".. index:: see: docutils; reStructuredText\n"
+ ".. index:: see: Python; interpreter\n"
+ ".. index:: see: Sphinx; documentation tool\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 3
+ assert index[0] == ('D', [('docutils', [[], [('see reStructuredText', [])], None])])
+ assert index[1] == ('P', [('Python', [[], [('see interpreter', [])], None])])
+ assert index[2] == ('S', [('Sphinx', [[], [('see documentation tool', [])], None])])
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_seealso_index(app):
+ text = (".. index:: seealso: docutils; reStructuredText\n"
+ ".. index:: seealso: Python; interpreter\n"
+ ".. index:: seealso: Sphinx; documentation tool\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 3
+ assert index[0] == ('D', [('docutils', [[], [('see also reStructuredText', [])], None])])
+ assert index[1] == ('P', [('Python', [[], [('see also interpreter', [])], None])])
+ assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])])
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_main_index(app):
+ text = (".. index:: !docutils\n"
+ ".. index:: docutils\n"
+ ".. index:: pip; install\n"
+ ".. index:: !pip; install\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 2
+ assert index[0] == ('D', [('docutils', [[('main', '#index-0'),
+ ('', '#index-1')], [], None])])
+ assert index[1] == ('P', [('pip', [[], [('install', [('main', '#index-3'),
+ ('', '#index-2')])], None])])
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_index_with_name(app):
+ text = (".. index:: single: docutils\n"
+ " :name: ref1\n"
+ ".. index:: single: Python\n"
+ " :name: ref2\n"
+ ".. index:: Sphinx\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+
+ # check index is created correctly
+ assert len(index) == 3
+ assert index[0] == ('D', [('docutils', [[('', '#ref1')], [], None])])
+ assert index[1] == ('P', [('Python', [[('', '#ref2')], [], None])])
+ assert index[2] == ('S', [('Sphinx', [[('', '#index-0')], [], None])])
+
+ # check the reference labels are created correctly
+ std = app.env.get_domain('std')
+ assert std.anonlabels['ref1'] == ('index', 'ref1')
+ assert std.anonlabels['ref2'] == ('index', 'ref2')
+
+
+@pytest.mark.sphinx('dummy', freshenv=True)
+def test_create_index_by_key(app):
+ # At present, only glossary directive is able to create index key
+ text = (".. glossary::\n"
+ "\n"
+ " docutils\n"
+ " Python\n"
+ " スフィンクス : ス\n")
+ restructuredtext.parse(app, text)
+ index = IndexEntries(app.env).create_index(app.builder)
+ assert len(index) == 3
+ assert index[0] == ('D', [('docutils', [[('main', '#term-docutils')], [], None])])
+ assert index[1] == ('P', [('Python', [[('main', '#term-Python')], [], None])])
+ assert index[2] == ('ス', [('スフィンクス', [[('main', '#term-0')], [], 'ス'])])
diff --git a/tests/test_environment/test_environment_record_dependencies.py b/tests/test_environment/test_environment_record_dependencies.py
new file mode 100644
index 0000000..0a17253
--- /dev/null
+++ b/tests/test_environment/test_environment_record_dependencies.py
@@ -0,0 +1,10 @@
+"""Tests for ``record_dependencies``."""
+
+import pytest
+
+
+@pytest.mark.sphinx('html', testroot='environment-record-dependencies')
+def test_record_dependencies_cleared(app):
+ app.builder.read()
+ assert app.env.dependencies['index'] == set()
+ assert app.env.dependencies['api'] == {'example_module.py'}
diff --git a/tests/test_environment/test_environment_toctree.py b/tests/test_environment/test_environment_toctree.py
new file mode 100644
index 0000000..175c6ab
--- /dev/null
+++ b/tests/test_environment/test_environment_toctree.py
@@ -0,0 +1,396 @@
+"""Test the sphinx.environment.adapters.toctree."""
+
+import pytest
+from docutils import nodes
+from docutils.nodes import bullet_list, list_item, literal, reference, title
+
+from sphinx import addnodes
+from sphinx.addnodes import compact_paragraph, only
+from sphinx.builders.html import StandaloneHTMLBuilder
+from sphinx.environment.adapters.toctree import document_toc, global_toctree_for_doc
+from sphinx.testing.util import assert_node
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_process_doc(app):
+ app.build()
+ # tocs
+ toctree = app.env.tocs['index']
+ assert_node(toctree,
+ [bullet_list, ([list_item, (compact_paragraph, # [0][0]
+ [bullet_list, (addnodes.toctree, # [0][1][0]
+ only, # [0][1][1]
+ list_item)])], # [0][1][2]
+ [list_item, (compact_paragraph, # [1][0]
+ [bullet_list, (addnodes.toctree, # [1][1][0]
+ addnodes.toctree)])], # [1][1][1]
+ list_item)])
+
+ assert_node(toctree[0][0],
+ [compact_paragraph, reference, "Welcome to Sphinx Tests’s documentation!"])
+ assert_node(toctree[0][0][0], reference, anchorname='')
+ assert_node(toctree[0][1][0], addnodes.toctree,
+ caption="Table of Contents", glob=False, hidden=False,
+ titlesonly=False, maxdepth=2, numbered=999,
+ entries=[(None, 'foo'), (None, 'bar'), (None, 'https://sphinx-doc.org/'),
+ (None, 'self')],
+ includefiles=['foo', 'bar'])
+
+ # only branch
+ assert_node(toctree[0][1][1], addnodes.only, expr="html")
+ assert_node(toctree[0][1][1],
+ [only, list_item, ([compact_paragraph, reference, "Section for HTML"],
+ [bullet_list, addnodes.toctree])])
+ assert_node(toctree[0][1][1][0][0][0], reference, anchorname='#section-for-html')
+ assert_node(toctree[0][1][1][0][1][0], addnodes.toctree,
+ caption=None, glob=False, hidden=False, entries=[(None, 'baz')],
+ includefiles=['baz'], titlesonly=False, maxdepth=-1, numbered=0)
+ assert_node(toctree[0][1][2],
+ ([compact_paragraph, reference, "subsection"],
+ [bullet_list, list_item, compact_paragraph, reference, "subsubsection"]))
+
+ assert_node(toctree[1][0],
+ [compact_paragraph, reference, "Test for issue #1157"])
+ assert_node(toctree[1][0][0], reference, anchorname='#test-for-issue-1157')
+ assert_node(toctree[1][1][0], addnodes.toctree,
+ caption=None, entries=[], glob=False, hidden=False,
+ titlesonly=False, maxdepth=-1, numbered=0)
+ assert_node(toctree[1][1][1], addnodes.toctree,
+ caption=None, glob=False, hidden=True,
+ titlesonly=False, maxdepth=-1, numbered=0,
+ entries=[('Latest reference', 'https://sphinx-doc.org/latest/'),
+ ('Python', 'https://python.org/')])
+
+ assert_node(toctree[2][0],
+ [compact_paragraph, reference, "Indices and tables"])
+
+ # other collections
+ assert app.env.toc_num_entries['index'] == 6
+ assert app.env.toctree_includes['index'] == ['foo', 'bar', 'baz']
+ assert app.env.files_to_rebuild['foo'] == {'index'}
+ assert app.env.files_to_rebuild['bar'] == {'index'}
+ assert app.env.files_to_rebuild['baz'] == {'index'}
+ assert app.env.glob_toctrees == set()
+ assert app.env.numbered_toctrees == {'index'}
+
+ # qux has no section title
+ assert len(app.env.tocs['qux']) == 0
+ assert_node(app.env.tocs['qux'], nodes.bullet_list)
+ assert app.env.toc_num_entries['qux'] == 0
+ assert 'qux' not in app.env.toctree_includes
+
+
+@pytest.mark.sphinx('dummy', testroot='toctree-glob')
+def test_glob(app):
+ includefiles = ['foo', 'bar/index', 'bar/bar_1', 'bar/bar_2',
+ 'bar/bar_3', 'baz', 'qux/index']
+
+ app.build()
+
+ # tocs
+ toctree = app.env.tocs['index']
+ assert_node(toctree,
+ [bullet_list, list_item, (compact_paragraph, # [0][0]
+ [bullet_list, (list_item, # [0][1][0]
+ list_item)])]) # [0][1][1]
+
+ assert_node(toctree[0][0],
+ [compact_paragraph, reference, "test-toctree-glob"])
+ assert_node(toctree[0][1][0],
+ [list_item, ([compact_paragraph, reference, "normal order"],
+ [bullet_list, addnodes.toctree])]) # [0][1][0][1][0]
+ assert_node(toctree[0][1][0][1][0], addnodes.toctree, caption=None,
+ glob=True, hidden=False, titlesonly=False,
+ maxdepth=-1, numbered=0, includefiles=includefiles,
+ entries=[(None, 'foo'), (None, 'bar/index'), (None, 'bar/bar_1'),
+ (None, 'bar/bar_2'), (None, 'bar/bar_3'), (None, 'baz'),
+ (None, 'qux/index'),
+ ('hyperref', 'https://sphinx-doc.org/?q=sphinx')])
+ assert_node(toctree[0][1][1],
+ [list_item, ([compact_paragraph, reference, "reversed order"],
+ [bullet_list, addnodes.toctree])]) # [0][1][1][1][0]
+ assert_node(toctree[0][1][1][1][0], addnodes.toctree, caption=None,
+ glob=True, hidden=False, titlesonly=False,
+ maxdepth=-1, numbered=0, includefiles=list(reversed(includefiles)),
+ entries=[(None, 'qux/index'), (None, 'baz'), (None, 'bar/bar_3'),
+ (None, 'bar/bar_2'), (None, 'bar/bar_1'), (None, 'bar/index'),
+ (None, 'foo')])
+
+ # other collections
+ assert app.env.toc_num_entries['index'] == 3
+ assert app.env.toctree_includes['index'] == includefiles + list(reversed(includefiles))
+ for file in includefiles:
+ assert 'index' in app.env.files_to_rebuild[file]
+ assert 'index' in app.env.glob_toctrees
+ assert app.env.numbered_toctrees == set()
+
+
+@pytest.mark.sphinx('dummy', testroot='toctree-domain-objects')
+def test_domain_objects(app):
+ app.build()
+
+ assert app.env.toc_num_entries['index'] == 0
+ assert app.env.toc_num_entries['domains'] == 9
+ assert app.env.toctree_includes['index'] == ['domains']
+ assert 'index' in app.env.files_to_rebuild['domains']
+ assert app.env.glob_toctrees == set()
+ assert app.env.numbered_toctrees == {'index'}
+
+ # tocs
+ toctree = app.env.tocs['domains']
+ assert_node(toctree,
+ [bullet_list, list_item, (compact_paragraph, # [0][0]
+ [bullet_list, (list_item, # [0][1][0]
+ [list_item, # [0][1][1]
+ (compact_paragraph, # [0][1][1][0]
+ [bullet_list, (list_item, # [0][1][1][1][0]
+ list_item,
+ list_item,
+ list_item)])], # [0][1][1][1][3]
+ list_item,
+ list_item)])]) # [0][1][1]
+
+ assert_node(toctree[0][0],
+ [compact_paragraph, reference, "test-domain-objects"])
+
+ assert_node(toctree[0][1][0],
+ [list_item, ([compact_paragraph, reference, literal, "world()"])])
+
+ assert_node(toctree[0][1][1][1][3],
+ [list_item, ([compact_paragraph, reference, literal, "HelloWorldPrinter.print()"])])
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_document_toc(app):
+ app.build()
+ toctree = document_toc(app.env, 'index', app.builder.tags)
+
+ assert_node(toctree,
+ [bullet_list, ([list_item, (compact_paragraph, # [0][0]
+ [bullet_list, (addnodes.toctree, # [0][1][0]
+ list_item)])], # [0][1][1]
+ [list_item, (compact_paragraph, # [1][0]
+ [bullet_list, (addnodes.toctree,
+ addnodes.toctree)])],
+ [list_item, compact_paragraph])]) # [2][0]
+ assert_node(toctree[0][0],
+ [compact_paragraph, reference, "Welcome to Sphinx Tests’s documentation!"])
+ assert_node(toctree[0][1][1],
+ ([compact_paragraph, reference, "subsection"],
+ [bullet_list, list_item, compact_paragraph, reference, "subsubsection"]))
+ assert_node(toctree[1][0],
+ [compact_paragraph, reference, "Test for issue #1157"])
+ assert_node(toctree[2][0],
+ [compact_paragraph, reference, "Indices and tables"])
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_document_toc_only(app):
+ app.build()
+ builder = StandaloneHTMLBuilder(app, app.env)
+ toctree = document_toc(app.env, 'index', builder.tags)
+
+ assert_node(toctree,
+ [bullet_list, ([list_item, (compact_paragraph, # [0][0]
+ [bullet_list, (addnodes.toctree, # [0][1][0]
+ list_item, # [0][1][1]
+ list_item)])], # [0][1][2]
+ [list_item, (compact_paragraph, # [1][0]
+ [bullet_list, (addnodes.toctree,
+ addnodes.toctree)])],
+ [list_item, compact_paragraph])]) # [2][0]
+ assert_node(toctree[0][0],
+ [compact_paragraph, reference, "Welcome to Sphinx Tests’s documentation!"])
+ assert_node(toctree[0][1][1],
+ ([compact_paragraph, reference, "Section for HTML"],
+ [bullet_list, addnodes.toctree]))
+ assert_node(toctree[0][1][2],
+ ([compact_paragraph, reference, "subsection"],
+ [bullet_list, list_item, compact_paragraph, reference, "subsubsection"]))
+ assert_node(toctree[1][0],
+ [compact_paragraph, reference, "Test for issue #1157"])
+ assert_node(toctree[2][0],
+ [compact_paragraph, reference, "Indices and tables"])
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_document_toc_tocdepth(app):
+ app.build()
+ toctree = document_toc(app.env, 'tocdepth', app.builder.tags)
+
+ assert_node(toctree,
+ [bullet_list, list_item, (compact_paragraph, # [0][0]
+ bullet_list)]) # [0][1]
+ assert_node(toctree[0][0],
+ [compact_paragraph, reference, "level 1"])
+ assert_node(toctree[0][1],
+ [bullet_list, list_item, compact_paragraph, reference, "level 2"])
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_global_toctree_for_doc(app):
+ app.build()
+ toctree = global_toctree_for_doc(app.env, 'index', app.builder, collapse=False)
+ assert_node(toctree,
+ [compact_paragraph, ([title, "Table of Contents"],
+ bullet_list,
+ bullet_list,
+ bullet_list)])
+
+ assert_node(toctree[1],
+ ([list_item, ([compact_paragraph, reference, "foo"],
+ bullet_list)],
+ [list_item, compact_paragraph, reference, "bar"],
+ [list_item, compact_paragraph, reference, "https://sphinx-doc.org/"],
+ [list_item, compact_paragraph, reference,
+ "Welcome to Sphinx Tests’s documentation!"]))
+ assert_node(toctree[1][0][1],
+ ([list_item, compact_paragraph, reference, "quux"],
+ [list_item, compact_paragraph, reference, "foo.1"],
+ [list_item, compact_paragraph, reference, "foo.2"]))
+
+ assert_node(toctree[1][0][0][0], reference, refuri="foo", secnumber=[1])
+ assert_node(toctree[1][0][1][0][0][0], reference, refuri="quux", secnumber=[1, 1])
+ assert_node(toctree[1][0][1][1][0][0], reference, refuri="foo#foo-1", secnumber=[1, 2])
+ assert_node(toctree[1][0][1][2][0][0], reference, refuri="foo#foo-2", secnumber=[1, 3])
+ assert_node(toctree[1][1][0][0], reference, refuri="bar", secnumber=[2])
+ assert_node(toctree[1][2][0][0], reference, refuri="https://sphinx-doc.org/")
+ assert_node(toctree[1][3][0][0], reference, refuri="")
+
+ assert_node(toctree[2],
+ [bullet_list, list_item, compact_paragraph, reference, "baz"])
+ assert_node(toctree[3],
+ ([list_item, compact_paragraph, reference, "Latest reference"],
+ [list_item, compact_paragraph, reference, "Python"]))
+ assert_node(toctree[3][0][0][0], reference, refuri="https://sphinx-doc.org/latest/")
+ assert_node(toctree[3][1][0][0], reference, refuri="https://python.org/")
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_global_toctree_for_doc_collapse(app):
+ app.build()
+ toctree = global_toctree_for_doc(app.env, 'index', app.builder, collapse=True)
+ assert_node(toctree,
+ [compact_paragraph, ([title, "Table of Contents"],
+ bullet_list,
+ bullet_list,
+ bullet_list)])
+
+ assert_node(toctree[1],
+ ([list_item, compact_paragraph, reference, "foo"],
+ [list_item, compact_paragraph, reference, "bar"],
+ [list_item, compact_paragraph, reference, "https://sphinx-doc.org/"],
+ [list_item, compact_paragraph, reference,
+ "Welcome to Sphinx Tests’s documentation!"]))
+ assert_node(toctree[1][0][0][0], reference, refuri="foo", secnumber=[1])
+ assert_node(toctree[1][1][0][0], reference, refuri="bar", secnumber=[2])
+ assert_node(toctree[1][2][0][0], reference, refuri="https://sphinx-doc.org/")
+ assert_node(toctree[1][3][0][0], reference, refuri="")
+
+ assert_node(toctree[2],
+ [bullet_list, list_item, compact_paragraph, reference, "baz"])
+ assert_node(toctree[3],
+ ([list_item, compact_paragraph, reference, "Latest reference"],
+ [list_item, compact_paragraph, reference, "Python"]))
+ assert_node(toctree[3][0][0][0], reference, refuri="https://sphinx-doc.org/latest/")
+ assert_node(toctree[3][1][0][0], reference, refuri="https://python.org/")
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_global_toctree_for_doc_maxdepth(app):
+ app.build()
+ toctree = global_toctree_for_doc(app.env, 'index', app.builder,
+ collapse=False, maxdepth=3)
+ assert_node(toctree,
+ [compact_paragraph, ([title, "Table of Contents"],
+ bullet_list,
+ bullet_list,
+ bullet_list)])
+
+ assert_node(toctree[1],
+ ([list_item, ([compact_paragraph, reference, "foo"],
+ bullet_list)],
+ [list_item, compact_paragraph, reference, "bar"],
+ [list_item, compact_paragraph, reference, "https://sphinx-doc.org/"],
+ [list_item, compact_paragraph, reference,
+ "Welcome to Sphinx Tests’s documentation!"]))
+ assert_node(toctree[1][0][1],
+ ([list_item, compact_paragraph, reference, "quux"],
+ [list_item, ([compact_paragraph, reference, "foo.1"],
+ bullet_list)],
+ [list_item, compact_paragraph, reference, "foo.2"]))
+ assert_node(toctree[1][0][1][1][1],
+ [bullet_list, list_item, compact_paragraph, reference, "foo.1-1"])
+
+ assert_node(toctree[1][0][0][0], reference, refuri="foo", secnumber=[1])
+ assert_node(toctree[1][0][1][0][0][0], reference, refuri="quux", secnumber=[1, 1])
+ assert_node(toctree[1][0][1][1][0][0], reference, refuri="foo#foo-1", secnumber=[1, 2])
+ assert_node(toctree[1][0][1][1][1][0][0][0],
+ reference, refuri="foo#foo-1-1", secnumber=[1, 2, 1])
+ assert_node(toctree[1][0][1][2][0][0], reference, refuri="foo#foo-2", secnumber=[1, 3])
+ assert_node(toctree[1][1][0][0], reference, refuri="bar", secnumber=[2])
+ assert_node(toctree[1][2][0][0], reference, refuri="https://sphinx-doc.org/")
+ assert_node(toctree[1][3][0][0], reference, refuri="")
+
+ assert_node(toctree[2],
+ [bullet_list, list_item, compact_paragraph, reference, "baz"])
+ assert_node(toctree[3],
+ ([list_item, compact_paragraph, reference, "Latest reference"],
+ [list_item, compact_paragraph, reference, "Python"]))
+ assert_node(toctree[3][0][0][0], reference, refuri="https://sphinx-doc.org/latest/")
+ assert_node(toctree[3][1][0][0], reference, refuri="https://python.org/")
+
+
+@pytest.mark.sphinx('xml', testroot='toctree')
+@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
+def test_global_toctree_for_doc_includehidden(app):
+ app.build()
+ toctree = global_toctree_for_doc(app.env, 'index', app.builder,
+ collapse=False, includehidden=False)
+ assert_node(toctree,
+ [compact_paragraph, ([title, "Table of Contents"],
+ bullet_list,
+ bullet_list)])
+
+ assert_node(toctree[1],
+ ([list_item, ([compact_paragraph, reference, "foo"],
+ bullet_list)],
+ [list_item, compact_paragraph, reference, "bar"],
+ [list_item, compact_paragraph, reference, "https://sphinx-doc.org/"],
+ [list_item, compact_paragraph, reference,
+ "Welcome to Sphinx Tests’s documentation!"]))
+ assert_node(toctree[1][0][1],
+ ([list_item, compact_paragraph, reference, "quux"],
+ [list_item, compact_paragraph, reference, "foo.1"],
+ [list_item, compact_paragraph, reference, "foo.2"]))
+
+ assert_node(toctree[1][0][0][0], reference, refuri="foo", secnumber=[1])
+ assert_node(toctree[1][0][1][0][0][0], reference, refuri="quux", secnumber=[1, 1])
+ assert_node(toctree[1][0][1][1][0][0], reference, refuri="foo#foo-1", secnumber=[1, 2])
+ assert_node(toctree[1][0][1][2][0][0], reference, refuri="foo#foo-2", secnumber=[1, 3])
+ assert_node(toctree[1][1][0][0], reference, refuri="bar", secnumber=[2])
+ assert_node(toctree[1][2][0][0], reference, refuri="https://sphinx-doc.org/")
+
+ assert_node(toctree[2],
+ [bullet_list, list_item, compact_paragraph, reference, "baz"])
+
+
+@pytest.mark.sphinx('xml', testroot='toctree-index')
+def test_toctree_index(app):
+ app.build()
+ toctree = app.env.tocs['index']
+ assert_node(toctree,
+ [bullet_list, ([list_item, (compact_paragraph, # [0][0]
+ [bullet_list, (addnodes.toctree, # [0][1][0]
+ addnodes.toctree)])])]) # [0][1][1]
+ assert_node(toctree[0][1][1], addnodes.toctree,
+ caption="Indices", glob=False, hidden=False,
+ titlesonly=False, maxdepth=-1, numbered=0,
+ entries=[(None, 'genindex'), (None, 'modindex'), (None, 'search')])