From b38f30b2dd00e67e7cfa75698f2526f9d2d80101 Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Sep 2024 18:44:18 +0100 Subject: [PATCH 1/5] HTML builder: add test coverage for parallelised `toctree` rendering The test case added here is expected to fail intermittently to begin with; it is added to uncover what seems to be a race condition that occurs during some but not all parallelised builds. --- .../test_builders/test_build_html_toctree.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_builders/test_build_html_toctree.py b/tests/test_builders/test_build_html_toctree.py index 7b9e5a49d13..2ab97d9b7f5 100644 --- a/tests/test_builders/test_build_html_toctree.py +++ b/tests/test_builders/test_build_html_toctree.py @@ -29,6 +29,30 @@ def test_relations(app): assert 'quux' not in app.builder.relations +@pytest.mark.sphinx( + 'html', + testroot='toctree-glob', + parallel=5, + confoverrides={'html_theme': 'alabaster'}, +) +def test_parallel_toctree(app, cached_etree_parse): + app.build(force_all=True) + + index = app.outdir / 'index.html' + bar1 = app.outdir / 'bar' / 'bar_1.html' + + # top-level documents should only contain depth-1 navigation links + sidebar_xpath = "//div[@class='sphinxsidebarwrapper']" + nested_links = f"{sidebar_xpath}//li[@class!='toctree-l1']/a" + check_xpath(cached_etree_parse(index), index.name, nested_links, None, be_found=False) + + # nested documents should contain breadcrumbs for depths one and two + crumb1 = f"{sidebar_xpath}//li[@class='toctree-l1 current']/a" + crumb2 = f"{sidebar_xpath}//li[@class='toctree-l2 current']/a" + check_xpath(cached_etree_parse(bar1), bar1.name, crumb1, '^Bar$') + check_xpath(cached_etree_parse(bar1), bar1.name, crumb2, '^Bar-1$') + + @pytest.mark.sphinx('singlehtml', testroot='toctree-empty') def test_singlehtml_toctree(app): app.build(force_all=True) From f0b2a9195f4b90322e07c36d8d997e4a6c739b0a Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Sep 2024 18:45:58 +0100 Subject: [PATCH 2/5] Linting: apply `ruff` formatting --- tests/test_builders/test_build_html_toctree.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_builders/test_build_html_toctree.py b/tests/test_builders/test_build_html_toctree.py index 2ab97d9b7f5..b449bb0b43f 100644 --- a/tests/test_builders/test_build_html_toctree.py +++ b/tests/test_builders/test_build_html_toctree.py @@ -44,7 +44,9 @@ def test_parallel_toctree(app, cached_etree_parse): # top-level documents should only contain depth-1 navigation links sidebar_xpath = "//div[@class='sphinxsidebarwrapper']" nested_links = f"{sidebar_xpath}//li[@class!='toctree-l1']/a" - check_xpath(cached_etree_parse(index), index.name, nested_links, None, be_found=False) + check_xpath( + cached_etree_parse(index), index.name, nested_links, None, be_found=False + ) # nested documents should contain breadcrumbs for depths one and two crumb1 = f"{sidebar_xpath}//li[@class='toctree-l1 current']/a" From 8f4d63b9bf059a72e254ac579cd7d346db93eae6 Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Sep 2024 18:59:44 +0100 Subject: [PATCH 3/5] Nitpick: resolve `FutureWarning` notices --- tests/test_builders/test_build_html_toctree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_builders/test_build_html_toctree.py b/tests/test_builders/test_build_html_toctree.py index b449bb0b43f..6eadbfe5761 100644 --- a/tests/test_builders/test_build_html_toctree.py +++ b/tests/test_builders/test_build_html_toctree.py @@ -42,7 +42,7 @@ def test_parallel_toctree(app, cached_etree_parse): bar1 = app.outdir / 'bar' / 'bar_1.html' # top-level documents should only contain depth-1 navigation links - sidebar_xpath = "//div[@class='sphinxsidebarwrapper']" + sidebar_xpath = ".//div[@class='sphinxsidebarwrapper']" nested_links = f"{sidebar_xpath}//li[@class!='toctree-l1']/a" check_xpath( cached_etree_parse(index), index.name, nested_links, None, be_found=False From aed7a6c18abe5ebb6215ea2887105f796aa343bb Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Sep 2024 19:05:39 +0100 Subject: [PATCH 4/5] Linting: rename variable to fit within line-length limits --- tests/test_builders/test_build_html_toctree.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_builders/test_build_html_toctree.py b/tests/test_builders/test_build_html_toctree.py index 6eadbfe5761..4849637e1fa 100644 --- a/tests/test_builders/test_build_html_toctree.py +++ b/tests/test_builders/test_build_html_toctree.py @@ -32,21 +32,19 @@ def test_relations(app): @pytest.mark.sphinx( 'html', testroot='toctree-glob', - parallel=5, + parallel=2, confoverrides={'html_theme': 'alabaster'}, ) def test_parallel_toctree(app, cached_etree_parse): app.build(force_all=True) - index = app.outdir / 'index.html' + root = app.outdir / 'index.html' bar1 = app.outdir / 'bar' / 'bar_1.html' # top-level documents should only contain depth-1 navigation links sidebar_xpath = ".//div[@class='sphinxsidebarwrapper']" nested_links = f"{sidebar_xpath}//li[@class!='toctree-l1']/a" - check_xpath( - cached_etree_parse(index), index.name, nested_links, None, be_found=False - ) + check_xpath(cached_etree_parse(root), root.name, nested_links, None, be_found=False) # nested documents should contain breadcrumbs for depths one and two crumb1 = f"{sidebar_xpath}//li[@class='toctree-l1 current']/a" From fcd4970b11db12056e73cc6050b8271a07afac11 Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Sep 2024 19:09:20 +0100 Subject: [PATCH 5/5] Nitpick: remove unintentional `parallel` argument change from test Relates-to commit aed7a6c18abe5ebb6215ea2887105f796aa343bb. --- tests/test_builders/test_build_html_toctree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_builders/test_build_html_toctree.py b/tests/test_builders/test_build_html_toctree.py index 4849637e1fa..7d5c436c2b6 100644 --- a/tests/test_builders/test_build_html_toctree.py +++ b/tests/test_builders/test_build_html_toctree.py @@ -32,7 +32,7 @@ def test_relations(app): @pytest.mark.sphinx( 'html', testroot='toctree-glob', - parallel=2, + parallel=5, confoverrides={'html_theme': 'alabaster'}, ) def test_parallel_toctree(app, cached_etree_parse):