1"""
2    test_builder
3    ~~~~~~~~
4
5    Test the Builder class.
6
7    :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
8    :license: BSD, see LICENSE for details.
9"""
10import pytest
11
12
13@pytest.mark.sphinx('dummy', srcdir="test_builder", freshenv=True)
14def test_incremental_reading(app):
15    # first reading
16    updated = app.builder.read()
17    assert set(updated) == app.env.found_docs == set(app.env.all_docs)
18    assert updated == sorted(updated)  # sorted by alphanumeric
19
20    # test if exclude_patterns works ok
21    assert 'subdir/excluded' not in app.env.found_docs
22
23    # before second reading, add, modify and remove source files
24    (app.srcdir / 'new.txt').write_text('New file\n========\n')
25    app.env.all_docs['index'] = 0  # mark as modified
26    (app.srcdir / 'autodoc.txt').unlink()
27
28    # second reading
29    updated = app.builder.read()
30
31    assert set(updated) == {'index', 'new'}
32    assert 'autodoc' not in app.env.all_docs
33    assert 'autodoc' not in app.env.found_docs
34
35
36@pytest.mark.sphinx('dummy', testroot='warnings', freshenv=True)
37def test_incremental_reading_for_missing_files(app):
38    # first reading
39    updated = app.builder.read()
40    assert set(updated) == app.env.found_docs == set(app.env.all_docs)
41
42    # second reading
43    updated = app.builder.read()
44
45    # "index" is listed up to updated because it contains references
46    # to nonexisting downloadable or image files
47    assert set(updated) == {'index'}
48