|
9 | 9 | from bs4 import BeautifulSoup |
10 | 10 | from sphinx.cmd.build import main as sphinx_main |
11 | 11 |
|
12 | | -from ._check import check_link_targets |
| 12 | +from ._check import check_link_targets, check_reference_targets_exist |
13 | 13 |
|
14 | 14 | # Insert test package root to path for all tests |
15 | 15 | sys.path.insert(0, str(Path(__file__).parent / "src")) |
@@ -365,6 +365,58 @@ def test_dirhtml_builder(tmp_path: Path): |
365 | 365 | assert_links(result_dir / "subdir/page3/index.html", links) |
366 | 366 |
|
367 | 367 | assert check_link_targets(result_dir) == len(links) * 4 |
| 368 | + check_reference_targets_exist(result_dir) |
| 369 | + |
| 370 | + |
| 371 | +def test_html_subdir_reference(tmp_path: Path): |
| 372 | + index = """ |
| 373 | +Test project |
| 374 | +============ |
| 375 | +
|
| 376 | +.. toctree:: |
| 377 | +
|
| 378 | + subdir/page1 |
| 379 | + subdir/subdir2/page2 |
| 380 | +
|
| 381 | +Index Page |
| 382 | +---------- |
| 383 | +
|
| 384 | +.. code:: python |
| 385 | +
|
| 386 | + import test_project |
| 387 | + test_project.bar() |
| 388 | +
|
| 389 | +.. automodule:: test_project |
| 390 | +""" |
| 391 | + |
| 392 | + page = """ |
| 393 | +Page {idx} |
| 394 | +=========== |
| 395 | +
|
| 396 | +.. code:: python |
| 397 | +
|
| 398 | + import test_project |
| 399 | + test_project.bar() |
| 400 | +
|
| 401 | +.. autolink-examples:: test_project.bar |
| 402 | +""" |
| 403 | + |
| 404 | + files = { |
| 405 | + "conf.py": default_conf, |
| 406 | + "index.rst": index, |
| 407 | + "subdir/page1.rst": page.format(idx=1), |
| 408 | + "subdir/subdir2/page2.rst": page.format(idx=2), |
| 409 | + } |
| 410 | + links = ["test_project", "test_project.bar"] |
| 411 | + |
| 412 | + result_dir = _sphinx_build(tmp_path, "html", files) |
| 413 | + |
| 414 | + assert_links(result_dir / "index.html", links) |
| 415 | + assert_links(result_dir / "subdir/page1.html", links) |
| 416 | + assert_links(result_dir / "subdir/subdir2/page2.html", links) |
| 417 | + |
| 418 | + assert check_link_targets(result_dir) == len(links) * 3 |
| 419 | + check_reference_targets_exist(result_dir) |
368 | 420 |
|
369 | 421 |
|
370 | 422 | def _sphinx_build( |
|
0 commit comments