| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import TYPE_CHECKING |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
if TYPE_CHECKING: |
| 8 |
from sphinx.testing.util import SphinxTestApp |
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.sphinx('html', testroot='trim_doctest_flags') |
| 12 |
def test_trim_doctest_flags_html(app: SphinxTestApp) -> None: |
| 13 |
app.build() |
| 14 |
|
| 15 |
result = (app.outdir / 'index.html').read_text(encoding='utf8') |
| 16 |
assert 'FOO' not in result |
| 17 |
assert 'BAR' in result |
| 18 |
assert 'BAZ' not in result |
| 19 |
assert 'QUX' not in result |
| 20 |
assert 'QUUX' not in result |
| 21 |
assert 'CORGE' not in result |
| 22 |
assert 'GRAULT' in result |
| 23 |
assert '<span class="n">now</span><span class="p">()</span> \n' not in result |
| 24 |
assert '<span class="n">now</span><span class="p">()</span>\n' in result |
| 25 |
|
| 26 |
|
| 27 |
@pytest.mark.sphinx( |
| 28 |
'html', |
| 29 |
testroot='trim_doctest_flags', |
| 30 |
confoverrides={'trim_doctest_flags': False}, |
| 31 |
) |
| 32 |
def test_trim_doctest_flags_disabled(app: SphinxTestApp) -> None: |
| 33 |
app.build() |
| 34 |
|
| 35 |
result = (app.outdir / 'index.html').read_text(encoding='utf8') |
| 36 |
assert 'FOO' in result |
| 37 |
assert 'BAR' in result |
| 38 |
assert 'BAZ' in result |
| 39 |
assert 'QUX' in result |
| 40 |
assert 'QUUX' not in result |
| 41 |
assert 'CORGE' not in result |
| 42 |
assert 'GRAULT' in result |
| 43 |
|
| 44 |
|
| 45 |
@pytest.mark.sphinx('latex', testroot='trim_doctest_flags') |
| 46 |
def test_trim_doctest_flags_latex(app: SphinxTestApp) -> None: |
| 47 |
app.build() |
| 48 |
|
| 49 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 50 |
assert 'FOO' not in result |
| 51 |
assert 'BAR' in result |
| 52 |
assert 'BAZ' not in result |
| 53 |
assert 'QUX' not in result |
| 54 |
assert 'QUUX' not in result |
| 55 |
assert 'CORGE' not in result |
| 56 |
assert 'GRAULT' in result |