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):
nodes = list(etree.findall(path))
if check is None:
@ -99,34 +95,31 @@ def test_html4_error(make_app, tmp_path):
)
@pytest.mark.parametrize(("fname", "expect"), flat_dict({
'index.html': [
(".//div[@class='citation']/span", r'Ref1'),
(".//div[@class='citation']/span", r'Ref_1'),
],
'footnote.html': [
(".//a[@class='footnote-reference brackets'][@href='#id9'][@id='id1']", r"1"),
(".//a[@class='footnote-reference brackets'][@href='#id10'][@id='id2']", r"2"),
(".//a[@class='footnote-reference brackets'][@href='#foo'][@id='id3']", r"3"),
(".//a[@class='reference internal'][@href='#bar'][@id='id4']/span", r"\[bar\]"),
(".//a[@class='reference internal'][@href='#baz-qux'][@id='id5']/span", r"\[baz_qux\]"),
(".//a[@class='footnote-reference brackets'][@href='#id11'][@id='id6']", r"4"),
(".//a[@class='footnote-reference brackets'][@href='#id12'][@id='id7']", r"5"),
(".//aside[@class='footnote brackets']/span/a[@href='#id1']", r"1"),
(".//aside[@class='footnote brackets']/span/a[@href='#id2']", r"2"),
(".//aside[@class='footnote brackets']/span/a[@href='#id3']", r"3"),
(".//div[@class='citation']/span/a[@href='#id4']", r"bar"),
(".//div[@class='citation']/span/a[@href='#id5']", r"baz_qux"),
(".//aside[@class='footnote brackets']/span/a[@href='#id6']", r"4"),
(".//aside[@class='footnote brackets']/span/a[@href='#id7']", r"5"),
(".//aside[@class='footnote brackets']/span/a[@href='#id8']", r"6"),
],
}))
@pytest.mark.parametrize(("fname", "path", "check"), [
('index.html', ".//div[@class='citation']/span", r'Ref1'),
('index.html', ".//div[@class='citation']/span", r'Ref_1'),
('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id9'][@id='id1']", r"1"),
('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id10'][@id='id2']", r"2"),
('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#foo'][@id='id3']", r"3"),
('footnote.html', ".//a[@class='reference internal'][@href='#bar'][@id='id4']/span", r"\[bar\]"),
('footnote.html', ".//a[@class='reference internal'][@href='#baz-qux'][@id='id5']/span", r"\[baz_qux\]"),
('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id11'][@id='id6']", r"4"),
('footnote.html', ".//a[@class='footnote-reference brackets'][@href='#id12'][@id='id7']", r"5"),
('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id1']", r"1"),
('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id2']", r"2"),
('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id3']", r"3"),
('footnote.html', ".//div[@class='citation']/span/a[@href='#id4']", r"bar"),
('footnote.html', ".//div[@class='citation']/span/a[@href='#id5']", r"baz_qux"),
('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id6']", r"4"),
('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id7']", r"5"),
('footnote.html', ".//aside[@class='footnote brackets']/span/a[@href='#id8']", r"6"),
])
@pytest.mark.sphinx('html')
@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()
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)

View File

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

View File

@ -2,59 +2,54 @@
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({
'index.html': [
(".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
(".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True),
(".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', 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),
@pytest.mark.parametrize(("fname", "path", "check", "be_found"), [
('index.html', ".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
('index.html', ".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True),
('index.html', ".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', False),
('index.html', ".//li[@class='toctree-l3']/a", '2.2.1. Bar B1', False),
(".//h1//span[@class='section-number']", '1. ', True),
(".//h2//span[@class='section-number']", '1.1. ', True),
(".//h3//span[@class='section-number']", '1.1.1. ', True),
(".//h2//span[@class='section-number']", '1.2. ', True),
(".//h3//span[@class='section-number']", '1.2.1. ', True),
('foo.html', ".//h1", 'Foo', True),
('foo.html', ".//h2", 'Foo A', True),
('foo.html', ".//h3", 'Foo A1', True),
('foo.html', ".//h2", 'Foo B', True),
('foo.html', ".//h3", 'Foo B1', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.1. Foo A', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.1.1. Foo A1', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.2. Foo B', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '1.2.1. Foo B1', True),
],
'bar.html': [
(".//h1", 'Bar', True),
(".//h2", 'Bar A', True),
(".//h2", 'Bar B', True),
(".//h3", 'Bar B1', True),
(".//h1//span[@class='section-number']", '2. ', True),
(".//h2//span[@class='section-number']", '2.1. ', True),
(".//h2//span[@class='section-number']", '2.2. ', True),
(".//h3//span[@class='section-number']", '2.2.1. ', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2. Bar', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2.1. Bar A', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2.2. Bar B', True),
(".//div[@class='sphinxsidebarwrapper']//li/a", '2.2.1. Bar B1', False),
],
'baz.html': [
(".//h1", 'Baz A', True),
(".//h1//span[@class='section-number']", '2.1.1. ', True),
],
}))
('foo.html', ".//h1//span[@class='section-number']", '1. ', True),
('foo.html', ".//h2//span[@class='section-number']", '1.1. ', True),
('foo.html', ".//h3//span[@class='section-number']", '1.1.1. ', True),
('foo.html', ".//h2//span[@class='section-number']", '1.2. ', True),
('foo.html', ".//h3//span[@class='section-number']", '1.2.1. ', True),
('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.1. Foo A', True),
('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.1.1. Foo A1', True),
('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.2. Foo B', True),
('foo.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '1.2.1. Foo B1', True),
('bar.html', ".//h1", 'Bar', True),
('bar.html', ".//h2", 'Bar A', True),
('bar.html', ".//h2", 'Bar B', True),
('bar.html', ".//h3", 'Bar B1', True),
('bar.html', ".//h1//span[@class='section-number']", '2. ', True),
('bar.html', ".//h2//span[@class='section-number']", '2.1. ', True),
('bar.html', ".//h2//span[@class='section-number']", '2.2. ', True),
('bar.html', ".//h3//span[@class='section-number']", '2.2.1. ', True),
('bar.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '2. Bar', True),
('bar.html', ".//div[@class='sphinxsidebarwrapper']//li/a", '2.1. Bar A', 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.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()
# 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", [