Remove `flat_dict`

This commit is contained in:
Adam Turner 2024-01-18 01:16:49 +00:00
parent 0331bdec0e
commit 898e50c2c7
4 changed files with 615 additions and 667 deletions

View File

@ -34,10 +34,6 @@ HTML_WARNINGS = ENV_WARNINGS + """\
""" """
def flat_dict(d: dict[str, list[str]]):
return ((fname, value) for fname, values in d.items() for value in values)
def check_xpath(etree, fname, path, check, be_found=True): def check_xpath(etree, fname, path, check, be_found=True):
nodes = list(etree.findall(path)) nodes = list(etree.findall(path))
if check is None: if check is None:
@ -99,34 +95,31 @@ def test_html4_error(make_app, tmp_path):
) )
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check"), [
'index.html': [ ('index.html', ".//div[@class='citation']/span", r'Ref1'),
(".//div[@class='citation']/span", r'Ref1'), ('index.html', ".//div[@class='citation']/span", r'Ref_1'),
(".//div[@class='citation']/span", r'Ref_1'),
], ('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id9'][@id='id1']", r"1"),
'footnote.html': [ ('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id10'][@id='id2']", r"2"),
(".//a[@class='footnote-reference brackets'][@href='#id9'][@id='id1']", r"1"), ('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#foo'][@id='id3']", r"3"),
(".//a[@class='footnote-reference brackets'][@href='#id10'][@id='id2']", r"2"), ('footnote.html', ".//a[@class='reference internal'][@href='#bar'][@id='id4']/span", r"\[bar\]"),
(".//a[@class='footnote-reference brackets'][@href='#foo'][@id='id3']", r"3"), ('footnote.html', ".//a[@class='reference internal'][@href='#baz-qux'][@id='id5']/span", r"\[baz_qux\]"),
(".//a[@class='reference internal'][@href='#bar'][@id='id4']/span", r"\[bar\]"), ('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id11'][@id='id6']", r"4"),
(".//a[@class='reference internal'][@href='#baz-qux'][@id='id5']/span", r"\[baz_qux\]"), ('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id12'][@id='id7']", r"5"),
(".//a[@class='footnote-reference brackets'][@href='#id11'][@id='id6']", r"4"), ('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id1']", r"1"),
(".//a[@class='footnote-reference brackets'][@href='#id12'][@id='id7']", r"5"), ('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id2']", r"2"),
(".//aside[@class='footnote brackets']/span/a[@href='#id1']", r"1"), ('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id3']", r"3"),
(".//aside[@class='footnote brackets']/span/a[@href='#id2']", r"2"), ('footnote.html', ".//div[@class='citation']/span/a[@href='#id4']", r"bar"),
(".//aside[@class='footnote brackets']/span/a[@href='#id3']", r"3"), ('footnote.html', ".//div[@class='citation']/span/a[@href='#id5']", r"baz_qux"),
(".//div[@class='citation']/span/a[@href='#id4']", r"bar"), ('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id6']", r"4"),
(".//div[@class='citation']/span/a[@href='#id5']", r"baz_qux"), ('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id7']", r"5"),
(".//aside[@class='footnote brackets']/span/a[@href='#id6']", r"4"), ('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id8']", r"6"),
(".//aside[@class='footnote brackets']/span/a[@href='#id7']", r"5"), ])
(".//aside[@class='footnote brackets']/span/a[@href='#id8']", r"6"),
],
}))
@pytest.mark.sphinx('html') @pytest.mark.sphinx('html')
@pytest.mark.test_params(shared_result='test_build_html_output_docutils18') @pytest.mark.test_params(shared_result='test_build_html_output_docutils18')
def test_docutils_output(app, cached_etree_parse, fname, expect): def test_docutils_output(app, cached_etree_parse, fname, path, check):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check)
@pytest.mark.sphinx('html', parallel=2) @pytest.mark.sphinx('html', parallel=2)

View File

@ -4,7 +4,7 @@ import re
import pytest import pytest
from tests.test_builders.test_build_html import check_xpath, flat_dict from tests.test_builders.test_build_html import check_xpath
def tail_check(check): def tail_check(check):
@ -19,272 +19,257 @@ def tail_check(check):
return checker return checker
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check"), [
'images.html': [ ('images.html', ".//img[@src='_images/img.png']", ''),
(".//img[@src='_images/img.png']", ''), ('images.html', ".//img[@src='_images/img1.png']", ''),
(".//img[@src='_images/img1.png']", ''), ('images.html', ".//img[@src='_images/simg.png']", ''),
(".//img[@src='_images/simg.png']", ''), ('images.html', ".//img[@src='_images/svgimg.svg']", ''),
(".//img[@src='_images/svgimg.svg']", ''), ('images.html', ".//a[@href='_sources/images.txt']", ''),
(".//a[@href='_sources/images.txt']", ''),
], ('subdir/images.html', ".//img[@src='../_images/img1.png']", ''),
'subdir/images.html': [ ('subdir/images.html', ".//img[@src='../_images/rimg.png']", ''),
(".//img[@src='../_images/img1.png']", ''),
(".//img[@src='../_images/rimg.png']", ''), ('subdir/includes.html', ".//a[@class='reference download internal']", ''),
], ('subdir/includes.html', ".//img[@src='../_images/img.png']", ''),
'subdir/includes.html': [ ('subdir/includes.html', ".//p", 'This is an include file.'),
(".//a[@class='reference download internal']", ''), ('subdir/includes.html', ".//pre/span", 'line 1'),
(".//img[@src='../_images/img.png']", ''), ('subdir/includes.html', ".//pre/span", 'line 2'),
(".//p", 'This is an include file.'),
(".//pre/span", 'line 1'), ('includes.html', ".//pre", 'Max Strauß'),
(".//pre/span", 'line 2'), ('includes.html', ".//a[@class='reference download internal']", ''),
], ('includes.html', ".//pre/span", '"quotes"'),
'includes.html': [ ('includes.html', ".//pre/span", "'included'"),
(".//pre", 'Max Strauß'), ('includes.html', ".//pre/span[@class='s2']", 'üöä'),
(".//a[@class='reference download internal']", ''), ('includes.html', ".//div[@class='inc-pyobj1 highlight-text notranslate']//pre",
(".//pre/span", '"quotes"'), r'^class Foo:\n pass\n\s*$'),
(".//pre/span", "'included'"), ('includes.html', ".//div[@class='inc-pyobj2 highlight-text notranslate']//pre",
(".//pre/span[@class='s2']", 'üöä'), r'^ def baz\(\):\n pass\n\s*$'),
(".//div[@class='inc-pyobj1 highlight-text notranslate']//pre", ('includes.html', ".//div[@class='inc-lines highlight-text notranslate']//pre",
r'^class Foo:\n pass\n\s*$'), r'^class Foo:\n pass\nclass Bar:\n$'),
(".//div[@class='inc-pyobj2 highlight-text notranslate']//pre", ('includes.html', ".//div[@class='inc-startend highlight-text notranslate']//pre",
r'^ def baz\(\):\n pass\n\s*$'), '^foo = "Including Unicode characters: üöä"\\n$'),
(".//div[@class='inc-lines highlight-text notranslate']//pre", ('includes.html', ".//div[@class='inc-preappend highlight-text notranslate']//pre",
r'^class Foo:\n pass\nclass Bar:\n$'), r'(?m)^START CODE$'),
(".//div[@class='inc-startend highlight-text notranslate']//pre", ('includes.html', ".//div[@class='inc-pyobj-dedent highlight-python notranslate']//span",
'^foo = "Including Unicode characters: üöä"\\n$'), r'def'),
(".//div[@class='inc-preappend highlight-text notranslate']//pre", ('includes.html', ".//div[@class='inc-tab3 highlight-text notranslate']//pre",
r'(?m)^START CODE$'), r'-| |-'),
(".//div[@class='inc-pyobj-dedent highlight-python notranslate']//span", ('includes.html', ".//div[@class='inc-tab8 highlight-python notranslate']//pre/span",
r'def'), r'-| |-'),
(".//div[@class='inc-tab3 highlight-text notranslate']//pre",
r'-| |-'), ('autodoc.html', ".//dl[@class='py class']/dt[@id='autodoc_target.Class']", ''),
(".//div[@class='inc-tab8 highlight-python notranslate']//pre/span", ('autodoc.html', ".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span/span", r'\*\*'),
r'-| |-'), ('autodoc.html', ".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span/span", r'kwds'),
], ('autodoc.html', ".//dd/p", r'Return spam\.'),
'autodoc.html': [
(".//dl[@class='py class']/dt[@id='autodoc_target.Class']", ''), ('extapi.html', ".//strong", 'from class: Bar'),
(".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span/span", r'\*\*'),
(".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span/span", r'kwds'), ('markup.html', ".//title", 'set by title directive'),
(".//dd/p", r'Return spam\.'), ('markup.html', ".//p/em", 'Section author: Georg Brandl'),
], ('markup.html', ".//p/em", 'Module author: Georg Brandl'),
'extapi.html': [ # created by the meta directive
(".//strong", 'from class: Bar'), ('markup.html', ".//meta[@name='author'][@content='Me']", ''),
], ('markup.html', ".//meta[@name='keywords'][@content='docs, sphinx']", ''),
'markup.html': [ # a label created by ``.. _label:``
(".//title", 'set by title directive'), ('markup.html', ".//div[@id='label']", ''),
(".//p/em", 'Section author: Georg Brandl'), # code with standard code blocks
(".//p/em", 'Module author: Georg Brandl'), ('markup.html', ".//pre", '^some code$'),
# created by the meta directive # an option list
(".//meta[@name='author'][@content='Me']", ''), ('markup.html', ".//span[@class='option']", '--help'),
(".//meta[@name='keywords'][@content='docs, sphinx']", ''), # admonitions
# a label created by ``.. _label:`` ('markup.html', ".//p[@class='admonition-title']", 'My Admonition'),
(".//div[@id='label']", ''), ('markup.html', ".//div[@class='admonition note']/p", 'Note text.'),
# code with standard code blocks ('markup.html', ".//div[@class='admonition warning']/p", 'Warning text.'),
(".//pre", '^some code$'), # inline markup
# an option list ('markup.html', ".//li/p/strong", r'^command\\n$'),
(".//span[@class='option']", '--help'), ('markup.html', ".//li/p/strong", r'^program\\n$'),
# admonitions ('markup.html', ".//li/p/em", r'^dfn\\n$'),
(".//p[@class='admonition-title']", 'My Admonition'), ('markup.html', ".//li/p/kbd", r'^kbd\\n$'),
(".//div[@class='admonition note']/p", 'Note text.'), ('markup.html', ".//li/p/span", 'File \N{TRIANGULAR BULLET} Close'),
(".//div[@class='admonition warning']/p", 'Warning text.'), ('markup.html', ".//li/p/code/span[@class='pre']", '^a/$'),
# inline markup ('markup.html', ".//li/p/code/em/span[@class='pre']", '^varpart$'),
(".//li/p/strong", r'^command\\n$'), ('markup.html', ".//li/p/code/em/span[@class='pre']", '^i$'),
(".//li/p/strong", r'^program\\n$'), ('markup.html', ".//a[@href='https://peps.python.org/pep-0008/']"
(".//li/p/em", r'^dfn\\n$'), "[@class='pep reference external']/strong", 'PEP 8'),
(".//li/p/kbd", r'^kbd\\n$'), ('markup.html', ".//a[@href='https://peps.python.org/pep-0008/']"
(".//li/p/span", 'File \N{TRIANGULAR BULLET} Close'), "[@class='pep reference external']/strong",
(".//li/p/code/span[@class='pre']", '^a/$'), 'Python Enhancement Proposal #8'),
(".//li/p/code/em/span[@class='pre']", '^varpart$'), ('markup.html', ".//a[@href='https://datatracker.ietf.org/doc/html/rfc1.html']"
(".//li/p/code/em/span[@class='pre']", '^i$'), "[@class='rfc reference external']/strong", 'RFC 1'),
(".//a[@href='https://peps.python.org/pep-0008/']" ('markup.html', ".//a[@href='https://datatracker.ietf.org/doc/html/rfc1.html']"
"[@class='pep reference external']/strong", 'PEP 8'), "[@class='rfc reference external']/strong", 'Request for Comments #1'),
(".//a[@href='https://peps.python.org/pep-0008/']" ('markup.html', ".//a[@href='objects.html#envvar-HOME']"
"[@class='pep reference external']/strong", "[@class='reference internal']/code/span[@class='pre']", 'HOME'),
'Python Enhancement Proposal #8'), ('markup.html', ".//a[@href='#with']"
(".//a[@href='https://datatracker.ietf.org/doc/html/rfc1.html']" "[@class='reference internal']/code/span[@class='pre']", '^with$'),
"[@class='rfc reference external']/strong", 'RFC 1'), ('markup.html', ".//a[@href='#grammar-token-try_stmt']"
(".//a[@href='https://datatracker.ietf.org/doc/html/rfc1.html']" "[@class='reference internal']/code/span", '^statement$'),
"[@class='rfc reference external']/strong", 'Request for Comments #1'), ('markup.html', ".//a[@href='#some-label'][@class='reference internal']/span", '^here$'),
(".//a[@href='objects.html#envvar-HOME']" ('markup.html', ".//a[@href='#some-label'][@class='reference internal']/span", '^there$'),
"[@class='reference internal']/code/span[@class='pre']", 'HOME'), ('markup.html', ".//a[@href='subdir/includes.html']"
(".//a[@href='#with']" "[@class='reference internal']/span", 'Including in subdir'),
"[@class='reference internal']/code/span[@class='pre']", '^with$'), ('markup.html', ".//a[@href='objects.html#cmdoption-python-c']"
(".//a[@href='#grammar-token-try_stmt']" "[@class='reference internal']/code/span[@class='pre']", '-c'),
"[@class='reference internal']/code/span", '^statement$'), # abbreviations
(".//a[@href='#some-label'][@class='reference internal']/span", '^here$'), ('markup.html', ".//abbr[@title='abbreviation']", '^abbr$'),
(".//a[@href='#some-label'][@class='reference internal']/span", '^there$'), # version stuff
(".//a[@href='subdir/includes.html']" ('markup.html', ".//div[@class='versionadded']/p/span", 'New in version 0.6: '),
"[@class='reference internal']/span", 'Including in subdir'), ('markup.html', ".//div[@class='versionadded']/p/span",
(".//a[@href='objects.html#cmdoption-python-c']" tail_check('First paragraph of versionadded')),
"[@class='reference internal']/code/span[@class='pre']", '-c'), ('markup.html', ".//div[@class='versionchanged']/p/span",
# abbreviations tail_check('First paragraph of versionchanged')),
(".//abbr[@title='abbreviation']", '^abbr$'), ('markup.html', ".//div[@class='versionchanged']/p",
# version stuff 'Second paragraph of versionchanged'),
(".//div[@class='versionadded']/p/span", 'New in version 0.6: '), # footnote reference
(".//div[@class='versionadded']/p/span", ('markup.html', ".//a[@class='footnote-reference brackets']", r'1'),
tail_check('First paragraph of versionadded')), # created by reference lookup
(".//div[@class='versionchanged']/p/span", ('markup.html', ".//a[@href='index.html#ref1']", ''),
tail_check('First paragraph of versionchanged')), # ``seealso`` directive
(".//div[@class='versionchanged']/p", ('markup.html', ".//div/p[@class='admonition-title']", 'See also'),
'Second paragraph of versionchanged'), # a ``hlist`` directive
# footnote reference ('markup.html', ".//table[@class='hlist']/tbody/tr/td/ul/li/p", '^This$'),
(".//a[@class='footnote-reference brackets']", r'1'), # a ``centered`` directive
# created by reference lookup ('markup.html', ".//p[@class='centered']/strong", 'LICENSE'),
(".//a[@href='index.html#ref1']", ''), # a glossary
# ``seealso`` directive ('markup.html', ".//dl/dt[@id='term-boson']", 'boson'),
(".//div/p[@class='admonition-title']", 'See also'), ('markup.html', ".//dl/dt[@id='term-boson']/a", ''),
# a ``hlist`` directive # a production list
(".//table[@class='hlist']/tbody/tr/td/ul/li/p", '^This$'), ('markup.html', ".//pre/strong", 'try_stmt'),
# a ``centered`` directive ('markup.html', ".//pre/a[@href='#grammar-token-try1_stmt']/code/span", 'try1_stmt'),
(".//p[@class='centered']/strong", 'LICENSE'), # tests for ``only`` directive
# a glossary ('markup.html', ".//p", 'A global substitution!'),
(".//dl/dt[@id='term-boson']", 'boson'), ('markup.html', ".//p", 'In HTML.'),
(".//dl/dt[@id='term-boson']/a", ''), ('markup.html', ".//p", 'In both.'),
# a production list ('markup.html', ".//p", 'Always present'),
(".//pre/strong", 'try_stmt'), # tests for ``any`` role
(".//pre/a[@href='#grammar-token-try1_stmt']/code/span", 'try1_stmt'), ('markup.html', ".//a[@href='#with']/span", 'headings'),
# tests for ``only`` directive ('markup.html', ".//a[@href='objects.html#func_without_body']/code/span", 'objects'),
(".//p", 'A global substitution!'), # tests for numeric labels
(".//p", 'In HTML.'), ('markup.html', ".//a[@href='#id1'][@class='reference internal']/span", 'Testing various markup'),
(".//p", 'In both.'), # tests for smartypants
(".//p", 'Always present'), ('markup.html', ".//li/p", 'Smart “quotes” in English text.'),
# tests for ``any`` role ('markup.html', ".//li/p", 'Smart — long and short dashes.'),
(".//a[@href='#with']/span", 'headings'), ('markup.html', ".//li/p", 'Ellipsis…'),
(".//a[@href='objects.html#func_without_body']/code/span", 'objects'), ('markup.html', ".//li/p/code/span[@class='pre']", 'foo--"bar"...'),
# tests for numeric labels ('markup.html', ".//p", 'Этот «абзац» должен использовать „русские“ кавычки.'),
(".//a[@href='#id1'][@class='reference internal']/span", 'Testing various markup'), ('markup.html', ".//p", 'Il dit : « Cest “super” ! »'),
# tests for smartypants
(".//li/p", 'Smart “quotes” in English text.'), ('objects.html', ".//dt[@id='mod.Cls.meth1']", ''),
(".//li/p", 'Smart — long and short dashes.'), ('objects.html', ".//dt[@id='errmod.Error']", ''),
(".//li/p", 'Ellipsis…'), ('objects.html', ".//dt/span[@class='sig-name descname']/span[@class='pre']", r'long\(parameter,'),
(".//li/p/code/span[@class='pre']", 'foo--"bar"...'), ('objects.html', ".//dt/span[@class='sig-name descname']/span[@class='pre']", r'list\)'),
(".//p", 'Этот «абзац» должен использовать „русские“ кавычки.'), ('objects.html', ".//dt/span[@class='sig-name descname']/span[@class='pre']", 'another'),
(".//p", 'Il dit : « Cest “super” ! »'), ('objects.html', ".//dt/span[@class='sig-name descname']/span[@class='pre']", 'one'),
], ('objects.html', ".//a[@href='#mod.Cls'][@class='reference internal']", ''),
'objects.html': [ ('objects.html', ".//dl[@class='std userdesc']", ''),
(".//dt[@id='mod.Cls.meth1']", ''), ('objects.html', ".//dt[@id='userdesc-myobj']", ''),
(".//dt[@id='errmod.Error']", ''), ('objects.html', ".//a[@href='#userdesc-myobj'][@class='reference internal']", ''),
(".//dt/span[@class='sig-name descname']/span[@class='pre']", r'long\(parameter,'), # docfields
(".//dt/span[@class='sig-name descname']/span[@class='pre']", r'list\)'), ('objects.html', ".//a[@class='reference internal'][@href='#TimeInt']/em", 'TimeInt'),
(".//dt/span[@class='sig-name descname']/span[@class='pre']", 'another'), ('objects.html', ".//a[@class='reference internal'][@href='#Time']", 'Time'),
(".//dt/span[@class='sig-name descname']/span[@class='pre']", 'one'), ('objects.html', ".//a[@class='reference internal'][@href='#errmod.Error']/strong", 'Error'),
(".//a[@href='#mod.Cls'][@class='reference internal']", ''), # C references
(".//dl[@class='std userdesc']", ''), ('objects.html', ".//span[@class='pre']", 'CFunction()'),
(".//dt[@id='userdesc-myobj']", ''), ('objects.html', ".//a[@href='#c.Sphinx_DoSomething']", ''),
(".//a[@href='#userdesc-myobj'][@class='reference internal']", ''), ('objects.html', ".//a[@href='#c.SphinxStruct.member']", ''),
# docfields ('objects.html', ".//a[@href='#c.SPHINX_USE_PYTHON']", ''),
(".//a[@class='reference internal'][@href='#TimeInt']/em", 'TimeInt'), ('objects.html', ".//a[@href='#c.SphinxType']", ''),
(".//a[@class='reference internal'][@href='#Time']", 'Time'), ('objects.html', ".//a[@href='#c.sphinx_global']", ''),
(".//a[@class='reference internal'][@href='#errmod.Error']/strong", 'Error'), # test global TOC created by toctree()
# C references ('objects.html', ".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='#']",
(".//span[@class='pre']", 'CFunction()'), 'Testing object descriptions'),
(".//a[@href='#c.Sphinx_DoSomething']", ''), ('objects.html', ".//li[@class='toctree-l1']/a[@href='markup.html']",
(".//a[@href='#c.SphinxStruct.member']", ''), 'Testing various markup'),
(".//a[@href='#c.SPHINX_USE_PYTHON']", ''), # test unknown field names
(".//a[@href='#c.SphinxType']", ''), ('objects.html', ".//dt[@class='field-odd']", 'Field_name'),
(".//a[@href='#c.sphinx_global']", ''), ('objects.html', ".//dt[@class='field-even']", 'Field_name all lower'),
# test global TOC created by toctree() ('objects.html', ".//dt[@class='field-odd']", 'FIELD_NAME'),
(".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='#']", ('objects.html', ".//dt[@class='field-even']", 'FIELD_NAME ALL CAPS'),
'Testing object descriptions'), ('objects.html', ".//dt[@class='field-odd']", 'Field_Name'),
(".//li[@class='toctree-l1']/a[@href='markup.html']", ('objects.html', ".//dt[@class='field-even']", 'Field_Name All Word Caps'),
'Testing various markup'), # ('objects.html', ".//dt[@class='field-odd']", 'Field_name'), (duplicate)
# test unknown field names ('objects.html', ".//dt[@class='field-even']", 'Field_name First word cap'),
(".//dt[@class='field-odd']", 'Field_name'), ('objects.html', ".//dt[@class='field-odd']", 'FIELd_name'),
(".//dt[@class='field-even']", 'Field_name all lower'), ('objects.html', ".//dt[@class='field-even']", 'FIELd_name PARTial caps'),
(".//dt[@class='field-odd']", 'FIELD_NAME'), # custom sidebar
(".//dt[@class='field-even']", 'FIELD_NAME ALL CAPS'), ('objects.html', ".//h4", 'Custom sidebar'),
(".//dt[@class='field-odd']", 'Field_Name'), # docfields
(".//dt[@class='field-even']", 'Field_Name All Word Caps'), ('objects.html', ".//dd[@class='field-odd']/p/strong", '^moo$'),
(".//dt[@class='field-odd']", 'Field_name'), ('objects.html', ".//dd[@class='field-odd']/p/strong", tail_check(r'\(Moo\) .* Moo')),
(".//dt[@class='field-even']", 'Field_name First word cap'), ('objects.html', ".//dd[@class='field-odd']/ul/li/p/strong", '^hour$'),
(".//dt[@class='field-odd']", 'FIELd_name'), ('objects.html', ".//dd[@class='field-odd']/ul/li/p/em", '^DuplicateType$'),
(".//dt[@class='field-even']", 'FIELd_name PARTial caps'), ('objects.html', ".//dd[@class='field-odd']/ul/li/p/em", tail_check(r'.* Some parameter')),
# custom sidebar # others
(".//h4", 'Custom sidebar'), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span",
# docfields 'perl'),
(".//dd[@class='field-odd']/p/strong", '^moo$'), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span",
(".//dd[@class='field-odd']/p/strong", tail_check(r'\(Moo\) .* Moo')), '\\+p'),
(".//dd[@class='field-odd']/ul/li/p/strong", '^hour$'), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-ObjC']/code/span",
(".//dd[@class='field-odd']/ul/li/p/em", '^DuplicateType$'), '--ObjC\\+\\+'),
(".//dd[@class='field-odd']/ul/li/p/em", tail_check(r'.* Some parameter')), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-plugin.option']/code/span",
# others '--plugin.option'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span", ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-arg-create-auth-token']"
'perl'), "/code/span",
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span", 'create-auth-token'),
'\\+p'), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-arg-arg']/code/span",
(".//a[@class='reference internal'][@href='#cmdoption-perl-ObjC']/code/span", 'arg'),
'--ObjC\\+\\+'), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-perl-j']/code/span",
(".//a[@class='reference internal'][@href='#cmdoption-perl-plugin.option']/code/span", '-j'),
'--plugin.option'), ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-create-auth-token']" 'hg'),
"/code/span", ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
'create-auth-token'), 'commit'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-arg']/code/span", ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
'arg'), 'git'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-j']/code/span", ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
'-j'), 'commit'),
(".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span", ('objects.html', ".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
'hg'), '-p'),
(".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
'commit'), ('index.html', ".//meta[@name='hc'][@content='hcval']", ''),
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span", ('index.html', ".//meta[@name='hc_co'][@content='hcval_co']", ''),
'git'), ('index.html', ".//li[@class='toctree-l1']/a", 'Testing various markup'),
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span", ('index.html', ".//li[@class='toctree-l2']/a", 'Inline markup'),
'commit'), ('index.html', ".//title", 'Sphinx <Tests>'),
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span", ('index.html', ".//div[@class='footer']", 'copyright text credits'),
'-p'), ('index.html', ".//a[@href='https://python.org/']"
], "[@class='reference external']", ''),
'index.html': [ ('index.html', ".//li/p/a[@href='genindex.html']/span", 'Index'),
(".//meta[@name='hc'][@content='hcval']", ''), ('index.html', ".//li/p/a[@href='py-modindex.html']/span", 'Module Index'),
(".//meta[@name='hc_co'][@content='hcval_co']", ''), # custom sidebar only for contents
(".//li[@class='toctree-l1']/a", 'Testing various markup'), ('index.html', ".//h4", 'Contents sidebar'),
(".//li[@class='toctree-l2']/a", 'Inline markup'), # custom JavaScript
(".//title", 'Sphinx <Tests>'), ('index.html', ".//script[@src='file://moo.js']", ''),
(".//div[@class='footer']", 'copyright text credits'), # URL in contents
(".//a[@href='https://python.org/']" ('index.html', ".//a[@class='reference external'][@href='https://sphinx-doc.org/']",
"[@class='reference external']", ''), 'https://sphinx-doc.org/'),
(".//li/p/a[@href='genindex.html']/span", 'Index'), ('index.html', ".//a[@class='reference external'][@href='https://sphinx-doc.org/latest/']",
(".//li/p/a[@href='py-modindex.html']/span", 'Module Index'), 'Latest reference'),
# custom sidebar only for contents # Indirect hyperlink targets across files
(".//h4", 'Contents sidebar'), ('index.html', ".//a[@href='markup.html#some-label'][@class='reference internal']/span",
# custom JavaScript '^indirect hyperref$'),
(".//script[@src='file://moo.js']", ''),
# URL in contents ('bom.html', ".//title", " File with UTF-8 BOM"),
(".//a[@class='reference external'][@href='https://sphinx-doc.org/']",
'https://sphinx-doc.org/'), ('extensions.html', ".//a[@href='https://python.org/dev/']", "https://python.org/dev/"),
(".//a[@class='reference external'][@href='https://sphinx-doc.org/latest/']", ('extensions.html', ".//a[@href='https://bugs.python.org/issue1000']", "issue 1000"),
'Latest reference'), ('extensions.html', ".//a[@href='https://bugs.python.org/issue1042']", "explicit caption"),
# Indirect hyperlink targets across files
(".//a[@href='markup.html#some-label'][@class='reference internal']/span", # index entries
'^indirect hyperref$'), ('genindex.html', ".//a/strong", "Main"),
], ('genindex.html', ".//a/strong", "[1]"),
'bom.html': [ ('genindex.html', ".//a/strong", "Other"),
(".//title", " File with UTF-8 BOM"), ('genindex.html', ".//a", "entry"),
], ('genindex.html', ".//li/a", "double"),
'extensions.html': [
(".//a[@href='https://python.org/dev/']", "https://python.org/dev/"), ('otherext.html', ".//h1", "Generated section"),
(".//a[@href='https://bugs.python.org/issue1000']", "issue 1000"), ('otherext.html', ".//a[@href='_sources/otherext.foo.txt']", ''),
(".//a[@href='https://bugs.python.org/issue1042']", "explicit caption"),
], ('search.html', ".//meta[@name='robots'][@content='noindex']", ''),
'genindex.html': [ ])
# index entries
(".//a/strong", "Main"),
(".//a/strong", "[1]"),
(".//a/strong", "Other"),
(".//a", "entry"),
(".//li/a", "double"),
],
'otherext.html': [
(".//h1", "Generated section"),
(".//a[@href='_sources/otherext.foo.txt']", ''),
],
'search.html': [
(".//meta[@name='robots'][@content='noindex']", ''),
],
}))
@pytest.mark.sphinx('html', tags=['testtag'], @pytest.mark.sphinx('html', tags=['testtag'],
confoverrides={'html_context.hckey_co': 'hcval_co'}) confoverrides={'html_context.hckey_co': 'hcval_co'})
@pytest.mark.test_params(shared_result='test_build_html_output') @pytest.mark.test_params(shared_result='test_build_html_output')
def test_html5_output(app, cached_etree_parse, fname, expect): def test_html5_output(app, cached_etree_parse, fname, path, check):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check)

View File

@ -5,7 +5,7 @@ import re
import pytest import pytest
from tests.test_builders.test_build_html import FIGURE_CAPTION, check_xpath, flat_dict from tests.test_builders.test_build_html import FIGURE_CAPTION, check_xpath
@pytest.mark.sphinx('html', testroot='numfig') @pytest.mark.sphinx('html', testroot='numfig')
@ -18,47 +18,42 @@ def test_numfig_disabled_warn(app, warning):
assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' not in warnings assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' not in warnings
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
'index.html': [ ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", None, True),
(FIGURE_CAPTION + "/span[@class='caption-number']", None, True), ('index.html', ".//table/caption/span[@class='caption-number']", None, True),
(".//table/caption/span[@class='caption-number']", None, True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", None, True),
"span[@class='caption-number']", None, True), ('index.html', ".//li/p/code/span", '^fig1$', True),
(".//li/p/code/span", '^fig1$', True), ('index.html', ".//li/p/code/span", '^Figure%s$', True),
(".//li/p/code/span", '^Figure%s$', True), ('index.html', ".//li/p/code/span", '^table-1$', True),
(".//li/p/code/span", '^table-1$', True), ('index.html', ".//li/p/code/span", '^Table:%s$', True),
(".//li/p/code/span", '^Table:%s$', True), ('index.html', ".//li/p/code/span", '^CODE_1$', True),
(".//li/p/code/span", '^CODE_1$', True), ('index.html', ".//li/p/code/span", '^Code-%s$', True),
(".//li/p/code/span", '^Code-%s$', True), ('index.html', ".//li/p/a/span", '^Section 1$', True),
(".//li/p/a/span", '^Section 1$', True), ('index.html', ".//li/p/a/span", '^Section 2.1$', True),
(".//li/p/a/span", '^Section 2.1$', True), ('index.html', ".//li/p/code/span", '^Fig.{number}$', True),
(".//li/p/code/span", '^Fig.{number}$', True), ('index.html', ".//li/p/a/span", '^Sect.1 Foo$', True),
(".//li/p/a/span", '^Sect.1 Foo$', True),
], ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", None, True),
'foo.html': [ ('foo.html', ".//table/caption/span[@class='caption-number']", None, True),
(FIGURE_CAPTION + "/span[@class='caption-number']", None, True), ('foo.html', ".//div[@class='code-block-caption']/"
(".//table/caption/span[@class='caption-number']", None, True), "span[@class='caption-number']", None, True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", None, True), ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", None, True),
], ('bar.html', ".//table/caption/span[@class='caption-number']", None, True),
'bar.html': [ ('bar.html', ".//div[@class='code-block-caption']/"
(FIGURE_CAPTION + "/span[@class='caption-number']", None, True), "span[@class='caption-number']", None, True),
(".//table/caption/span[@class='caption-number']", None, True),
(".//div[@class='code-block-caption']/" ('baz.html', FIGURE_CAPTION + "/span[@class='caption-number']", None, True),
"span[@class='caption-number']", None, True), ('baz.html', ".//table/caption/span[@class='caption-number']", None, True),
], ('baz.html', ".//div[@class='code-block-caption']/"
'baz.html': [ "span[@class='caption-number']", None, True),
(FIGURE_CAPTION + "/span[@class='caption-number']", None, True), ])
(".//table/caption/span[@class='caption-number']", None, True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", None, True),
],
}))
@pytest.mark.sphinx('html', testroot='numfig') @pytest.mark.sphinx('html', testroot='numfig')
@pytest.mark.test_params(shared_result='test_build_html_numfig') @pytest.mark.test_params(shared_result='test_build_html_numfig')
def test_numfig_disabled(app, cached_etree_parse, fname, expect): def test_numfig_disabled(app, cached_etree_parse, fname, path, check, be_found):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)
@pytest.mark.sphinx( @pytest.mark.sphinx(
@ -80,81 +75,76 @@ def test_numfig_without_numbered_toctree_warn(app, warning):
assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
'index.html': [ ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 9 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 9 $', True), ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 10 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 10 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 9 $', True),
'^Table 9 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 10 $', True),
'^Table 10 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 9 $', True),
"span[@class='caption-number']", '^Listing 9 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 10 $', True),
"span[@class='caption-number']", '^Listing 10 $', True), ('index.html', ".//li/p/a/span", '^Fig. 9$', True),
(".//li/p/a/span", '^Fig. 9$', True), ('index.html', ".//li/p/a/span", '^Figure6$', True),
(".//li/p/a/span", '^Figure6$', True), ('index.html', ".//li/p/a/span", '^Table 9$', True),
(".//li/p/a/span", '^Table 9$', True), ('index.html', ".//li/p/a/span", '^Table:6$', True),
(".//li/p/a/span", '^Table:6$', True), ('index.html', ".//li/p/a/span", '^Listing 9$', True),
(".//li/p/a/span", '^Listing 9$', True), ('index.html', ".//li/p/a/span", '^Code-6$', True),
(".//li/p/a/span", '^Code-6$', True), ('index.html', ".//li/p/code/span", '^foo$', True),
(".//li/p/code/span", '^foo$', True), ('index.html', ".//li/p/code/span", '^bar_a$', True),
(".//li/p/code/span", '^bar_a$', True), ('index.html', ".//li/p/a/span", '^Fig.9 should be Fig.1$', True),
(".//li/p/a/span", '^Fig.9 should be Fig.1$', True), ('index.html', ".//li/p/code/span", '^Sect.{number}$', True),
(".//li/p/code/span", '^Sect.{number}$', True),
], ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True),
'foo.html': [ ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 3 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 4 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 3 $', True), ('foo.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 4 $', True), '^Table 1 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1 $', True), '^Table 2 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 2 $', True), '^Table 3 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 3 $', True), '^Table 4 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//div[@class='code-block-caption']/"
'^Table 4 $', True), "span[@class='caption-number']", '^Listing 1 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1 $', True), "span[@class='caption-number']", '^Listing 2 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 2 $', True), "span[@class='caption-number']", '^Listing 3 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 3 $', True), "span[@class='caption-number']", '^Listing 4 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 4 $', True), ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 5 $', True),
], ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 7 $', True),
'bar.html': [ ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 8 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 5 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 7 $', True), '^Table 5 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 8 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 7 $', True),
'^Table 5 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 8 $', True),
'^Table 7 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//table/caption/span[@class='caption-number']", "span[@class='caption-number']", '^Listing 5 $', True),
'^Table 8 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 7 $', True),
"span[@class='caption-number']", '^Listing 5 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 8 $', True),
"span[@class='caption-number']", '^Listing 7 $', True),
(".//div[@class='code-block-caption']/" ('baz.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 6 $', True),
"span[@class='caption-number']", '^Listing 8 $', True), ('baz.html', ".//table/caption/span[@class='caption-number']",
], '^Table 6 $', True),
'baz.html': [ ('baz.html', ".//div[@class='code-block-caption']/"
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 6 $', True), "span[@class='caption-number']", '^Listing 6 $', True),
(".//table/caption/span[@class='caption-number']", ])
'^Table 6 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 6 $', True),
],
}))
@pytest.mark.sphinx( @pytest.mark.sphinx(
'html', testroot='numfig', 'html', testroot='numfig',
srcdir='test_numfig_without_numbered_toctree', srcdir='test_numfig_without_numbered_toctree',
confoverrides={'numfig': True}) confoverrides={'numfig': True})
def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect): def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, path, check, be_found):
# remove :numbered: option # remove :numbered: option
index = (app.srcdir / 'index.rst').read_text(encoding='utf8') index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
index = re.sub(':numbered:.*', '', index) index = re.sub(':numbered:.*', '', index)
@ -162,7 +152,7 @@ def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect)
if not os.listdir(app.outdir): if not os.listdir(app.outdir):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)
@pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True}) @pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True})
@ -176,81 +166,76 @@ def test_numfig_with_numbered_toctree_warn(app, warning):
assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
'index.html': [ ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True), ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 1 $', True),
'^Table 1 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 2 $', True),
'^Table 2 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 1 $', True),
"span[@class='caption-number']", '^Listing 1 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 2 $', True),
"span[@class='caption-number']", '^Listing 2 $', True), ('index.html', ".//li/p/a/span", '^Fig. 1$', True),
(".//li/p/a/span", '^Fig. 1$', True), ('index.html', ".//li/p/a/span", '^Figure2.2$', True),
(".//li/p/a/span", '^Figure2.2$', True), ('index.html', ".//li/p/a/span", '^Table 1$', True),
(".//li/p/a/span", '^Table 1$', True), ('index.html', ".//li/p/a/span", '^Table:2.2$', True),
(".//li/p/a/span", '^Table:2.2$', True), ('index.html', ".//li/p/a/span", '^Listing 1$', True),
(".//li/p/a/span", '^Listing 1$', True), ('index.html', ".//li/p/a/span", '^Code-2.2$', True),
(".//li/p/a/span", '^Code-2.2$', True), ('index.html', ".//li/p/a/span", '^Section.1$', True),
(".//li/p/a/span", '^Section.1$', True), ('index.html', ".//li/p/a/span", '^Section.2.1$', True),
(".//li/p/a/span", '^Section.2.1$', True), ('index.html', ".//li/p/a/span", '^Fig.1 should be Fig.1$', True),
(".//li/p/a/span", '^Fig.1 should be Fig.1$', True), ('index.html', ".//li/p/a/span", '^Sect.1 Foo$', True),
(".//li/p/a/span", '^Sect.1 Foo$', True),
], ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1 $', True),
'foo.html': [ ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.3 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.2 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.4 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.3 $', True), ('foo.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.4 $', True), '^Table 1.1 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1.1 $', True), '^Table 1.2 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1.2 $', True), '^Table 1.3 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1.3 $', True), '^Table 1.4 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//div[@class='code-block-caption']/"
'^Table 1.4 $', True), "span[@class='caption-number']", '^Listing 1.1 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.1 $', True), "span[@class='caption-number']", '^Listing 1.2 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.2 $', True), "span[@class='caption-number']", '^Listing 1.3 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.3 $', True), "span[@class='caption-number']", '^Listing 1.4 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.4 $', True), ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1 $', True),
], ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.3 $', True),
'bar.html': [ ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.4 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.3 $', True), '^Table 2.1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.4 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 2.3 $', True),
'^Table 2.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 2.4 $', True),
'^Table 2.3 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//table/caption/span[@class='caption-number']", "span[@class='caption-number']", '^Listing 2.1 $', True),
'^Table 2.4 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 2.3 $', True),
"span[@class='caption-number']", '^Listing 2.1 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 2.4 $', True),
"span[@class='caption-number']", '^Listing 2.3 $', True),
(".//div[@class='code-block-caption']/" ('baz.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.2 $', True),
"span[@class='caption-number']", '^Listing 2.4 $', True), ('baz.html', ".//table/caption/span[@class='caption-number']",
], '^Table 2.2 $', True),
'baz.html': [ ('baz.html', ".//div[@class='code-block-caption']/"
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.2 $', True), "span[@class='caption-number']", '^Listing 2.2 $', True),
(".//table/caption/span[@class='caption-number']", ])
'^Table 2.2 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 2.2 $', True),
],
}))
@pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True}) @pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True})
@pytest.mark.test_params(shared_result='test_build_html_numfig_on') @pytest.mark.test_params(shared_result='test_build_html_numfig_on')
def test_numfig_with_numbered_toctree(app, cached_etree_parse, fname, expect): def test_numfig_with_numbered_toctree(app, cached_etree_parse, fname, path, check, be_found):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)
@pytest.mark.sphinx('html', testroot='numfig', confoverrides={ @pytest.mark.sphinx('html', testroot='numfig', confoverrides={
@ -269,76 +254,71 @@ def test_numfig_with_prefix_warn(app, warning):
assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
'index.html': [ ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1 $', True), ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Tab_1 $', True),
'^Tab_1 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Tab_2 $', True),
'^Tab_2 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Code-1 $', True),
"span[@class='caption-number']", '^Code-1 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Code-2 $', True),
"span[@class='caption-number']", '^Code-2 $', True), ('index.html', ".//li/p/a/span", '^Figure:1$', True),
(".//li/p/a/span", '^Figure:1$', True), ('index.html', ".//li/p/a/span", '^Figure2.2$', True),
(".//li/p/a/span", '^Figure2.2$', True), ('index.html', ".//li/p/a/span", '^Tab_1$', True),
(".//li/p/a/span", '^Tab_1$', True), ('index.html', ".//li/p/a/span", '^Table:2.2$', True),
(".//li/p/a/span", '^Table:2.2$', True), ('index.html', ".//li/p/a/span", '^Code-1$', True),
(".//li/p/a/span", '^Code-1$', True), ('index.html', ".//li/p/a/span", '^Code-2.2$', True),
(".//li/p/a/span", '^Code-2.2$', True), ('index.html', ".//li/p/a/span", '^SECTION-1$', True),
(".//li/p/a/span", '^SECTION-1$', True), ('index.html', ".//li/p/a/span", '^SECTION-2.1$', True),
(".//li/p/a/span", '^SECTION-2.1$', True), ('index.html', ".//li/p/a/span", '^Fig.1 should be Fig.1$', True),
(".//li/p/a/span", '^Fig.1 should be Fig.1$', True), ('index.html', ".//li/p/a/span", '^Sect.1 Foo$', True),
(".//li/p/a/span", '^Sect.1 Foo$', True),
], ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.1 $', True),
'foo.html': [ ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.1 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.3 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.2 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.4 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.3 $', True), ('foo.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:1.4 $', True), '^Tab_1.1 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Tab_1.1 $', True), '^Tab_1.2 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Tab_1.2 $', True), '^Tab_1.3 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Tab_1.3 $', True), '^Tab_1.4 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//div[@class='code-block-caption']/"
'^Tab_1.4 $', True), "span[@class='caption-number']", '^Code-1.1 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Code-1.1 $', True), "span[@class='caption-number']", '^Code-1.2 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Code-1.2 $', True), "span[@class='caption-number']", '^Code-1.3 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Code-1.3 $', True), "span[@class='caption-number']", '^Code-1.4 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Code-1.4 $', True), ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.1 $', True),
], ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.3 $', True),
'bar.html': [ ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.4 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.3 $', True), '^Tab_2.1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.4 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Tab_2.3 $', True),
'^Tab_2.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Tab_2.4 $', True),
'^Tab_2.3 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//table/caption/span[@class='caption-number']", "span[@class='caption-number']", '^Code-2.1 $', True),
'^Tab_2.4 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Code-2.3 $', True),
"span[@class='caption-number']", '^Code-2.1 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Code-2.4 $', True),
"span[@class='caption-number']", '^Code-2.3 $', True),
(".//div[@class='code-block-caption']/" ('baz.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.2 $', True),
"span[@class='caption-number']", '^Code-2.4 $', True), ('baz.html', ".//table/caption/span[@class='caption-number']",
], '^Tab_2.2 $', True),
'baz.html': [ ('baz.html', ".//div[@class='code-block-caption']/"
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Figure:2.2 $', True), "span[@class='caption-number']", '^Code-2.2 $', True),
(".//table/caption/span[@class='caption-number']", ])
'^Tab_2.2 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Code-2.2 $', True),
],
}))
@pytest.mark.sphinx('html', testroot='numfig', @pytest.mark.sphinx('html', testroot='numfig',
confoverrides={'numfig': True, confoverrides={'numfig': True,
'numfig_format': {'figure': 'Figure:%s', 'numfig_format': {'figure': 'Figure:%s',
@ -346,9 +326,9 @@ def test_numfig_with_prefix_warn(app, warning):
'code-block': 'Code-%s', 'code-block': 'Code-%s',
'section': 'SECTION-%s'}}) 'section': 'SECTION-%s'}})
@pytest.mark.test_params(shared_result='test_build_html_numfig_format_warn') @pytest.mark.test_params(shared_result='test_build_html_numfig_format_warn')
def test_numfig_with_prefix(app, cached_etree_parse, fname, expect): def test_numfig_with_prefix(app, cached_etree_parse, fname, path, check, be_found):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)
@pytest.mark.sphinx('html', testroot='numfig', @pytest.mark.sphinx('html', testroot='numfig',
@ -363,83 +343,78 @@ def test_numfig_with_secnum_depth_warn(app, warning):
assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings assert 'index.rst:57: WARNING: invalid numfig_format: Fig %s %s' in warnings
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
'index.html': [ ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True), ('index.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 1 $', True),
'^Table 1 $', True), ('index.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 2 $', True),
'^Table 2 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 1 $', True),
"span[@class='caption-number']", '^Listing 1 $', True), ('index.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 2 $', True),
"span[@class='caption-number']", '^Listing 2 $', True), ('index.html', ".//li/p/a/span", '^Fig. 1$', True),
(".//li/p/a/span", '^Fig. 1$', True), ('index.html', ".//li/p/a/span", '^Figure2.1.2$', True),
(".//li/p/a/span", '^Figure2.1.2$', True), ('index.html', ".//li/p/a/span", '^Table 1$', True),
(".//li/p/a/span", '^Table 1$', True), ('index.html', ".//li/p/a/span", '^Table:2.1.2$', True),
(".//li/p/a/span", '^Table:2.1.2$', True), ('index.html', ".//li/p/a/span", '^Listing 1$', True),
(".//li/p/a/span", '^Listing 1$', True), ('index.html', ".//li/p/a/span", '^Code-2.1.2$', True),
(".//li/p/a/span", '^Code-2.1.2$', True), ('index.html', ".//li/p/a/span", '^Section.1$', True),
(".//li/p/a/span", '^Section.1$', True), ('index.html', ".//li/p/a/span", '^Section.2.1$', True),
(".//li/p/a/span", '^Section.2.1$', True), ('index.html', ".//li/p/a/span", '^Fig.1 should be Fig.1$', True),
(".//li/p/a/span", '^Fig.1 should be Fig.1$', True), ('index.html', ".//li/p/a/span", '^Sect.1 Foo$', True),
(".//li/p/a/span", '^Sect.1 Foo$', True),
], ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1 $', True),
'foo.html': [ ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1.1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1.2 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1.1 $', True), ('foo.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.2.1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.1.2 $', True), ('foo.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1.2.1 $', True), '^Table 1.1 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1.1 $', True), '^Table 1.1.1 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1.1.1 $', True), '^Table 1.1.2 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//table/caption/span[@class='caption-number']",
'^Table 1.1.2 $', True), '^Table 1.2.1 $', True),
(".//table/caption/span[@class='caption-number']", ('foo.html', ".//div[@class='code-block-caption']/"
'^Table 1.2.1 $', True), "span[@class='caption-number']", '^Listing 1.1 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.1 $', True), "span[@class='caption-number']", '^Listing 1.1.1 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.1.1 $', True), "span[@class='caption-number']", '^Listing 1.1.2 $', True),
(".//div[@class='code-block-caption']/" ('foo.html', ".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.1.2 $', True), "span[@class='caption-number']", '^Listing 1.2.1 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 1.2.1 $', True), ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1.1 $', True),
], ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1.3 $', True),
'bar.html': [ ('bar.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.2.1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1.3 $', True), '^Table 2.1.1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.2.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 2.1.3 $', True),
'^Table 2.1.1 $', True), ('bar.html', ".//table/caption/span[@class='caption-number']",
(".//table/caption/span[@class='caption-number']", '^Table 2.2.1 $', True),
'^Table 2.1.3 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//table/caption/span[@class='caption-number']", "span[@class='caption-number']", '^Listing 2.1.1 $', True),
'^Table 2.2.1 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 2.1.3 $', True),
"span[@class='caption-number']", '^Listing 2.1.1 $', True), ('bar.html', ".//div[@class='code-block-caption']/"
(".//div[@class='code-block-caption']/" "span[@class='caption-number']", '^Listing 2.2.1 $', True),
"span[@class='caption-number']", '^Listing 2.1.3 $', True),
(".//div[@class='code-block-caption']/" ('baz.html', FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1.2 $', True),
"span[@class='caption-number']", '^Listing 2.2.1 $', True), ('baz.html', ".//table/caption/span[@class='caption-number']",
], '^Table 2.1.2 $', True),
'baz.html': [ ('baz.html', ".//div[@class='code-block-caption']/"
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2.1.2 $', True), "span[@class='caption-number']", '^Listing 2.1.2 $', True),
(".//table/caption/span[@class='caption-number']", ])
'^Table 2.1.2 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 2.1.2 $', True),
],
}))
@pytest.mark.sphinx('html', testroot='numfig', @pytest.mark.sphinx('html', testroot='numfig',
confoverrides={'numfig': True, confoverrides={'numfig': True,
'numfig_secnum_depth': 2}) 'numfig_secnum_depth': 2})
@pytest.mark.test_params(shared_result='test_build_html_numfig_depth_2') @pytest.mark.test_params(shared_result='test_build_html_numfig_depth_2')
def test_numfig_with_secnum_depth(app, cached_etree_parse, fname, expect): def test_numfig_with_secnum_depth(app, cached_etree_parse, fname, path, check, be_found):
app.build() app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)
@pytest.mark.parametrize("expect", [ @pytest.mark.parametrize("expect", [

View File

@ -2,59 +2,54 @@
import pytest import pytest
from tests.test_builders.test_build_html import check_xpath, flat_dict from tests.test_builders.test_build_html import check_xpath
@pytest.mark.parametrize(("fname", "expect"), flat_dict({ @pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
'index.html': [ ('index.html', ".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
(".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True), ('index.html', ".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True),
(".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True), ('index.html', ".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', False),
(".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', False), ('index.html', ".//li[@class='toctree-l3']/a", '2.2.1. Bar B1', False),
(".//li[@class='toctree-l3']/a", '2.2.1. Bar B1', False),
],
'foo.html': [
(".//h1", 'Foo', True),
(".//h2", 'Foo A', True),
(".//h3", 'Foo A1', True),
(".//h2", 'Foo B', True),
(".//h3", 'Foo B1', True),
(".//h1//span[@class='section-number']", '1. ', True), ('foo.html', ".//h1", 'Foo', True),
(".//h2//span[@class='section-number']", '1.1. ', True), ('foo.html', ".//h2", 'Foo A', True),
(".//h3//span[@class='section-number']", '1.1.1. ', True), ('foo.html', ".//h3", 'Foo A1', True),
(".//h2//span[@class='section-number']", '1.2. ', True), ('foo.html', ".//h2", 'Foo B', True),
(".//h3//span[@class='section-number']", '1.2.1. ', True), ('foo.html', ".//h3", 'Foo B1', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.1. Foo A', True), ('foo.html', ".//h1//span[@class='section-number']", '1. ', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.1.1. Foo A1', True), ('foo.html', ".//h2//span[@class='section-number']", '1.1. ', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.2. Foo B', True), ('foo.html', ".//h3//span[@class='section-number']", '1.1.1. ', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.2.1. Foo B1', True), ('foo.html', ".//h2//span[@class='section-number']", '1.2. ', True),
], ('foo.html', ".//h3//span[@class='section-number']", '1.2.1. ', True),
'bar.html': [
(".//h1", 'Bar', True), ('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.1. Foo A', True),
(".//h2", 'Bar A', True), ('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.1.1. Foo A1', True),
(".//h2", 'Bar B', True), ('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.2. Foo B', True),
(".//h3", 'Bar B1', True), ('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.2.1. Foo B1', True),
(".//h1//span[@class='section-number']", '2. ', True),
(".//h2//span[@class='section-number']", '2.1. ', True), ('bar.html', ".//h1", 'Bar', True),
(".//h2//span[@class='section-number']", '2.2. ', True), ('bar.html', ".//h2", 'Bar A', True),
(".//h3//span[@class='section-number']", '2.2.1. ', True), ('bar.html', ".//h2", 'Bar B', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2. Bar', True), ('bar.html', ".//h3", 'Bar B1', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2.1. Bar A', True), ('bar.html', ".//h1//span[@class='section-number']", '2. ', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2.2. Bar B', True), ('bar.html', ".//h2//span[@class='section-number']", '2.1. ', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2.2.1. Bar B1', False), ('bar.html', ".//h2//span[@class='section-number']", '2.2. ', True),
], ('bar.html', ".//h3//span[@class='section-number']", '2.2.1. ', True),
'baz.html': [ ('bar.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '2. Bar', True),
(".//h1", 'Baz A', True), ('bar.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '2.1. Bar A', True),
(".//h1//span[@class='section-number']", '2.1.1. ', True), ('bar.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '2.2. Bar B', True),
], ('bar.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '2.2.1. Bar B1', False),
}))
('baz.html', ".//h1", 'Baz A', True),
('baz.html', ".//h1//span[@class='section-number']", '2.1.1. ', True),
])
@pytest.mark.sphinx('html', testroot='tocdepth') @pytest.mark.sphinx('html', testroot='tocdepth')
@pytest.mark.test_params(shared_result='test_build_html_tocdepth') @pytest.mark.test_params(shared_result='test_build_html_tocdepth')
def test_tocdepth(app, cached_etree_parse, fname, expect): def test_tocdepth(app, cached_etree_parse, fname, path, check, be_found):
app.build() app.build()
# issue #1251 # issue #1251
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)
@pytest.mark.parametrize("expect", [ @pytest.mark.parametrize("expect", [