|
3 | 3 | from pathlib import Path
|
4 | 4 |
|
5 | 5 | import pytest
|
| 6 | +from _pytest.fixtures import SubRequest |
6 | 7 | from sphinx.testing.util import SphinxTestApp
|
7 | 8 |
|
8 | 9 |
|
9 |
| -@pytest.mark.sphinx("html", testroot="basic") |
10 |
| -def test_basic_as_html(app: SphinxTestApp) -> None: |
| 10 | +@pytest.fixture() |
| 11 | +def build_outcome(app: SphinxTestApp, request: SubRequest) -> str: |
11 | 12 | app.build()
|
12 |
| - outcome = (Path(app.outdir) / "index.html").read_text() |
13 |
| - assert outcome |
| 13 | + ext = {"html": "html", "text": "txt"} |
| 14 | + ext = ext.get(request.node.get_closest_marker("sphinx").args[0]) |
| 15 | + assert ext is not None |
| 16 | + return (Path(app.outdir) / f"index.{ext}").read_text() |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.sphinx("html", testroot="basic") |
| 20 | +def test_basic_as_html(build_outcome: str) -> None: |
| 21 | + assert build_outcome |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.sphinx("text", testroot="complex") |
| 25 | +def test_complex_as_text(build_outcome: str) -> None: |
| 26 | + expected = (Path(__file__).parent / "complex.txt").read_text() |
| 27 | + assert build_outcome == expected |
14 | 28 |
|
15 | 29 |
|
16 | 30 | @pytest.mark.sphinx("html", testroot="complex")
|
17 |
| -def test_complex_as_html(app: SphinxTestApp) -> None: |
18 |
| - app.build() |
19 |
| - outcome = (Path(app.outdir) / "index.html").read_text() |
20 |
| - assert outcome |
| 31 | +def test_complex_as_html(build_outcome: str) -> None: |
| 32 | + assert build_outcome |
21 | 33 |
|
22 | 34 |
|
23 | 35 | @pytest.mark.sphinx("text", testroot="prog")
|
24 |
| -def test_prog_as_text(app: SphinxTestApp) -> None: |
25 |
| - app.build() |
26 |
| - outcome = (Path(app.outdir) / "index.txt").read_text() |
27 |
| - assert outcome == "magic - CLI interface\n*********************\n\n magic\n" |
| 36 | +def test_prog_as_text(build_outcome: str) -> None: |
| 37 | + assert build_outcome == "magic - CLI interface\n*********************\n\n magic\n" |
28 | 38 |
|
29 | 39 |
|
30 | 40 | @pytest.mark.sphinx("text", testroot="title-set")
|
31 |
| -def test_set_title_as_text(app: SphinxTestApp) -> None: |
32 |
| - app.build() |
33 |
| - outcome = (Path(app.outdir) / "index.txt").read_text() |
34 |
| - assert outcome == "My own title\n************\n\n foo\n" |
| 41 | +def test_set_title_as_text(build_outcome: str) -> None: |
| 42 | + assert build_outcome == "My own title\n************\n\n foo\n" |
35 | 43 |
|
36 | 44 |
|
37 | 45 | @pytest.mark.sphinx("text", testroot="title-empty")
|
38 |
| -def test_empty_title_as_text(app: SphinxTestApp) -> None: |
39 |
| - app.build() |
40 |
| - outcome = (Path(app.outdir) / "index.txt").read_text() |
41 |
| - assert outcome == " foo\n" |
| 46 | +def test_empty_title_as_text(build_outcome: str) -> None: |
| 47 | + assert build_outcome == " foo\n" |
0 commit comments