3232any_whitespace = re .compile (r"\s*" )
3333ref_tests = [(p .name , p ) for p in Path (__file__ ).with_name ("ref" ).glob ("*.txt" )]
3434ref_xfails = {}
35+ builders = ["html" , "dirhtml" ]
3536
3637
3738def assert_links (file : Path , links : list ):
@@ -46,7 +47,8 @@ def assert_links(file: Path, links: list):
4647
4748
4849@pytest .mark .parametrize (("name" , "file" ), ref_tests )
49- def test_references (name : str , file : Path , tmp_path : Path ):
50+ @pytest .mark .parametrize ("builder" , builders )
51+ def test_references (name : str , file : Path , builder : str , tmp_path : Path ):
5052 """
5153 Basic extension tests for reference building.
5254
@@ -71,7 +73,7 @@ def test_references(name: str, file: Path, tmp_path: Path):
7173
7274 files = {"conf.py" : default_conf + conf , "index.rst" : index }
7375 print (f"Building file { name } ." )
74- result_dir = _sphinx_build (tmp_path , "html" , files )
76+ result_dir = _sphinx_build (tmp_path , builder , files )
7577
7678 assert_links (result_dir / "index.html" , links )
7779 assert check_link_targets (result_dir ) == len (links )
@@ -81,7 +83,8 @@ def test_references(name: str, file: Path, tmp_path: Path):
8183
8284
8385@pytest .mark .parametrize ("file" , table_tests )
84- def test_tables (file : Path , tmp_path : Path ):
86+ @pytest .mark .parametrize ("builder" , builders )
87+ def test_tables (file : Path , builder : str , tmp_path : Path ):
8588 """
8689 Tests for backreference tables.
8790
@@ -107,7 +110,7 @@ def test_tables(file: Path, tmp_path: Path):
107110 links = []
108111
109112 files = {"conf.py" : default_conf + conf , "index.rst" : index }
110- result_dir = _sphinx_build (tmp_path , "html" , files )
113+ result_dir = _sphinx_build (tmp_path , builder , files )
111114
112115 index_html = result_dir / "index.html"
113116 text = index_html .read_text ("utf-8" )
@@ -124,7 +127,8 @@ def test_tables(file: Path, tmp_path: Path):
124127
125128
126129@pytest .mark .parametrize ("file" , fail_tests )
127- def test_fails (file : Path , tmp_path : Path ):
130+ @pytest .mark .parametrize ("builder" , builders )
131+ def test_fails (file : Path , builder : str , tmp_path : Path ):
128132 """
129133 Tests for failing builds.
130134
@@ -138,7 +142,7 @@ def test_fails(file: Path, tmp_path: Path):
138142 conf , index = file .read_text ("utf-8" ).split ("# split" )
139143 files = {"conf.py" : default_conf + conf , "index.rst" : index }
140144 with pytest .raises (RuntimeError ):
141- _sphinx_build (tmp_path , "html" , files )
145+ _sphinx_build (tmp_path , builder , files )
142146
143147
144148def test_non_html_build (tmp_path : Path ):
@@ -158,7 +162,8 @@ def test_non_html_build(tmp_path: Path):
158162 _sphinx_build (tmp_path , "man" , files )
159163
160164
161- def test_build_twice_and_modify_one_file (tmp_path : Path ):
165+ @pytest .mark .parametrize ("builder" , builders )
166+ def test_build_twice_and_modify_one_file (builder : str , tmp_path : Path ):
162167 index = """
163168Test project
164169------------
@@ -187,11 +192,12 @@ def test_build_twice_and_modify_one_file(tmp_path: Path):
187192.. autolink-examples:: test_package.bar
188193"""
189194 files = {"conf.py" : default_conf , "index.rst" : index , "another.rst" : another }
190- _sphinx_build (tmp_path , "html" , files )
191- _sphinx_build (tmp_path , "html" , {"another.rst" : another2 })
195+ _sphinx_build (tmp_path , builder , files )
196+ _sphinx_build (tmp_path , builder , {"another.rst" : another2 })
192197
193198
194- def test_build_twice_and_delete_one_file (tmp_path : Path ):
199+ @pytest .mark .parametrize ("builder" , builders )
200+ def test_build_twice_and_delete_one_file (builder : str , tmp_path : Path ):
195201 conf = default_conf + "\n suppress_warnings = ['toc.not_readable']"
196202 index = """
197203Test project
@@ -215,12 +221,13 @@ def test_build_twice_and_delete_one_file(tmp_path: Path):
215221"""
216222
217223 files = {"conf.py" : conf , "index.rst" : index , "another.rst" : another }
218- _sphinx_build (tmp_path , "html" , files )
224+ _sphinx_build (tmp_path , builder , files )
219225 (tmp_path / "src" / "another.rst" ).unlink ()
220- _sphinx_build (tmp_path , "html" , {})
226+ _sphinx_build (tmp_path , builder , {})
221227
222228
223- def test_raise_unexpected (tmp_path : Path ):
229+ @pytest .mark .parametrize ("builder" , builders )
230+ def test_raise_unexpected (builder : str , tmp_path : Path ):
224231 index = """
225232Test project
226233------------
@@ -243,13 +250,14 @@ def raise_nomsg(*_, **__):
243250
244251 target = "sphinx_codeautolink.parse.ImportTrackerVisitor"
245252 with pytest .raises (RuntimeError ), patch (target , raise_msg ):
246- _sphinx_build (tmp_path , "html" , files )
253+ _sphinx_build (tmp_path , builder , files )
247254
248255 with pytest .raises (RuntimeError ), patch (target , raise_nomsg ):
249- _sphinx_build (tmp_path , "html" , files )
256+ _sphinx_build (tmp_path , builder , files )
250257
251258
252- def test_parallel_build (tmp_path : Path ):
259+ @pytest .mark .parametrize ("builder" , builders )
260+ def test_parallel_build (builder : str , tmp_path : Path ):
253261 index = """
254262Test project
255263------------
@@ -274,14 +282,19 @@ def test_parallel_build(tmp_path: Path):
274282 index = index + "\n " .join (["" , * list (subfiles )])
275283 files = {"conf.py" : default_conf , "index.rst" : index }
276284 files .update ({k + ".rst" : v for k , v in subfiles .items ()})
277- result_dir = _sphinx_build (tmp_path , "html" , files , n_processes = 4 )
285+ result_dir = _sphinx_build (tmp_path , builder , files , n_processes = 4 )
278286
279287 for file in subfiles :
280- assert_links (result_dir / (file + ".html" ), links )
288+ if builder == "dirhtml" and file != "index" :
289+ assert_links (result_dir / file / "index.html" , links )
290+ else :
291+ assert_links (result_dir / (file + ".html" ), links )
292+
281293 assert check_link_targets (result_dir ) == n_subfiles * len (links )
282294
283295
284- def test_skip_identical_code (tmp_path : Path ):
296+ @pytest .mark .parametrize ("builder" , builders )
297+ def test_skip_identical_code (builder : str , tmp_path : Path ):
285298 """Code skipped and then linked in an identical block after."""
286299 index = """
287300Test project
@@ -301,7 +314,7 @@ def test_skip_identical_code(tmp_path: Path):
301314.. automodule:: test_project
302315"""
303316 files = {"conf.py" : default_conf , "index.rst" : index }
304- result_dir = _sphinx_build (tmp_path , "html" , files )
317+ result_dir = _sphinx_build (tmp_path , builder , files )
305318
306319 index_html = result_dir / "index.html"
307320 text = index_html .read_text ("utf-8" )
0 commit comments