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 74 75 76 77 78 79 80 81 82
|
from pathlib import Path
import pytest
from syrupy.filters import props
@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_needarch"}],
indirect=True,
)
def test_doc_needarch(test_app):
app = test_app
app.build()
html = Path(app.outdir, "index.html").read_text(encoding="utf8")
assert html
@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_needarch_negative_tests"}],
indirect=True,
)
def test_doc_needarch_negative(test_app):
import subprocess
app = test_app
srcdir = Path(app.srcdir)
out_dir = srcdir / "_build"
out = subprocess.run(
["sphinx-build", "-M", "html", srcdir, out_dir], capture_output=True
)
assert out.returncode == 1
assert (
"sphinx_needs.directives.needuml.NeedArchException: Directive needarch "
"can only be used inside a need." in out.stderr.decode("utf-8")
)
@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_needarch_jinja_func_import"}],
indirect=True,
)
def test_doc_needarch_jinja_import(test_app, snapshot):
app = test_app
app.build()
html = Path(app.outdir, "index.html").read_text(encoding="utf8")
assert html
# check needarch
all_needumls = app.env._needs_all_needumls
assert all_needumls == snapshot(exclude=props("process_time"))
@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_needarch_jinja_func_need"}],
indirect=True,
)
def test_needarch_jinja_func_need(test_app, snapshot):
app = test_app
app.build()
all_needumls = app.env._needs_all_needumls
assert all_needumls == snapshot(exclude=props("process_time"))
html = Path(app.outdir, "index.html").read_text(encoding="utf8")
assert "as INT_001 [[../index.html#INT_001]]" in html
import subprocess
srcdir = Path(app.srcdir)
out_dir = srcdir / "_build"
out = subprocess.run(
["sphinx-build", "-M", "html", srcdir, out_dir], capture_output=True
)
assert out.returncode == 0
|