6
6
from pathlib import Path
7
7
8
8
import pytest
9
+ from lxml import html as html_parser
9
10
from sphinx import version_info
10
- from sphinx .application import Sphinx
11
11
from sphinx .testing .util import SphinxTestApp
12
12
from syrupy .filters import props
13
13
14
14
from sphinx_needs .api .need import NeedsNoIdException
15
15
16
16
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
-
32
17
@pytest .mark .parametrize (
33
18
"test_app" ,
34
- [{"buildername" : "html" , "srcdir" : "doc_test/generic_doc" }],
19
+ [{"buildername" : "html" , "srcdir" : "doc_test/doc_basic" , "no_plantuml" : True }],
35
20
indirect = True ,
36
21
)
37
- def test_build_html_parallel (test_app : Sphinx , snapshot_doctree ):
22
+ def test_build_html (test_app : SphinxTestApp , snapshot_doctree ):
38
23
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
40
34
41
35
# Check if static files got copied correctly.
42
36
build_dir = Path (app .outdir ) / "_static" / "sphinx-needs" / "libs" / "html"
@@ -45,22 +39,19 @@ def test_build_html_parallel(test_app: Sphinx, snapshot_doctree):
45
39
assert build_dir / "datatables_loader.js" in files
46
40
assert build_dir / "DataTables-1.10.16" / "js" / "jquery.dataTables.min.js" in files
47
41
48
- assert app .env .get_doctree ("index" ) == snapshot_doctree
49
-
50
42
51
43
@pytest .mark .skipif (
52
44
sys .platform == "win32" , reason = "assert fails on windows, need to fix later."
53
45
)
54
46
@pytest .mark .parametrize (
55
47
"test_app" ,
56
- [{"buildername" : "html" , "srcdir" : "doc_test/generic_doc" }],
48
+ [{"buildername" : "html" , "srcdir" : "doc_test/doc_basic" , "no_plantuml" : True }],
57
49
indirect = True ,
58
50
)
59
- def test_html_head_files (test_app ):
51
+ def test_html_head_files (test_app : SphinxTestApp ):
60
52
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 () == ""
64
55
65
56
# check usage in project root level
66
57
html_path = str (Path (app .outdir , "index.html" ))
@@ -81,48 +72,64 @@ def test_html_head_files(test_app):
81
72
82
73
@pytest .mark .parametrize (
83
74
"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
+ ],
85
82
indirect = True ,
86
83
)
87
- def test_build_singlehtml (test_app ):
84
+ def test_build_singlehtml (test_app : SphinxTestApp ):
88
85
app = test_app
89
- app .builder .build_all ()
86
+ app .build ()
87
+ assert app ._warning .getvalue () == ""
90
88
91
89
92
90
@pytest .mark .parametrize (
93
91
"test_app" ,
94
- [{"buildername" : "latex" , "srcdir" : "doc_test/doc_basic" }],
92
+ [{"buildername" : "latex" , "srcdir" : "doc_test/doc_basic" , "no_plantuml" : True }],
95
93
indirect = True ,
96
94
)
97
- def test_build_latex (test_app ):
95
+ def test_build_latex (test_app : SphinxTestApp ):
98
96
app = test_app
99
- app .builder .build_all ()
97
+ app .build ()
98
+ assert app ._warning .getvalue () == ""
100
99
101
100
102
101
@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 ,
104
105
)
105
- def test_build_epub (test_app ):
106
+ def test_build_epub (test_app : SphinxTestApp ):
106
107
app = test_app
107
- app .builder .build_all ()
108
+ app .build ()
109
+ assert app ._warning .getvalue () == ""
108
110
109
111
110
112
@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 ,
112
116
)
113
- def test_build_json (test_app ):
117
+ def test_build_json (test_app : SphinxTestApp ):
114
118
app = test_app
115
- app .builder .build_all ()
119
+ app .build ()
120
+ assert app ._warning .getvalue () == ""
116
121
117
122
118
123
@pytest .mark .parametrize (
119
124
"test_app" ,
120
- [{"buildername" : "needs" , "srcdir" : "doc_test/doc_basic" }],
125
+ [{"buildername" : "needs" , "srcdir" : "doc_test/doc_basic" , "no_plantuml" : True }],
121
126
indirect = True ,
122
127
)
123
- def test_build_needs (test_app , snapshot ):
128
+ def test_build_needs (test_app : SphinxTestApp , snapshot ):
124
129
app = test_app
125
- app .builder .build_all ()
130
+ app .build ()
131
+ assert app ._warning .getvalue () == ""
132
+
126
133
json_text = Path (app .outdir , "needs.json" ).read_text ()
127
134
needs_data = json .loads (json_text )
128
135
@@ -137,14 +144,15 @@ def test_build_needs(test_app, snapshot):
137
144
"buildername" : "html" ,
138
145
"srcdir" : "doc_test/doc_basic" ,
139
146
"confoverrides" : {"needs_id_required" : True },
147
+ "no_plantuml" : True ,
140
148
}
141
149
],
142
150
indirect = True ,
143
151
)
144
- def test_id_required_build_html (test_app ):
152
+ def test_id_required_build_html (test_app : SphinxTestApp ):
145
153
with pytest .raises (NeedsNoIdException ):
146
154
app = test_app
147
- app .builder . build_all ()
155
+ app .build ()
148
156
149
157
150
158
def test_sphinx_api_build (tmp_path : Path , make_app : type [SphinxTestApp ]):
0 commit comments