Build the shared test site into a directory that is made new, with a test, and give the zip archives fixed member times so equal files make equal bytes

This commit is contained in:
swaits committed 2026-11-20 16:33:34 -07:00
1 parent c645159ae7
commit 5d86a42ad1
3 files changed
+58 -4

No files matched your search

+4 -1
View File
@@ -32,7 +32,10 @@ _built = bool(PREBUILT)
def build(out, *extra, env=None):
"""Run the site build into out (a directory that need not exist). Raises when it fails."""
"""Run the site build into out, a directory that is made new: whatever was there is removed first,
so nothing in it can be a page an earlier build (of another branch, say) wrote and this one
does not. Raises when the build fails."""
shutil.rmtree(out, ignore_errors=True)
done = subprocess.run([sys.executable, os.path.join(WEB, "build.py"), "--out", out, *extra],
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True, env=env)
if done.returncode:
+41
View File
@@ -0,0 +1,41 @@
"""The shared test build is always a fresh one: nothing in the directory tests read can be left over
from an earlier build, such as a page that another branch wrote and this one does not."""
import os
import subprocess
import sys
import tempfile
import unittest
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import builtsite # noqa: E402
class FreshBuildTest(unittest.TestCase):
def test_a_page_left_by_an_earlier_build_is_not_there_when_the_next_build_starts(self):
with tempfile.TemporaryDirectory() as tmp:
out = os.path.join(tmp, "site")
os.makedirs(os.path.join(out, "regions", "gone"))
for rel in (os.path.join("regions", "gone", "index.html"), "old.json"):
with open(os.path.join(out, rel), "w") as f:
f.write("left over")
seen = []
def fake_build(cmd, **kwargs):
seen.append(sorted(os.listdir(out)) if os.path.isdir(out) else None)
os.makedirs(out, exist_ok=True)
return subprocess.CompletedProcess(cmd, 0, "", "")
with mock.patch.object(builtsite.subprocess, "run", fake_build):
builtsite.build(out)
self.assertIn(seen[0], (None, []))
self.assertEqual(os.listdir(out), [])
def test_the_shared_site_is_in_a_directory_named_for_this_process(self):
if not builtsite.PREBUILT:
self.assertTrue(builtsite.OUT.endswith(f"test-site-{os.getpid()}"))
if __name__ == "__main__":
unittest.main()