@@ -313,14 +313,70 @@ def test_skip_identical_code(tmp_path: Path):
313313 assert "sphinx-codeautolink-a" in str (blocks [1 ])
314314
315315
316+ def test_dirhtml_builder (tmp_path : Path ):
317+ index = """
318+ Test project
319+ ============
320+
321+ .. toctree::
322+ :maxdepth: 2
323+
324+ page1/index
325+ page2
326+ subdir/page3
327+
328+ Index Page Code
329+ ---------------
330+
331+ .. code:: python
332+
333+ import test_project
334+ test_project.bar()
335+
336+ .. automodule:: test_project
337+ """
338+
339+ page = """
340+ Page {idx}
341+ ===========
342+
343+ .. code:: python
344+
345+ import test_project
346+ test_project.bar()
347+
348+ .. autolink-examples:: test_project.bar
349+ """
350+
351+ files = {
352+ "conf.py" : default_conf ,
353+ "index.rst" : index ,
354+ "page1/index.rst" : page .format (idx = 1 ),
355+ "page2.rst" : page .format (idx = 2 ),
356+ "subdir/page3.rst" : page .format (idx = 3 ),
357+ }
358+ links = ["test_project" , "test_project.bar" ]
359+
360+ result_dir = _sphinx_build (tmp_path , "dirhtml" , files )
361+
362+ assert_links (result_dir / "index.html" , links )
363+ assert_links (result_dir / "page1/index.html" , links )
364+ assert_links (result_dir / "page2/index.html" , links )
365+ assert_links (result_dir / "subdir/page3/index.html" , links )
366+
367+ assert check_link_targets (result_dir ) == len (links ) * 4
368+
369+
316370def _sphinx_build (
317371 folder : Path , builder : str , files : dict [str , str ], n_processes : int | None = None
318372) -> Path :
319373 """Build Sphinx documentation and return result folder."""
320374 src_dir = folder / "src"
321375 src_dir .mkdir (exist_ok = True )
322376 for name , content in files .items ():
323- (src_dir / name ).write_text (content , "utf-8" )
377+ path = src_dir / name
378+ path .parent .mkdir (exist_ok = True , parents = True )
379+ path .write_text (content , "utf-8" )
324380
325381 build_dir = folder / "build"
326382 args = ["-M" , builder , str (src_dir ), str (build_dir ), "-W" ]
0 commit comments