refactor: compute an export apart from writing it

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 16:43:46 +01:00
1 parent 745ab63e63
commit b018681f06
5 files changed
+102 -47

No files matched your search

+7 -7
View File
@@ -21,6 +21,7 @@ from pathlib import Path
from core import upstream
from core.cli import InputMissing
from exporter.native import ExportResult
from exporter.originals import SOURCES_INDEX
from freshness.catalogs import (
NO_INTRO_MIRROR,
@@ -188,16 +189,15 @@ class PublishedExportTests(unittest.TestCase):
self.published = Path(self._tmp.name)
(self.published / "plat").mkdir()
(self.published / "plat" / "list.txt").write_text("a", encoding="utf-8")
(self.published / "plat.json").write_text("{}", encoding="utf-8")
(self.published / "plat.json").write_text("{}\n", encoding="utf-8")
def _state(self, written: str, ok: bool = True) -> str:
def fake(platform, _cls, _truth, output, *_rest):
(output / platform).mkdir(parents=True)
(output / platform / "list.txt").write_text(written, encoding="utf-8")
(output / f"{platform}.json").write_text("{}", encoding="utf-8")
return ok, [] if ok else ["the platform's own file is required"]
def fake(platform, *_rest):
if not ok:
return ExportResult(platform, False, ["the platform's own file is required"])
return ExportResult(platform, True, [], {"list.txt": written}, report={})
with mock.patch("freshness.native.export_platform", fake):
with mock.patch("freshness.native.build_export", fake):
return published_export_state(
"plat", object, Path("t"), Path("p"), Path("c"), self.published
)
+13 -11
View File
@@ -17,7 +17,7 @@ from pathlib import Path
from exporter import native
from exporter.landed import landed_changes
from exporter.native import current_truth, export_platform, write_report
from exporter.native import build_export, current_truth, write_report
from model.profiles import load_emulator_profiles
from sitegen.exports import generate_exports_page, load_export_reports
@@ -56,8 +56,8 @@ class ExportReportIsWrittenAndRead(unittest.TestCase):
def test_export_keeps_every_change_not_the_printed_five(self):
source = (ROOT / "scripts" / "exporter" / "native.py").read_text(encoding="utf-8")
body = source[source.index("def export_platform("):source.index("def write_report(")]
call = body[body.index("write_report("):]
body = source[source.index("def build_export("):source.index("def write_report(")]
call = body[body.index("ExportResult(platform, True"):]
for key, value in (
("hashes_updated", "applied"), ("hashes_filled", "filled"),
("sizes_updated", "resized"), ("sizes_removed", "unsized"),
@@ -223,12 +223,14 @@ class TheRunReportStatesWhatTheFileCarries(unittest.TestCase):
mock.patch.object(native, "unpinned", return_value=[]), \
mock.patch.object(native, "removal_candidates", return_value=[]), \
mock.patch.object(native, "doubled_in", return_value=[doubled]):
ok, messages = export_platform(
"plat", Plain, Path(scratch), Path(scratch) / "out",
str(ROOT / "platforms"), Path(scratch) / "cache", False,
result = build_export(
"plat", Plain, Path(scratch), str(ROOT / "platforms"),
Path(scratch) / "cache", False,
)
self.assertTrue(ok, messages)
report = json.loads((Path(scratch) / "out" / "plat.json").read_text())
messages = result.messages
self.assertTrue(result.ok, messages)
report = result.report
assert report is not None
self.assertEqual(report["doubled"], [doubled])
self.assertIn(
"1 destination declared twice for two files, listed in the report", messages
@@ -469,7 +471,7 @@ class ThePageShowsEachValueBeforeAndAfter(unittest.TestCase):
def test_the_report_carries_every_change(self):
source = (ROOT / "scripts" / "exporter" / "native.py").read_text(encoding="utf-8")
body = source[source.index("def export_platform("):source.index("def write_report(")]
body = source[source.index("def build_export("):source.index("def write_report(")]
self.assertIn('"changes": changes.records,', body)
@@ -578,7 +580,7 @@ class RemovalCandidatesNeedAReadingNoCoreAnswers(unittest.TestCase):
def test_the_report_carries_the_list(self):
source = (ROOT / "scripts" / "exporter" / "native.py").read_text(encoding="utf-8")
body = source[source.index("def export_platform("):source.index("def write_report(")]
body = source[source.index("def build_export("):source.index("def write_report(")]
self.assertIn('"removal_candidates": candidates,', body)
@@ -675,7 +677,7 @@ class ADestinationDeclaredTwiceIsNamed(unittest.TestCase):
def test_the_run_counts_it_and_the_report_carries_it(self):
source = (ROOT / "scripts" / "exporter" / "native.py").read_text(encoding="utf-8")
body = source[source.index("def export_platform("):source.index("def write_report(")]
body = source[source.index("def build_export("):source.index("def write_report(")]
self.assertIn('"doubled": doubled,', body)
self.assertIn("declared twice for two files", body)
+1 -1
View File
@@ -1618,7 +1618,7 @@ class AnExportLeavesNoStaleFile(unittest.TestCase):
def test_the_export_clears_before_it_writes(self):
source = (REPO_ROOT / "scripts" / "exporter" / "native.py").read_text()
body = source[source.index("def export_platform("):]
body = source[source.index("def write_export("):]
self.assertLess(body.index("_remove_stale("), body.index("_write_produced("))