| 1 |
"""Test all builders. |
| 2 |
|
| 3 |
This test skips building docs for some builders that have independent testcases. |
| 4 |
(html, changes, epub, latex, texinfo and manpage) |
| 5 |
""" |
| 6 |
|
| 7 |
from __future__ import annotations |
| 8 |
|
| 9 |
import shutil |
| 10 |
from typing import TYPE_CHECKING |
| 11 |
from unittest import mock |
| 12 |
|
| 13 |
import pytest |
| 14 |
|
| 15 |
from sphinx.testing.util import SphinxTestApp |
| 16 |
|
| 17 |
if TYPE_CHECKING: |
| 18 |
from collections.abc import Callable |
| 19 |
from pathlib import Path |
| 20 |
from unittest.mock import MagicMock |
| 21 |
|
| 22 |
from sphinx.testing.util import SphinxTestApp |
| 23 |
|
| 24 |
|
| 25 |
def request_session_head(url: str, **kwargs: object) -> mock.Mock: |
| 26 |
response = mock.Mock() |
| 27 |
response.status_code = 200 |
| 28 |
response.url = url |
| 29 |
return response |
| 30 |
|
| 31 |
|
| 32 |
@pytest.fixture |
| 33 |
def nonascii_srcdir(rootdir: Path, sphinx_test_tempdir: Path) -> Path: |
| 34 |
# Build in a non-ASCII source dir |
| 35 |
test_name = '\u65e5\u672c\u8a9e' |
| 36 |
srcdir = sphinx_test_tempdir / 'test_build_all' / test_name |
| 37 |
if not srcdir.exists(): |
| 38 |
shutil.copytree(rootdir / 'test-root', srcdir) |
| 39 |
|
| 40 |
# add a doc with a non-ASCII file name to the source dir |
| 41 |
(srcdir / f'{test_name}.txt').write_text( |
| 42 |
'non-ascii file name page\n========================\n', encoding='utf8' |
| 43 |
) |
| 44 |
|
| 45 |
with srcdir.joinpath('index.txt').open('a', encoding='utf8') as f: |
| 46 |
f.write(f""" |
| 47 |
.. toctree:: |
| 48 |
|
| 49 |
{test_name}/{test_name} |
| 50 |
""") |
| 51 |
return srcdir |
| 52 |
|
| 53 |
|
| 54 |
def test_build_dirhtml( |
| 55 |
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path |
| 56 |
) -> None: |
| 57 |
app = make_app('dirhtml', srcdir=nonascii_srcdir) |
| 58 |
app.build(force_all=True) |
| 59 |
|
| 60 |
|
| 61 |
def test_build_singlehtml( |
| 62 |
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path |
| 63 |
) -> None: |
| 64 |
app = make_app('singlehtml', srcdir=nonascii_srcdir) |
| 65 |
app.build(force_all=True) |
| 66 |
|
| 67 |
|
| 68 |
def test_build_text( |
| 69 |
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path |
| 70 |
) -> None: |
| 71 |
app = make_app('text', srcdir=nonascii_srcdir) |
| 72 |
app.build(force_all=True) |
| 73 |
|
| 74 |
|
| 75 |
def test_build_xml( |
| 76 |
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path |
| 77 |
) -> None: |
| 78 |
app = make_app('xml', srcdir=nonascii_srcdir) |
| 79 |
app.build(force_all=True) |
| 80 |
|
| 81 |
|
| 82 |
def test_build_pseudoxml( |
| 83 |
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path |
| 84 |
) -> None: |
| 85 |
app = make_app('pseudoxml', srcdir=nonascii_srcdir) |
| 86 |
app.build(force_all=True) |
| 87 |
|
| 88 |
|
| 89 |
@mock.patch( |
| 90 |
'sphinx.builders.linkcheck.requests.head', |
| 91 |
side_effect=request_session_head, |
| 92 |
) |
| 93 |
def test_build_linkcheck( |
| 94 |
requests_head: MagicMock, |
| 95 |
make_app: Callable[..., SphinxTestApp], |
| 96 |
nonascii_srcdir: Path, |
| 97 |
) -> None: |
| 98 |
app = make_app('linkcheck', srcdir=nonascii_srcdir) |
| 99 |
app.build(force_all=True) |