mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Split out `test_build_all`
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from contextlib import contextmanager
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from docutils import nodes
|
||||
@@ -16,59 +14,6 @@ from sphinx.errors import SphinxError
|
||||
from tests.utils import TESTS_ROOT
|
||||
|
||||
|
||||
def request_session_head(url, **kwargs):
|
||||
response = mock.Mock()
|
||||
response.status_code = 200
|
||||
response.url = url
|
||||
return response
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
|
||||
# Build in a non-ASCII source dir
|
||||
test_name = '\u65e5\u672c\u8a9e'
|
||||
basedir = sphinx_test_tempdir / request.node.originalname
|
||||
srcdir = basedir / test_name
|
||||
if not srcdir.exists():
|
||||
shutil.copytree(rootdir / 'test-root', srcdir)
|
||||
|
||||
# add a doc with a non-ASCII file name to the source dir
|
||||
(srcdir / (test_name + '.txt')).write_text(
|
||||
"""
|
||||
nonascii file name page
|
||||
=======================
|
||||
""",
|
||||
encoding='utf8',
|
||||
)
|
||||
|
||||
root_doc = srcdir / 'index.txt'
|
||||
root_doc.write_text(
|
||||
root_doc.read_text(encoding='utf8')
|
||||
+ f"""
|
||||
.. toctree::
|
||||
|
||||
{test_name}/{test_name}
|
||||
""",
|
||||
encoding='utf8',
|
||||
)
|
||||
return srcdir
|
||||
|
||||
|
||||
# note: this test skips building docs for some builders because they have independent testcase.
|
||||
# (html, changes, epub, latex, texinfo and manpage)
|
||||
@pytest.mark.parametrize(
|
||||
'buildername',
|
||||
['dirhtml', 'singlehtml', 'text', 'xml', 'pseudoxml', 'linkcheck'],
|
||||
)
|
||||
@mock.patch(
|
||||
'sphinx.builders.linkcheck.requests.head',
|
||||
side_effect=request_session_head,
|
||||
)
|
||||
def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
|
||||
app = make_app(buildername, srcdir=nonascii_srcdir)
|
||||
app.build()
|
||||
|
||||
|
||||
def test_root_doc_not_found(tmp_path, make_app):
|
||||
(tmp_path / 'conf.py').touch()
|
||||
assert [p.name for p in tmp_path.iterdir()] == ['conf.py']
|
||||
|
||||
97
tests/test_builders/test_build_all.py
Normal file
97
tests/test_builders/test_build_all.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""Test all builders.
|
||||
|
||||
This test skips building docs for some builders that have independent testcases.
|
||||
(html, changes, epub, latex, texinfo and manpage)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from sphinx.testing.util import SphinxTestApp
|
||||
|
||||
|
||||
def request_session_head(url: str, **kwargs: object) -> mock.Mock:
|
||||
response = mock.Mock()
|
||||
response.status_code = 200
|
||||
response.url = url
|
||||
return response
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def nonascii_srcdir(rootdir: Path, sphinx_test_tempdir: Path) -> Path:
|
||||
# Build in a non-ASCII source dir
|
||||
test_name = '\u65e5\u672c\u8a9e'
|
||||
srcdir = sphinx_test_tempdir / 'test_build_all' / test_name
|
||||
if not srcdir.exists():
|
||||
shutil.copytree(rootdir / 'test-root', srcdir)
|
||||
|
||||
# add a doc with a non-ASCII file name to the source dir
|
||||
(srcdir / f'{test_name}.txt').write_text(
|
||||
'non-ascii file name page\n========================\n', encoding='utf8'
|
||||
)
|
||||
|
||||
with srcdir.joinpath('index.txt').open('a', encoding='utf8') as f:
|
||||
f.write(f"""
|
||||
.. toctree::
|
||||
|
||||
{test_name}/{test_name}
|
||||
""")
|
||||
return srcdir
|
||||
|
||||
|
||||
def test_build_dirhtml(
|
||||
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path
|
||||
) -> None:
|
||||
app = make_app('dirhtml', srcdir=nonascii_srcdir)
|
||||
app.build(force_all=True)
|
||||
|
||||
|
||||
def test_build_singlehtml(
|
||||
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path
|
||||
) -> None:
|
||||
app = make_app('singlehtml', srcdir=nonascii_srcdir)
|
||||
app.build(force_all=True)
|
||||
|
||||
|
||||
def test_build_text(
|
||||
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path
|
||||
) -> None:
|
||||
app = make_app('text', srcdir=nonascii_srcdir)
|
||||
app.build(force_all=True)
|
||||
|
||||
|
||||
def test_build_xml(
|
||||
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path
|
||||
) -> None:
|
||||
app = make_app('xml', srcdir=nonascii_srcdir)
|
||||
app.build(force_all=True)
|
||||
|
||||
|
||||
def test_build_pseudoxml(
|
||||
make_app: Callable[..., SphinxTestApp], nonascii_srcdir: Path
|
||||
) -> None:
|
||||
app = make_app('pseudoxml', srcdir=nonascii_srcdir)
|
||||
app.build(force_all=True)
|
||||
|
||||
|
||||
@mock.patch(
|
||||
'sphinx.builders.linkcheck.requests.head',
|
||||
side_effect=request_session_head,
|
||||
)
|
||||
def test_build_linkcheck(
|
||||
requests_head: MagicMock,
|
||||
make_app: Callable[..., SphinxTestApp],
|
||||
nonascii_srcdir: Path,
|
||||
) -> None:
|
||||
app = make_app('linkcheck', srcdir=nonascii_srcdir)
|
||||
app.build(force_all=True)
|
||||
Reference in New Issue
Block a user