| 1 |
"""Test dirhtml builder.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import posixpath |
| 6 |
from typing import TYPE_CHECKING |
| 7 |
|
| 8 |
import pytest |
| 9 |
|
| 10 |
from sphinx.util.inventory import InventoryFile, _InventoryItem |
| 11 |
|
| 12 |
if TYPE_CHECKING: |
| 13 |
from sphinx.testing.util import SphinxTestApp |
| 14 |
|
| 15 |
|
| 16 |
@pytest.mark.sphinx('dirhtml', testroot='builder-dirhtml') |
| 17 |
def test_dirhtml(app: SphinxTestApp) -> None: |
| 18 |
app.build() |
| 19 |
|
| 20 |
assert (app.outdir / 'index.html').exists() |
| 21 |
assert (app.outdir / 'foo/index.html').exists() |
| 22 |
assert (app.outdir / 'foo/foo_1/index.html').exists() |
| 23 |
assert (app.outdir / 'foo/foo_2/index.html').exists() |
| 24 |
assert (app.outdir / 'bar/index.html').exists() |
| 25 |
|
| 26 |
content = (app.outdir / 'index.html').read_text(encoding='utf8') |
| 27 |
assert 'href="foo/"' in content |
| 28 |
assert 'href="foo/foo_1/"' in content |
| 29 |
assert 'href="foo/foo_2/"' in content |
| 30 |
assert 'href="bar/"' in content |
| 31 |
|
| 32 |
# objects.inv |
| 33 |
# See: https://github.com/sphinx-doc/sphinx/issues/7095 |
| 34 |
with (app.outdir / 'objects.inv').open('rb') as f: |
| 35 |
invdata = InventoryFile.load(f, 'path/to', posixpath.join) |
| 36 |
|
| 37 |
assert 'index' in invdata.get('std:doc', {}) |
| 38 |
assert invdata['std:doc']['index'] == _InventoryItem( |
| 39 |
project_name='Project name not set', |
| 40 |
project_version='', |
| 41 |
uri='path/to/', |
| 42 |
display_name='-', |
| 43 |
) |
| 44 |
|
| 45 |
assert 'foo/index' in invdata.get('std:doc', {}) |
| 46 |
assert invdata['std:doc']['foo/index'] == _InventoryItem( |
| 47 |
project_name='Project name not set', |
| 48 |
project_version='', |
| 49 |
uri='path/to/foo/', |
| 50 |
display_name='-', |
| 51 |
) |
| 52 |
|
| 53 |
assert 'index' in invdata.get('std:label', {}) |
| 54 |
assert invdata['std:label']['index'] == _InventoryItem( |
| 55 |
project_name='Project name not set', |
| 56 |
project_version='', |
| 57 |
uri='path/to/#index', |
| 58 |
display_name='-', |
| 59 |
) |
| 60 |
|
| 61 |
assert 'foo' in invdata.get('std:label', {}) |
| 62 |
assert invdata['std:label']['foo'] == _InventoryItem( |
| 63 |
project_name='Project name not set', |
| 64 |
project_version='', |
| 65 |
uri='path/to/foo/#foo', |
| 66 |
display_name='foo/index', |
| 67 |
) |