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