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 38 39 40 41 42 43 44 45
|
# stdlib
import pathlib
import sys
import types
from typing import Iterator
# 3rd party
import pytest
import sphinx
from bs4 import BeautifulSoup # type: ignore[import]
from sphinx.application import Sphinx
if sys.version_info >= (3, 10):
types.Union = types.UnionType
if sphinx.version_info >= (7, 2):
path = pathlib.Path
else:
# 3rd party
from sphinx.testing.path import path # type: ignore[misc]
pytest_plugins = ("coincidence", "sphinx.testing.fixtures")
@pytest.fixture(scope="session")
def rootdir() -> path:
rdir = pathlib.Path(__file__).parent.absolute() / "doc-test"
if not (rdir / "test-root").is_dir():
(rdir / "test-root").mkdir(parents=True)
return path(rdir)
@pytest.fixture()
def content(app: Sphinx) -> Iterator[Sphinx]:
app.build()
yield app
@pytest.fixture()
def page(content, request) -> BeautifulSoup: # noqa: MAN001
pagename = request.param
c = (content.outdir / pagename).read_text()
c = c.replace("¶", '¶')
c = c.replace("’", '’')
yield BeautifulSoup(c, "html5lib")
|