refactor: reuse the shared helpers left copied

Copies of helpers the first pass created, replaced by the helper:
- source_yaml_file for our YAML sources (generate_db read them in the
  locale's encoding, a syntax error named no file);
- data_dir_registry_at in registry_bundles, platform_registry_at (new,
  beside load_platform_registry) in the manifest;
- DATA_DIRS_FILE for the registry path five modules spelled;
- load_optional_database, sha1_at, VERSIONS_FILE, installer_module;
- DerivedView where a cache was keyed by id() of a dict;
- count_text and series where a plural or a list was written by hand.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:31:29 +01:00
1 parent 32a4ca1fa1
commit 036a6ebf29
35 files changed
+141 -170

No files matched your search

+2 -6
View File
@@ -1048,13 +1048,9 @@ class UnknownRegionSaysWhatToType(unittest.TestCase):
self.assertIn("Short forms: jp", message)
def test_the_installer_says_the_same(self):
import importlib.util
from installer_build.module import installer_module
spec = importlib.util.spec_from_file_location(
"install_under_test", Path(__file__).resolve().parents[1] / "install.py"
)
install = importlib.util.module_from_spec(spec)
spec.loader.exec_module(install)
install = installer_module()
with self.assertRaises(ValueError) as caught:
install.canonical_region("europ")
self.assertIn("Close matches: europe", str(caught.exception))
+3 -4
View File
@@ -11,7 +11,6 @@ from __future__ import annotations
import tests
import importlib.util
import json
import random
import re
@@ -19,11 +18,11 @@ import tempfile
import unittest
from pathlib import Path
from installer_build.module import installer_module
REPO_ROOT = Path(__file__).resolve().parents[1]
_spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py")
install = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(install)
install = installer_module()
PICKER = REPO_ROOT / "website" / "src" / "components" / "FilePicker.astro"
+2 -9
View File
@@ -43,12 +43,12 @@ import re
import unittest
from pathlib import Path
import yaml
import importlib.util
from sitegen import diagrams
from model.guides import INSTALL_SH
from tests import sitepages
from installer_build import port
from installer_build.module import installer_module
from release.check import SUMS, Asset, compare_release
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -932,13 +932,6 @@ class NoBackslashInProseCode(unittest.TestCase):
self.assertNotRegex(line, r"`[^`]*\\\|[^`]*`")
def _install_module():
spec = importlib.util.spec_from_file_location("install_r4wiki", REPO_ROOT / "install.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
class EventsTranscript(unittest.TestCase):
"""D10: the events table had no sample of what a run writes."""
@@ -948,7 +941,7 @@ class EventsTranscript(unittest.TestCase):
self.assertIsNotNone(block)
lines = block.group(1).splitlines()
self.assertEqual(len(lines), 5)
keys = _install_module().EVENT_KEYS
keys = installer_module().EVENT_KEYS
events = [json.loads(line) for line in lines]
for event in events:
with self.subTest(event=event["event"]):
+20
View File
@@ -250,5 +250,25 @@ class OfflinePipelineVerifiesOffline(unittest.TestCase):
self.assertIn('verify_cmd.append("--offline")', block)
class RegistryBundlesReadTheRegistry(unittest.TestCase):
"""registry_bundles read _data_dirs.yml by its own copy of the registry
reader: a missing file ended on FileNotFoundError and a syntax error
named no line."""
def test_bundles_and_a_missing_registry(self):
from core.cli import InputMissing
from release.assets import RELEASE_DOWNLOAD, registry_bundles
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp, "_data_dirs.yml")
path.write_text(yaml.safe_dump({"data_directories": {
"served": {"source_url": f"{RELEASE_DOWNLOAD}tree.zip", "description": "A tree"},
"upstream": {"source_url": "https://example.org/x.zip"},
}}), encoding="utf-8")
self.assertEqual(registry_bundles(str(path)), {"tree.zip": "A tree"})
with self.assertRaises(InputMissing):
registry_bundles(str(Path(tmp, "absent.yml")))
if __name__ == "__main__":
unittest.main()