2018-02-23 10:16:27 -06:00
|
|
|
"""Test the Builder class."""
|
2024-01-18 17:55:43 -06:00
|
|
|
|
2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-01-18 17:55:43 -06:00
|
|
|
import sys
|
|
|
|
|
2018-02-23 10:16:27 -06:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'dummy',
|
2024-08-12 16:34:03 -05:00
|
|
|
testroot='root',
|
2024-08-11 08:58:56 -05:00
|
|
|
srcdir='test_builder',
|
|
|
|
freshenv=True,
|
|
|
|
)
|
2018-02-23 10:16:27 -06:00
|
|
|
def test_incremental_reading(app):
|
|
|
|
# first reading
|
|
|
|
updated = app.builder.read()
|
|
|
|
assert set(updated) == app.env.found_docs == set(app.env.all_docs)
|
2019-02-03 07:10:43 -06:00
|
|
|
assert updated == sorted(updated) # sorted by alphanumeric
|
2018-02-23 10:16:27 -06:00
|
|
|
|
|
|
|
# test if exclude_patterns works ok
|
|
|
|
assert 'subdir/excluded' not in app.env.found_docs
|
|
|
|
|
|
|
|
# before second reading, add, modify and remove source files
|
2022-04-26 21:11:08 -05:00
|
|
|
(app.srcdir / 'new.txt').write_text('New file\n========\n', encoding='utf8')
|
2018-09-03 07:38:31 -05:00
|
|
|
app.env.all_docs['index'] = 0 # mark as modified
|
2018-02-23 10:16:27 -06:00
|
|
|
(app.srcdir / 'autodoc.txt').unlink()
|
|
|
|
|
|
|
|
# second reading
|
|
|
|
updated = app.builder.read()
|
|
|
|
|
2019-03-17 14:49:36 -05:00
|
|
|
assert set(updated) == {'index', 'new'}
|
2018-02-23 10:16:27 -06:00
|
|
|
assert 'autodoc' not in app.env.all_docs
|
|
|
|
assert 'autodoc' not in app.env.found_docs
|
|
|
|
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'dummy',
|
|
|
|
testroot='warnings',
|
|
|
|
freshenv=True,
|
|
|
|
)
|
2019-02-03 07:10:43 -06:00
|
|
|
def test_incremental_reading_for_missing_files(app):
|
|
|
|
# first reading
|
|
|
|
updated = app.builder.read()
|
|
|
|
assert set(updated) == app.env.found_docs == set(app.env.all_docs)
|
2018-02-23 10:16:27 -06:00
|
|
|
|
2019-02-03 07:10:43 -06:00
|
|
|
# second reading
|
|
|
|
updated = app.builder.read()
|
2018-02-23 10:16:27 -06:00
|
|
|
|
2019-02-03 07:10:43 -06:00
|
|
|
# "index" is listed up to updated because it contains references
|
|
|
|
# to nonexisting downloadable or image files
|
2019-03-17 14:49:36 -05:00
|
|
|
assert set(updated) == {'index'}
|
2024-01-18 17:55:43 -06:00
|
|
|
|
|
|
|
sys.modules.pop('autodoc_fodder', None)
|