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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
import subprocess
from pathlib import Path
import pytest
from sphinx.util.console import strip_colors
@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_report_dead_links_true"}],
indirect=True,
)
def test_needs_dead_links_warnings(test_app):
app = test_app
src_dir = Path(app.srcdir)
out_dir = Path(app.outdir)
output = subprocess.run(
["sphinx-build", "-M", "html", src_dir, out_dir], capture_output=True
)
# check there are expected warnings
stderr = strip_colors(output.stderr.decode("utf-8"))
expected_warnings = [
f"{Path(str(app.srcdir)) / 'index.rst'}:17: WARNING: Need 'REQ_004' has unknown outgoing link 'ANOTHER_DEAD_LINK' in field 'links' [needs.link_outgoing]",
f"{Path(str(app.srcdir)) / 'index.rst'}:45: WARNING: Need 'TEST_004' has unknown outgoing link 'REQ_005.invalid' in field 'links' [needs.link_outgoing]",
f"{Path(str(app.srcdir)) / 'index.rst'}:45: WARNING: Need 'TEST_004' has unknown outgoing link 'REQ_005.invalid' in field 'tests' [needs.link_outgoing]",
]
assert stderr.splitlines() == expected_warnings
@pytest.mark.parametrize(
"test_app",
[{"buildername": "needs", "srcdir": "doc_test/doc_report_dead_links_true"}],
indirect=True,
)
def test_needs_dead_links_warnings_needs_builder(test_app):
app = test_app
src_dir = Path(app.srcdir)
out_dir = Path(app.outdir)
output = subprocess.run(
["sphinx-build", "-M", "needs", src_dir, out_dir], capture_output=True
)
# check there are expected warnings
stderr = strip_colors(output.stderr.decode("utf-8"))
expected_warnings = [
f"{Path(str(app.srcdir)) / 'index.rst'}:17: WARNING: Need 'REQ_004' has unknown outgoing link 'ANOTHER_DEAD_LINK' in field 'links' [needs.link_outgoing]",
f"{Path(str(app.srcdir)) / 'index.rst'}:45: WARNING: Need 'TEST_004' has unknown outgoing link 'REQ_005.invalid' in field 'links' [needs.link_outgoing]",
f"{Path(str(app.srcdir)) / 'index.rst'}:45: WARNING: Need 'TEST_004' has unknown outgoing link 'REQ_005.invalid' in field 'tests' [needs.link_outgoing]",
]
assert stderr.splitlines() == expected_warnings
@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_report_dead_links_false"}],
indirect=True,
)
def test_needs_dead_links_suppress_warnings(test_app):
app = test_app
src_dir = Path(app.srcdir)
out_dir = Path(app.outdir)
output = subprocess.run(
["sphinx-build", "-M", "html", src_dir, out_dir], capture_output=True
)
# check there are no warnings
assert not output.stderr
|