File: test_build.py

package info (click to toggle)
sphinx-remove-toctrees 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: python: 124; makefile: 14; sh: 7
file content (37 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from pathlib import Path
from shutil import copytree

from bs4 import BeautifulSoup
from sphinx import version_info as sphinx_version_info

pytest_plugins = "sphinx.testing.fixtures"

path_test_doc = Path(__file__).parent / "site"


def test_build_html(make_app, tmp_path):
    """Test building the base html template and config."""
    src_dir = tmp_path / "test_doc"
    copytree(path_test_doc, src_dir)    

    # For compatibility with multiple versions of sphinx, convert pathlib.Path to
    # sphinx.testing.path.path here.
    if sphinx_version_info >= (7, 2):
        app_src_dir = src_dir
    else:
        from sphinx.testing.path import path

        app_src_dir = path(os.fspath(src_dir))

    app = make_app(srcdir=app_src_dir)
    app.build()
    index = tmp_path / "test_doc" / "_build" / "html" / "index.html"
    assert index.exists()
    index = BeautifulSoup(index.read_text())
    sidenav = index.select("ul.bd-sidenav")[0]

    # Grab all references to second-level links, we should *only* find the shown page
    second_level_links = sidenav.select(".toctree-l2 a")
    assert len(second_level_links) == 1
    assert second_level_links[0].attrs["href"] == "nested/nested_page_shown.html"