Debian Codegraph @

tests/test_builders/test_incremental_reading.py

raw
1 """Test the Builder class."""
2
3 from __future__ import annotations
4
5 import sys
6 from typing import TYPE_CHECKING
7
8 import pytest
9
10 if TYPE_CHECKING:
11 from sphinx.testing.util import SphinxTestApp
12
13
14 @pytest.mark.sphinx(
15 'dummy',
16 testroot='root',
17 srcdir='test_builder',
18 freshenv=True,
19 )
20 def test_incremental_reading(app: SphinxTestApp) -> None:
21 # first reading
22 updated = app.builder.read()
23 assert set(updated) == app.env.found_docs == set(app.env.all_docs)
24 assert updated == sorted(updated) # sorted by alphanumeric
25
26 # test if exclude_patterns works ok
27 assert 'subdir/excluded' not in app.env.found_docs
28
29 # before second reading, add, modify and remove source files
30 (app.srcdir / 'new.txt').write_text('New file\n========\n', encoding='utf8')
31 app.env.all_docs['index'] = 0 # mark as modified
32 (app.srcdir / 'autodoc.txt').unlink()
33
34 # second reading
35 updated = app.builder.read()
36
37 assert set(updated) == {'index', 'new'}
38 assert 'autodoc' not in app.env.all_docs
39 assert 'autodoc' not in app.env.found_docs
40
41
42 @pytest.mark.sphinx(
43 'dummy',
44 testroot='warnings',
45 freshenv=True,
46 )
47 def test_incremental_reading_for_missing_files(app: SphinxTestApp) -> None:
48 # first reading
49 updated = app.builder.read()
50 assert set(updated) == app.env.found_docs == set(app.env.all_docs)
51
52 # second reading
53 updated = app.builder.read()
54
55 # "index" is listed up to updated because it contains references
56 # to nonexisting downloadable or image files
57 assert set(updated) == {'index'}
58
59 sys.modules.pop('autodoc_fodder', None)