Remove unneeded uses of `flat_dict()`

This commit is contained in:
Adam Turner 2024-01-17 01:58:52 +00:00
parent 59cf4d4c35
commit 841f2bd9b7

View File

@ -4,7 +4,6 @@ import hashlib
import os
import posixpath
import re
from itertools import chain, cycle
from pathlib import Path
from unittest.mock import ANY, call, patch
@ -59,13 +58,8 @@ def cached_etree_parse():
etree_cache.clear()
def flat_dict(d):
return chain.from_iterable(
[
zip(cycle([fname]), values)
for fname, values in d.items()
],
)
def flat_dict(d: dict[str, list[str]]):
return ((fname, value) for fname, values in d.items() for value in values)
def tail_check(check):
@ -409,7 +403,6 @@ def test_html4_error(make_app, tmp_path):
@pytest.mark.test_params(shared_result='test_build_html_output')
def test_html5_output(app, cached_etree_parse, fname, expect):
app.build()
print(app.outdir / fname)
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
@ -440,7 +433,6 @@ def test_html5_output(app, cached_etree_parse, fname, expect):
@pytest.mark.test_params(shared_result='test_build_html_output_docutils18')
def test_docutils_output(app, cached_etree_parse, fname, expect):
app.build()
print(app.outdir / fname)
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
@ -565,8 +557,7 @@ def test_tocdepth(app, cached_etree_parse, fname, expect):
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
@pytest.mark.parametrize(("fname", "expect"), flat_dict({
'index.html': [
@pytest.mark.parametrize("expect", [
(".//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),
@ -600,13 +591,12 @@ def test_tocdepth(app, cached_etree_parse, fname, expect):
# baz.rst
(".//h4", 'Baz A', True),
(".//h4//span[@class='section-number']", '2.1.1. ', True),
],
}))
])
@pytest.mark.sphinx('singlehtml', testroot='tocdepth')
@pytest.mark.test_params(shared_result='test_build_html_tocdepth')
def test_tocdepth_singlehtml(app, cached_etree_parse, fname, expect):
def test_tocdepth_singlehtml(app, cached_etree_parse, expect):
app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)
@pytest.mark.sphinx('html', testroot='numfig')
@ -1043,8 +1033,7 @@ def test_numfig_with_secnum_depth(app, cached_etree_parse, fname, expect):
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
@pytest.mark.parametrize(("fname", "expect"), flat_dict({
'index.html': [
@pytest.mark.parametrize("expect", [
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 1 $', True),
(FIGURE_CAPTION + "/span[@class='caption-number']", '^Fig. 2 $', True),
(".//table/caption/span[@class='caption-number']",
@ -1105,17 +1094,15 @@ def test_numfig_with_secnum_depth(app, cached_etree_parse, fname, expect):
'^Table 2.2 $', True),
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", '^Listing 2.2 $', True),
],
}))
])
@pytest.mark.sphinx('singlehtml', testroot='numfig', confoverrides={'numfig': True})
@pytest.mark.test_params(shared_result='test_build_html_numfig_on')
def test_numfig_with_singlehtml(app, cached_etree_parse, fname, expect):
def test_numfig_with_singlehtml(app, cached_etree_parse, expect):
app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)
@pytest.mark.parametrize(("fname", "expect"), flat_dict({
'index.html': [
@pytest.mark.parametrize("expect", [
(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),
@ -1126,13 +1113,12 @@ def test_numfig_with_singlehtml(app, cached_etree_parse, fname, expect):
(".//li/p/a/span", 'Fig. 3', True),
(".//li/p/a/span", 'No.1', True),
(".//li/p/a/span", 'No.2', True),
],
}))
])
@pytest.mark.sphinx('html', testroot='add_enumerable_node',
srcdir='test_enumerable_node')
def test_enumerable_node(app, cached_etree_parse, fname, expect):
def test_enumerable_node(app, cached_etree_parse, expect):
app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)
@pytest.mark.sphinx('html', testroot='html_assets')
@ -1368,8 +1354,7 @@ def test_html_raw_directive(app, status, warning):
assert '<p>LaTeX: abc ghi</p>' in result
@pytest.mark.parametrize(("fname", "expect"), flat_dict({
'index.html': [
@pytest.mark.parametrize("expect", [
(".//link[@href='_static/persistent.css']"
"[@rel='stylesheet']", '', True),
(".//link[@href='_static/default.css']"
@ -1390,12 +1375,11 @@ def test_html_raw_directive(app, status, warning):
"[@title='Alternate']", '', True),
(".//link[@href='_static/more_alternate2.css']"
"[@rel='alternate stylesheet']", '', True),
],
}))
])
@pytest.mark.sphinx('html', testroot='stylesheets')
def test_alternate_stylesheets(app, cached_etree_parse, fname, expect):
def test_alternate_stylesheets(app, cached_etree_parse, expect):
app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)
@pytest.mark.sphinx('html', testroot='html_style')