Build the site once per test run, and split every page into tags once, for all the tests that read built pages
Twelve test modules each ran the whole build, and each of them walked every page with its own parser. They now share one build (web/tests/builtsite.py), made in a directory of the run's own, and one recording of each page, made on all the cores. test_thumbs's second build and test_google_tag's two builds still build, on their own, as before; the google tag builds run side by side. web/tests/run.py runs the modules side by side. test_extra's elevation tile check now compares with the last entry of connect-src, which is where the tile path is since the Google tag added three before it. New tests keep the build's shortcuts honest (test_build_store.py). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
84d5770e13
commit
7c321c6e15
16 files changed
+561
-87
No files matched your search
+19
-16
@@ -3,7 +3,6 @@ import contextlib
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -15,7 +14,9 @@ sys.path.insert(0, WEB)
|
||||
|
||||
from olt import records, thumbs # noqa: E402
|
||||
|
||||
OUT = os.path.join(WEB, ".cache", "test-site")
|
||||
import builtsite # noqa: E402
|
||||
|
||||
OUT = builtsite.OUT
|
||||
MAX_SIDE = 256
|
||||
|
||||
|
||||
@@ -29,11 +30,15 @@ class Imgs(HTMLParser):
|
||||
self.imgs.append(dict(attrs))
|
||||
|
||||
|
||||
_imgs = {}
|
||||
|
||||
|
||||
def page_imgs(path):
|
||||
p = Imgs()
|
||||
with open(path, encoding="utf-8") as f:
|
||||
p.feed(f.read())
|
||||
return p.imgs
|
||||
"""The <img> tags of a page, read once per run (the tests only look at the result)."""
|
||||
stamp = (os.path.abspath(path), os.stat(path).st_mtime_ns)
|
||||
if stamp not in _imgs:
|
||||
_imgs[stamp] = builtsite.feed(path, Imgs()).imgs
|
||||
return _imgs[stamp]
|
||||
|
||||
|
||||
def html_files(out):
|
||||
@@ -63,11 +68,6 @@ def repository_logos():
|
||||
return found
|
||||
|
||||
|
||||
def build():
|
||||
subprocess.run([sys.executable, os.path.join(WEB, "build.py"), "--out", OUT],
|
||||
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
|
||||
class ThumbFilesTest(unittest.TestCase):
|
||||
def test_every_repository_logo_has_a_thumbnail_no_larger_than_256(self):
|
||||
logos = repository_logos()
|
||||
@@ -147,8 +147,7 @@ class ThumbFilesTest(unittest.TestCase):
|
||||
class BuiltPagesTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
os.makedirs(os.path.dirname(OUT), exist_ok=True)
|
||||
build()
|
||||
builtsite.ensure()
|
||||
cls.records = records.load_records(ROOT)
|
||||
cls.png = [r["id"] for r in cls.records
|
||||
if r["derived"]["files"].get("shield", "").endswith(".png")]
|
||||
@@ -195,9 +194,13 @@ class BuiltPagesTest(unittest.TestCase):
|
||||
self.assertEqual(img.get("loading"), "lazy")
|
||||
|
||||
def test_thumbnails_survive_a_second_build(self):
|
||||
build()
|
||||
for tid in self.png:
|
||||
self.assertTrue(os.path.isfile(os.path.join(OUT, "trails", tid, thumbs.THUMB_NAME)), tid)
|
||||
# A build over a site that is already built, on a copy: the shared one is never written to.
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
again = os.path.join(tmp, "site")
|
||||
shutil.copytree(OUT, again)
|
||||
builtsite.build(again)
|
||||
for tid in self.png:
|
||||
self.assertTrue(os.path.isfile(os.path.join(again, "trails", tid, thumbs.THUMB_NAME)), tid)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user