Skip to content

Commit 5685bd9

Browse files
committed
Add a test
1 parent 75eb76a commit 5685bd9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/test_general_tags.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,43 @@ def test_empty_taglinks():
106106
msg = "No tags passed to 'tags' directive"
107107
with pytest.raises(ExtensionError, match=msg):
108108
tag_links.run()
109+
110+
111+
@pytest.mark.sphinx("text", testroot="rst", confoverrides={"tags_create_tags": True})
112+
def test_tag_page_cache(app: SphinxTestApp):
113+
"""
114+
This test attempts to check that when doing an incremental rebuild
115+
of sphinx the built tags are updated.
116+
117+
We do a build, then modify the tag list in one of the tag files
118+
and it should change the output on the second build.
119+
"""
120+
app.build(force_all=True)
121+
build_dir = Path(app.srcdir) / "_build" / "text"
122+
123+
# Check all expected tag pages
124+
for tag in ["tag_1", "tag2", "tag-3", "tag-4", "tag_5", "test-tag-please-ignore"]:
125+
contents = build_dir / "_tags" / f"{tag}.txt"
126+
expected_contents = OUTPUT_DIR / "_tags" / f"{tag}.txt"
127+
with open(contents, "r") as actual, open(expected_contents, "r") as expected:
128+
assert actual.readlines() == expected.readlines()
129+
130+
# Modify a source file
131+
with open(Path(app.srcdir) / "page_1.rst") as fobj:
132+
contents = fobj.readlines()
133+
contents[-1] = ".. tags:: tag_1, tag2"
134+
135+
with open(Path(app.srcdir) / "page_1.rst", mode="w+") as fobj:
136+
fobj.writelines(contents)
137+
138+
app.build(force_all=True)
139+
build_dir = Path(app.srcdir) / "_build" / "text"
140+
141+
# Check all expected tag pages
142+
for tag in ["tag-3", "tag-4"]:
143+
contents = build_dir / "_tags" / f"{tag}.txt"
144+
expected_contents = OUTPUT_DIR / "_tags" / f"{tag}.txt"
145+
with open(contents, "r") as actual, open(expected_contents, "r") as expected:
146+
actual_lines = actual.readlines()
147+
assert "* Page 1\n" not in actual_lines
148+
assert actual_lines != expected.readlines()

0 commit comments

Comments
 (0)