forked from pyodide/sphinx-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_incremental.py
More file actions
102 lines (76 loc) · 2.95 KB
/
test_incremental.py
File metadata and controls
102 lines (76 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Test incremental builds."""
import warnings
from pathlib import Path
import pytest
from sphinx.environment import CONFIG_NEW, CONFIG_OK
try:
from sphinx.util.console import strip_colors
except ImportError:
from sphinx.testing.util import strip_escseq as strip_colors
def build(app):
"""Build the given app, collecting docnames read and written (resolved).
Returns a tuple (status text, [reads], [writes]), with reads and writes
sorted for convenience.
"""
reads = set([])
writes = set([])
def source_read(app, docname, source):
reads.add(docname)
def doctree_resolved(app, doctree, docname):
writes.add(docname)
source_read_id = app.connect("source-read", source_read)
doctree_resolved_id = app.connect("doctree-resolved", doctree_resolved)
try:
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
app.build()
finally:
app.disconnect(source_read_id)
app.disconnect(doctree_resolved_id)
return (
strip_colors(app._status.getvalue()),
list(sorted(reads)),
list(sorted(writes)),
)
def do_test(app, extension="js"):
# Clean build.
assert app.env.config_status == CONFIG_NEW
status, reads, writes = build(app)
assert reads == ["a", "a_b", "b", "index", "unrelated"]
assert writes == ["a", "a_b", "b", "index", "unrelated"]
# Incremental build, no config changed and no files changed.
assert app.env.config_status == CONFIG_OK
status, reads, writes = build(app)
assert reads == []
assert writes == []
# Incremental build, one file changed.
a_js = Path(app.srcdir) / f"a.{extension}"
a_js.write_text(a_js.read_text() + "\n\n")
assert app.env.config_status == CONFIG_OK
status, reads, writes = build(app)
# FIXME: re-enable the rest of this test!
return
assert reads == ["a", "a_b"]
# Note that the transitive dependency 'index' is written.
assert writes == ["a", "a_b", "index"]
# Incremental build, the other file changed.
b_js = Path(app.srcdir) / "inner" / f"b.{extension}"
b_js.write_text(b_js.read_text() + "\n\n")
assert app.env.config_status == CONFIG_OK
status, reads, writes = build(app)
assert reads == ["a_b", "b"]
# Note that the transitive dependency 'index' is written.
assert writes == ["a_b", "b", "index"]
# We must use a "real" builder since the `dummy` builder does not track changed
# files.
@pytest.mark.sphinx("html", testroot="incremental_js")
def test_incremental_js(make_app, app_params):
args, kwargs = app_params
app = make_app(*args, freshenv=True, **kwargs)
do_test(app, extension="js")
@pytest.mark.xfail(reason="TODO: fix me!")
@pytest.mark.sphinx("html", testroot="incremental_ts")
def test_incremental_ts(make_app, app_params):
args, kwargs = app_params
app = make_app(*args, freshenv=True, **kwargs)
do_test(app, extension="ts")