Skip to content

Commit dc3242a

Browse files
authored
🧪 Improve tests/test_basic_doc.py (#1300)
All tests are now checked for build warnings. Additionally, the `generic_doc` test build was removed, since it was basically the same as `doc_basic`
1 parent 2ff14e7 commit dc3242a

File tree

9 files changed

+74
-129
lines changed

9 files changed

+74
-129
lines changed

‎tests/__snapshots__/test_basic_doc.ambr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# name: test_build_needs[test_app0]
22
dict({
3-
'current_version': '',
3+
'current_version': '0.1.0',
44
'versions': dict({
5-
'': dict({
5+
'0.1.0': dict({
66
'filters': dict({
77
}),
88
'filters_amount': 0,
@@ -56,9 +56,9 @@
5656
'pre_template': None,
5757
'prefix': '',
5858
'query': '',
59-
'section_name': 'Welcome to basic test’s documentation!',
59+
'section_name': 'TEST DOCUMENT',
6060
'sections': list([
61-
'Welcome to basic test’s documentation!',
61+
'TEST DOCUMENT',
6262
]),
6363
'service': '',
6464
'signature': '',
@@ -126,9 +126,9 @@
126126
'pre_template': None,
127127
'prefix': '',
128128
'query': '',
129-
'section_name': 'Welcome to basic test’s documentation!',
129+
'section_name': 'TEST DOCUMENT',
130130
'sections': list([
131-
'Welcome to basic test’s documentation!',
131+
'TEST DOCUMENT',
132132
]),
133133
'service': '',
134134
'signature': '',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<document source="<source>">
2+
<section ids="test-document" names="test\ document">
3+
<title>
4+
TEST DOCUMENT
5+
<target anonymous="" ids="ST_001" refid="ST_001">
6+
<Need classes="need need-story" ids="ST_001" refid="ST_001">
7+
<target anonymous="" ids="US_38823" refid="US_38823">
8+
<Need classes="need need-story" ids="US_38823" refid="US_38823">
9+
<target refid="needtable-index-0">
10+
<Needtable caption="True" classes="" columns="('ID',\ 'ID') ('TITLE',\ 'Title') ('STATUS',\ 'Status') ('TYPE',\ 'Type') ('OUTGOING',\ 'Outgoing') ('TAGS',\ 'Tags')" colwidths="" docname="index" export_id="" filter="status == "open"" filter_code="[]" filter_func="True" filter_warning="True" ids="needtable-index-0" lineno="12" show_filters="False" show_parts="False" sort="id_complete" sort_by="True" status="" style="" style_col="" style_row="" tags="" target_id="needtable-index-0" types="">

‎tests/__snapshots__/test_basic_doc/test_build_html_parallel[test_app0].doctree.xml

-12
This file was deleted.

‎tests/doc_test/doc_basic/conf.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
extensions = ["sphinx_needs", "sphinxcontrib.plantuml"]
1+
version = "0.1.0"
2+
copyright = "2024"
23

3-
# note, the plantuml executable command is set globally in the test suite
4-
plantuml_output_format = "svg"
4+
extensions = ["sphinx_needs"]
5+
6+
suppress_warnings = ["epub.unknown_project_files"]
57

68
needs_id_regex = "^[A-Za-z0-9_]"
79

‎tests/doc_test/doc_basic/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Welcome to basic test's documentation!
2-
======================================
1+
TEST DOCUMENT
2+
=============
33

44
.. story:: Test story
55
:id: ST_001

‎tests/doc_test/generic_doc/conf.py

-32
This file was deleted.

‎tests/doc_test/generic_doc/index.rst

-15
This file was deleted.

‎tests/test_basic_doc.py

+51-43
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,31 @@
66
from pathlib import Path
77

88
import pytest
9+
from lxml import html as html_parser
910
from sphinx import version_info
10-
from sphinx.application import Sphinx
1111
from sphinx.testing.util import SphinxTestApp
1212
from syrupy.filters import props
1313

1414
from sphinx_needs.api.need import NeedsNoIdException
1515

1616

17-
@pytest.mark.parametrize(
18-
"test_app", [{"buildername": "html", "srcdir": "doc_test/doc_basic"}], indirect=True
19-
)
20-
def test_build_html(test_app):
21-
app = test_app
22-
app.builder.build_all()
23-
24-
# Check if static files got copied correctly.
25-
build_dir = Path(app.outdir) / "_static" / "sphinx-needs" / "libs" / "html"
26-
files = [f for f in build_dir.glob("**/*") if f.is_file()]
27-
assert build_dir / "sphinx_needs_collapse.js" in files
28-
assert build_dir / "datatables_loader.js" in files
29-
assert build_dir / "DataTables-1.10.16" / "js" / "jquery.dataTables.min.js" in files
30-
31-
3217
@pytest.mark.parametrize(
3318
"test_app",
34-
[{"buildername": "html", "srcdir": "doc_test/generic_doc"}],
19+
[{"buildername": "html", "srcdir": "doc_test/doc_basic", "no_plantuml": True}],
3520
indirect=True,
3621
)
37-
def test_build_html_parallel(test_app: Sphinx, snapshot_doctree):
22+
def test_build_html(test_app: SphinxTestApp, snapshot_doctree):
3823
app = test_app
39-
app.builder.build_all()
24+
app.build()
25+
assert app._warning.getvalue() == ""
26+
27+
# Check if doctree is correct.
28+
assert app.env.get_doctree("index") == snapshot_doctree
29+
30+
# Basic checks for the generated html.
31+
html = Path(app.outdir, "index.html").read_text()
32+
assert "<h1>TEST DOCUMENT" in html
33+
assert "ST_001" in html
4034

4135
# Check if static files got copied correctly.
4236
build_dir = Path(app.outdir) / "_static" / "sphinx-needs" / "libs" / "html"
@@ -45,22 +39,19 @@ def test_build_html_parallel(test_app: Sphinx, snapshot_doctree):
4539
assert build_dir / "datatables_loader.js" in files
4640
assert build_dir / "DataTables-1.10.16" / "js" / "jquery.dataTables.min.js" in files
4741

48-
assert app.env.get_doctree("index") == snapshot_doctree
49-
5042

5143
@pytest.mark.skipif(
5244
sys.platform == "win32", reason="assert fails on windows, need to fix later."
5345
)
5446
@pytest.mark.parametrize(
5547
"test_app",
56-
[{"buildername": "html", "srcdir": "doc_test/generic_doc"}],
48+
[{"buildername": "html", "srcdir": "doc_test/doc_basic", "no_plantuml": True}],
5749
indirect=True,
5850
)
59-
def test_html_head_files(test_app):
51+
def test_html_head_files(test_app: SphinxTestApp):
6052
app = test_app
61-
app.builder.build_all()
62-
63-
from lxml import html as html_parser
53+
app.build()
54+
assert app._warning.getvalue() == ""
6455

6556
# check usage in project root level
6657
html_path = str(Path(app.outdir, "index.html"))
@@ -81,48 +72,64 @@ def test_html_head_files(test_app):
8172

8273
@pytest.mark.parametrize(
8374
"test_app",
84-
[{"buildername": "singlehtml", "srcdir": "doc_test/doc_basic"}],
75+
[
76+
{
77+
"buildername": "singlehtml",
78+
"srcdir": "doc_test/doc_basic",
79+
"no_plantuml": True,
80+
}
81+
],
8582
indirect=True,
8683
)
87-
def test_build_singlehtml(test_app):
84+
def test_build_singlehtml(test_app: SphinxTestApp):
8885
app = test_app
89-
app.builder.build_all()
86+
app.build()
87+
assert app._warning.getvalue() == ""
9088

9189

9290
@pytest.mark.parametrize(
9391
"test_app",
94-
[{"buildername": "latex", "srcdir": "doc_test/doc_basic"}],
92+
[{"buildername": "latex", "srcdir": "doc_test/doc_basic", "no_plantuml": True}],
9593
indirect=True,
9694
)
97-
def test_build_latex(test_app):
95+
def test_build_latex(test_app: SphinxTestApp):
9896
app = test_app
99-
app.builder.build_all()
97+
app.build()
98+
assert app._warning.getvalue() == ""
10099

101100

102101
@pytest.mark.parametrize(
103-
"test_app", [{"buildername": "epub", "srcdir": "doc_test/doc_basic"}], indirect=True
102+
"test_app",
103+
[{"buildername": "epub", "srcdir": "doc_test/doc_basic", "no_plantuml": True}],
104+
indirect=True,
104105
)
105-
def test_build_epub(test_app):
106+
def test_build_epub(test_app: SphinxTestApp):
106107
app = test_app
107-
app.builder.build_all()
108+
app.build()
109+
assert app._warning.getvalue() == ""
108110

109111

110112
@pytest.mark.parametrize(
111-
"test_app", [{"buildername": "json", "srcdir": "doc_test/doc_basic"}], indirect=True
113+
"test_app",
114+
[{"buildername": "json", "srcdir": "doc_test/doc_basic", "no_plantuml": True}],
115+
indirect=True,
112116
)
113-
def test_build_json(test_app):
117+
def test_build_json(test_app: SphinxTestApp):
114118
app = test_app
115-
app.builder.build_all()
119+
app.build()
120+
assert app._warning.getvalue() == ""
116121

117122

118123
@pytest.mark.parametrize(
119124
"test_app",
120-
[{"buildername": "needs", "srcdir": "doc_test/doc_basic"}],
125+
[{"buildername": "needs", "srcdir": "doc_test/doc_basic", "no_plantuml": True}],
121126
indirect=True,
122127
)
123-
def test_build_needs(test_app, snapshot):
128+
def test_build_needs(test_app: SphinxTestApp, snapshot):
124129
app = test_app
125-
app.builder.build_all()
130+
app.build()
131+
assert app._warning.getvalue() == ""
132+
126133
json_text = Path(app.outdir, "needs.json").read_text()
127134
needs_data = json.loads(json_text)
128135

@@ -137,14 +144,15 @@ def test_build_needs(test_app, snapshot):
137144
"buildername": "html",
138145
"srcdir": "doc_test/doc_basic",
139146
"confoverrides": {"needs_id_required": True},
147+
"no_plantuml": True,
140148
}
141149
],
142150
indirect=True,
143151
)
144-
def test_id_required_build_html(test_app):
152+
def test_id_required_build_html(test_app: SphinxTestApp):
145153
with pytest.raises(NeedsNoIdException):
146154
app = test_app
147-
app.builder.build_all()
155+
app.build()
148156

149157

150158
def test_sphinx_api_build(tmp_path: Path, make_app: type[SphinxTestApp]):

‎tests/test_test_doc.py

-16
This file was deleted.

0 commit comments

Comments
 (0)