mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 20:38:52 -06:00
refactor: move schema checks into a package
This commit is contained in:
1 parent
1227152bef
commit
5fa802a3c5
34 files changed
+1367
-1168
No files matched your search
@@ -88,6 +88,13 @@ COMMANDS = {
|
||||
"sitesources.py": ("sitegen/sources.py",),
|
||||
"site_markdown.py": ("sitegen/pagemarkdown.py",),
|
||||
"validate_site.py": ("sitegen/validate.py",),
|
||||
"validate_schemas.py": (
|
||||
"schemas/validators.py", "schemas/sources.py", "schemas/profilechecks.py",
|
||||
"schemas/citations.py", "schemas/platformchecks.py", "schemas/sourcetree.py",
|
||||
"schemas/registry.py", "schemas/documents.py", "schemas/installs.py",
|
||||
"schemas/packmanifests.py", "schemas/events.py", "schemas/measurements.py",
|
||||
"schemas/romfolders.py", "schemas/games.py", "schemas/run.py",
|
||||
),
|
||||
"site_insights.py": ("sitegen/insights.py",),
|
||||
"generate_readme.py": ("sitegen/readme.py",),
|
||||
"romset_recipes.py": (
|
||||
|
||||
@@ -412,9 +412,9 @@ class CommittedIndex(unittest.TestCase):
|
||||
"""A bumped profile kept the game-to-BIOS map of the old code."""
|
||||
from unittest import mock
|
||||
|
||||
import validate_schemas
|
||||
from schemas import games
|
||||
|
||||
self.assertEqual(validate_schemas._arcade_pin_errors(), [])
|
||||
self.assertEqual(games.arcade_pin_errors(), [])
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
(root / "games" / "arcade").mkdir(parents=True)
|
||||
@@ -423,8 +423,8 @@ class CommittedIndex(unittest.TestCase):
|
||||
f"source_commit: {'b' * 40}\ncore_version: '0.2'\n")
|
||||
(root / "games" / "arcade" / "core.json").write_text(json.dumps(
|
||||
{"profile": "core", "core_version": "0.1", "source": {"commit": COMMIT}}))
|
||||
with mock.patch.object(validate_schemas, "REPO_ROOT", root):
|
||||
(error,) = validate_schemas._arcade_pin_errors()
|
||||
with mock.patch("core.paths.REPO_ROOT", root):
|
||||
(error,) = games.arcade_pin_errors()
|
||||
self.assertIn("read at aaaaaaaaaaaa", error)
|
||||
self.assertIn("core_version '0.1'", error)
|
||||
self.assertIn("arcade_parent_importer --profile core", error)
|
||||
|
||||
@@ -472,9 +472,9 @@ class UnreachableCitationRegressions(unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(HAS_JSONSCHEMA, "validating a schema needs jsonschema")
|
||||
def _hits(self, text: str) -> bool:
|
||||
import validate_schemas
|
||||
from schemas import citations
|
||||
|
||||
return bool(validate_schemas._UNREACHABLE_REF.search(" " + text))
|
||||
return bool(citations.UNREACHABLE_REF.search(" " + text))
|
||||
|
||||
def test_a_scratch_directory_is_rejected(self):
|
||||
self.assertTrue(self._hits("tmp/es-de/ANDROID.md:470-474"))
|
||||
@@ -499,13 +499,13 @@ class UnreachableCitationRegressions(unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(HAS_JSONSCHEMA, "validating a schema needs jsonschema")
|
||||
def test_the_corpus_carries_none(self):
|
||||
import validate_schemas
|
||||
from schemas import citations
|
||||
|
||||
errors = []
|
||||
for path in sorted((ROOT / "emulators").glob("*.yml")):
|
||||
with path.open(encoding="utf-8") as handle:
|
||||
errors.extend(
|
||||
validate_schemas._unreachable_citations(path, yaml.safe_load(handle))
|
||||
citations.unreachable_citations(path, yaml.safe_load(handle))
|
||||
)
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
@@ -517,9 +517,9 @@ class DoubledCitationPaths(unittest.TestCase):
|
||||
showed it to the citation checks."""
|
||||
|
||||
def _hits(self, text: str) -> bool:
|
||||
import validate_schemas
|
||||
from schemas import citations
|
||||
|
||||
return bool(validate_schemas._DOUBLED_PATH.search(text))
|
||||
return bool(citations.DOUBLED_PATH.search(text))
|
||||
|
||||
def test_a_repeated_directory_is_rejected(self):
|
||||
self.assertTrue(self._hits(
|
||||
@@ -537,11 +537,11 @@ class DoubledCitationPaths(unittest.TestCase):
|
||||
self.assertFalse(self._hits(good))
|
||||
|
||||
def test_the_corpus_carries_none(self):
|
||||
import validate_schemas
|
||||
from schemas import citations
|
||||
|
||||
errors = []
|
||||
for path in sorted((ROOT / "emulators").glob("*.yml")):
|
||||
errors.extend(validate_schemas._doubled_paths(path))
|
||||
errors.extend(citations.doubled_paths(path))
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
|
||||
@@ -1377,11 +1377,11 @@ class SchemaFormatsAreChecked(unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(HAS_JSONSCHEMA, "validating a schema needs jsonschema")
|
||||
def test_a_missing_checker_is_named(self):
|
||||
import validate_schemas
|
||||
from schemas import validators
|
||||
|
||||
empty = mock.Mock(checkers={})
|
||||
with mock.patch.object(validate_schemas, "FormatChecker", return_value=empty):
|
||||
self.assertEqual(validate_schemas.unchecked_formats(), ["date-time", "uri"])
|
||||
with mock.patch.object(validators, "FormatChecker", return_value=empty):
|
||||
self.assertEqual(validators.unchecked_formats(), ["date-time", "uri"])
|
||||
|
||||
def test_every_install_asks_for_the_extras(self):
|
||||
for path in (".github/workflows/validate.yml", ".github/workflows/deploy-site.yml",
|
||||
@@ -2162,7 +2162,7 @@ class InstallerBoundaryRegressions(unittest.TestCase):
|
||||
A filesystem glob over dist/ matches nothing and reports success
|
||||
without validating a single document.
|
||||
"""
|
||||
import validate_schemas
|
||||
from schemas import packmanifests
|
||||
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
dist = Path(directory)
|
||||
@@ -2180,7 +2180,7 @@ class InstallerBoundaryRegressions(unittest.TestCase):
|
||||
with zipfile.ZipFile(dist / "Pack.zip", "w") as archive:
|
||||
archive.writestr("manifest.json", json.dumps(broken))
|
||||
|
||||
errors = validate_schemas._validate_pack_manifests(dist)
|
||||
errors = packmanifests.validate_pack_manifests(dist)
|
||||
self.assertTrue(errors, "an invalid in-archive manifest must be reported")
|
||||
self.assertTrue(any("sha1" in message for message in errors), errors)
|
||||
|
||||
@@ -2191,7 +2191,7 @@ class InstallerBoundaryRegressions(unittest.TestCase):
|
||||
alone. The pack schema refused both keys, and each is checked under
|
||||
its own contract."""
|
||||
from packs import scope
|
||||
import validate_schemas
|
||||
from schemas import packmanifests
|
||||
|
||||
install_list = json.loads((ROOT / "install" / "romm.json").read_text(encoding="utf-8"))
|
||||
targets = {"browser": None, "rpi4": {"cores": ["mgba"], "images": ["rpi4"]}}
|
||||
@@ -2210,13 +2210,13 @@ class InstallerBoundaryRegressions(unittest.TestCase):
|
||||
dist = Path(directory)
|
||||
with zipfile.ZipFile(dist / "Pack.zip", "w") as archive:
|
||||
archive.writestr("manifest.json", json.dumps(document))
|
||||
self.assertEqual(validate_schemas._validate_pack_manifests(dist), [])
|
||||
self.assertEqual(packmanifests.validate_pack_manifests(dist), [])
|
||||
|
||||
broken = {**document, "targets": {"rpi4": [1]},
|
||||
"install_list": {**install_list, "files": "none"}}
|
||||
with zipfile.ZipFile(dist / "Pack.zip", "w") as archive:
|
||||
archive.writestr("manifest.json", json.dumps(broken))
|
||||
errors = validate_schemas._validate_pack_manifests(dist)
|
||||
errors = packmanifests.validate_pack_manifests(dist)
|
||||
self.assertTrue(any(":targets:" in message for message in errors), errors)
|
||||
self.assertTrue(any(":install_list:" in message for message in errors), errors)
|
||||
|
||||
@@ -3905,8 +3905,8 @@ class ModuleConstantsDeclaredOnce(unittest.TestCase):
|
||||
|
||||
class OnlyTheSchemaValidatorNeedsJsonschema(unittest.TestCase):
|
||||
"""Build scripts and install.py run on stdlib plus pyyaml, and jsonschema is
|
||||
tooling for validate_schemas and CI. An import anywhere else turns a
|
||||
contributor's pipeline run into an ImportError."""
|
||||
tooling for the schemas package behind validate_schemas and CI. An import
|
||||
anywhere else turns a contributor's pipeline run into an ImportError."""
|
||||
|
||||
@staticmethod
|
||||
def _imports_jsonschema(source: str) -> bool:
|
||||
@@ -3925,7 +3925,7 @@ class OnlyTheSchemaValidatorNeedsJsonschema(unittest.TestCase):
|
||||
offenders = [
|
||||
str(path.relative_to(ROOT))
|
||||
for path in sorted(ROOT.glob("scripts/**/*.py")) + [ROOT / "install.py"]
|
||||
if path.name != "validate_schemas.py"
|
||||
if path.parent != ROOT / "scripts" / "schemas"
|
||||
and self._imports_jsonschema(path.read_text())
|
||||
]
|
||||
self.assertEqual(offenders, [])
|
||||
@@ -3945,14 +3945,14 @@ class HashMergeBackupsAreNotSources(unittest.TestCase):
|
||||
|
||||
def test_the_validator_skips_a_backup(self):
|
||||
try:
|
||||
from validate_schemas import _validate_yaml_directory
|
||||
from schemas.sourcetree import validate_yaml_directory
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
(Path(directory) / "mame.old.yml").write_text("emulator: [\n")
|
||||
self.assertEqual(
|
||||
_validate_yaml_directory(Path(directory), "emulator.schema.json"), []
|
||||
validate_yaml_directory(Path(directory), "emulator.schema.json"), []
|
||||
)
|
||||
|
||||
def test_the_backup_suffix_is_written_once(self):
|
||||
@@ -6161,7 +6161,7 @@ class AProfilePathIsTheEmulatorsNotOurs(unittest.TestCase):
|
||||
from unittest import mock
|
||||
|
||||
try:
|
||||
from scripts import validate_schemas
|
||||
from schemas import sourcetree
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
|
||||
@@ -6172,8 +6172,8 @@ class AProfilePathIsTheEmulatorsNotOurs(unittest.TestCase):
|
||||
"emulator: X\nfiles:\n - name: scph1001.bin\n"
|
||||
" path: .variants/scph1001.bin.abc12345\n"
|
||||
)
|
||||
with mock.patch.object(validate_schemas, "REPO_ROOT", Path(directory)):
|
||||
errors = validate_schemas._repository_layout_in_profiles()
|
||||
with mock.patch("core.paths.REPO_ROOT", Path(directory)):
|
||||
errors = sourcetree.repository_layout_in_profiles()
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn(".variants/", errors[0])
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
class ChecksHaveValues(unittest.TestCase):
|
||||
def setUp(self):
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import profilechecks
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
self.check = validate_schemas._checks_without_values
|
||||
self.check = profilechecks.checks_without_values
|
||||
|
||||
def test_a_valueless_check_is_named(self):
|
||||
path = REPO_ROOT / "emulators" / "x.yml"
|
||||
|
||||
+10
-10
@@ -17,10 +17,10 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
class DataDirRefsAreRegistered(unittest.TestCase):
|
||||
def test_no_unknown_ref(self):
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import sourcetree
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
self.assertEqual(validate_schemas._unknown_data_dir_refs(), [])
|
||||
self.assertEqual(sourcetree.unknown_data_dir_refs(), [])
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class EachSourceIsParsedOnce(unittest.TestCase):
|
||||
from unittest import mock
|
||||
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import sources, sourcetree
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -44,15 +44,15 @@ class EachSourceIsParsedOnce(unittest.TestCase):
|
||||
(root / "emulators" / "core.yml").write_text(
|
||||
"emulator: Core\nfiles:\n- name: a.bin\n path: .variants/a.bin\n")
|
||||
loaded = []
|
||||
real = validate_schemas.yaml_load
|
||||
with mock.patch.object(validate_schemas, "REPO_ROOT", root), \
|
||||
mock.patch.object(validate_schemas, "yaml_load",
|
||||
real = sources.yaml_load
|
||||
with mock.patch("core.paths.REPO_ROOT", root), \
|
||||
mock.patch.object(sources, "yaml_load",
|
||||
side_effect=lambda h: loaded.append(h.name) or real(h)):
|
||||
validate_schemas._validate_yaml_directory(root / "emulators", "emulator.schema.json")
|
||||
validate_schemas._unknown_data_dir_refs()
|
||||
layout = validate_schemas._repository_layout_in_profiles()
|
||||
sourcetree.validate_yaml_directory(root / "emulators", "emulator.schema.json")
|
||||
sourcetree.unknown_data_dir_refs()
|
||||
layout = sourcetree.repository_layout_in_profiles()
|
||||
# _data_dirs.yml is read by model.registry.load_data_dir_registry, so
|
||||
# only the profile passes through validate_schemas' own loader.
|
||||
# only the profile passes through the schema checks' own loader.
|
||||
self.assertEqual(sorted(Path(n).name for n in loaded), ["core.yml"])
|
||||
self.assertEqual(len(layout), 1)
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ from pathlib import Path
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import citations, sources
|
||||
except ImportError as exc:
|
||||
validate_schemas = None
|
||||
citations = sources = None
|
||||
IMPORT_ERROR = str(exc)
|
||||
else:
|
||||
IMPORT_ERROR = ""
|
||||
@@ -22,12 +22,12 @@ def _profile(ref: object) -> dict:
|
||||
return {"files": [{"name": "doom.wad", "source_ref": ref}]}
|
||||
|
||||
|
||||
@unittest.skipIf(validate_schemas is None, f"validate_schemas unavailable: {IMPORT_ERROR}")
|
||||
@unittest.skipIf(citations is None, f"the schema checks are unavailable: {IMPORT_ERROR}")
|
||||
class DataOnlySourceRefs(unittest.TestCase):
|
||||
path = REPO_ROOT / "emulators" / "synthetic.yml"
|
||||
|
||||
def errors(self, ref: object) -> list[str]:
|
||||
return validate_schemas._data_only_source_refs(self.path, _profile(ref))
|
||||
return citations.data_only_source_refs(self.path, _profile(ref))
|
||||
|
||||
def test_a_data_table_alone_is_refused(self):
|
||||
self.assertEqual(len(self.errors("wadsrc_extra/static/iwadinfo.txt:420, 437")), 1)
|
||||
@@ -78,15 +78,15 @@ class DataOnlySourceRefs(unittest.TestCase):
|
||||
|
||||
def test_an_excepted_profile_is_not_judged(self):
|
||||
path = REPO_ROOT / "emulators" / "synthetic.yml"
|
||||
exceptions = validate_schemas.DATA_ONLY_REF_EXCEPTIONS
|
||||
exceptions = citations.DATA_ONLY_REF_EXCEPTIONS
|
||||
exceptions["synthetic"] = "binary found nowhere"
|
||||
try:
|
||||
self.assertEqual(validate_schemas._data_only_source_refs(path, _profile("history.txt:38")), [])
|
||||
self.assertEqual(citations.data_only_source_refs(path, _profile("history.txt:38")), [])
|
||||
finally:
|
||||
del exceptions["synthetic"]
|
||||
|
||||
def test_every_exception_names_a_profile_and_a_reason(self):
|
||||
for name, reason in validate_schemas.DATA_ONLY_REF_EXCEPTIONS.items():
|
||||
for name, reason in citations.DATA_ONLY_REF_EXCEPTIONS.items():
|
||||
with self.subTest(profile=name):
|
||||
self.assertTrue((REPO_ROOT / "emulators" / f"{name}.yml").is_file())
|
||||
self.assertTrue(reason.strip())
|
||||
@@ -94,8 +94,8 @@ class DataOnlySourceRefs(unittest.TestCase):
|
||||
def test_the_profiles_cite_their_readers(self):
|
||||
errors: list[str] = []
|
||||
for path in sorted((REPO_ROOT / "emulators").glob("*.yml")):
|
||||
errors.extend(validate_schemas._data_only_source_refs(
|
||||
path, validate_schemas._load_source(path)))
|
||||
errors.extend(citations.data_only_source_refs(
|
||||
path, sources.load_source(path)))
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -7018,19 +7018,19 @@ class OneOfASearchList(unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(HAS_JSONSCHEMA, "validate_schemas needs jsonschema")
|
||||
def test_schema_refuses_a_set_split_on_required(self):
|
||||
from validate_schemas import _group_requirement_split
|
||||
from schemas.profilechecks import group_requirement_split
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
path = REPO_ROOT / "emulators" / "seq.yml"
|
||||
own_value = {"groups": {"g": {"required": True}},
|
||||
"files": [{"name": "a", "group": "g", "required": False},
|
||||
{"name": "b", "group": "g"}]}
|
||||
self.assertEqual(len(_group_requirement_split(path, own_value)), 1)
|
||||
self.assertEqual(len(group_requirement_split(path, own_value)), 1)
|
||||
undeclared_set = {"files": [{"name": "a", "group": "g"}]}
|
||||
self.assertEqual(len(_group_requirement_split(path, undeclared_set)), 1)
|
||||
self.assertEqual(len(group_requirement_split(path, undeclared_set)), 1)
|
||||
unused = {"groups": {"g": {"required": True}}, "files": [{"name": "a"}]}
|
||||
self.assertEqual(len(_group_requirement_split(path, unused)), 1)
|
||||
self.assertEqual(_group_requirement_split(path, self.raw), [])
|
||||
self.assertEqual(len(group_requirement_split(path, unused)), 1)
|
||||
self.assertEqual(group_requirement_split(path, self.raw), [])
|
||||
|
||||
def test_a_shared_fallback_takes_its_requirement_from_its_sets(self):
|
||||
"""pom2 falls back on apple2e.rom for the //e it boots by default
|
||||
|
||||
@@ -593,7 +593,7 @@ class ExpertRuns(Lists):
|
||||
from unittest import mock
|
||||
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import installs
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
|
||||
@@ -603,8 +603,8 @@ class ExpertRuns(Lists):
|
||||
json.dumps({**LIST, "truth_files": None}), encoding="utf-8")
|
||||
path = Path(root) / "install" / "standalone" / "retroarch.json"
|
||||
path.write_text(json.dumps(LAYOUTS), encoding="utf-8")
|
||||
with mock.patch.object(validate_schemas, "REPO_ROOT", Path(root)):
|
||||
self.assertEqual(validate_schemas._semantic_standalone_checks(path, LAYOUTS),
|
||||
with mock.patch("core.paths.REPO_ROOT", Path(root)):
|
||||
self.assertEqual(installs.semantic_standalone_checks(path, LAYOUTS),
|
||||
[])
|
||||
|
||||
def test_a_layout_file_missing_or_unreachable_refuses_on_one_line(self):
|
||||
|
||||
@@ -11,6 +11,7 @@ import tests
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import yaml
|
||||
|
||||
@@ -31,13 +32,17 @@ from resolve.launcherrefs import config_ref, is_feature_ref
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def schema_checks(test: unittest.TestCase):
|
||||
"""validate_schemas, or a skip: it needs jsonschema, the build does not."""
|
||||
def schema_checks(test: unittest.TestCase) -> SimpleNamespace:
|
||||
"""The launcher and config_reads checks, or a skip: they need jsonschema,
|
||||
the build does not."""
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import platformchecks, profilechecks
|
||||
except ImportError as exc:
|
||||
test.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
return validate_schemas
|
||||
return SimpleNamespace(
|
||||
config_records_without_evidence=platformchecks.config_records_without_evidence,
|
||||
config_reads_without_build=profilechecks.config_reads_without_build,
|
||||
)
|
||||
|
||||
|
||||
def record(**fields: object) -> dict:
|
||||
@@ -241,27 +246,27 @@ class StartScripts(unittest.TestCase):
|
||||
|
||||
class Invariants(unittest.TestCase):
|
||||
def test_a_config_record_without_its_platform_links_is_an_error(self) -> None:
|
||||
_config_records_without_evidence = schema_checks(self)._config_records_without_evidence
|
||||
config_records_without_evidence = schema_checks(self).config_records_without_evidence
|
||||
path = REPO_ROOT / "platforms" / "x.yml"
|
||||
bare = {k: v for k, v in record().items() if k not in ("installs", "overrides")}
|
||||
listed = record(source_ref="gen.cs:3, es_features.yml:9")
|
||||
errors = _config_records_without_evidence(path, {"launchers": [record(), bare, listed]})
|
||||
errors = config_records_without_evidence(path, {"launchers": [record(), bare, listed]})
|
||||
self.assertEqual(len(errors), 2)
|
||||
self.assertIn("without installs and overrides", errors[0])
|
||||
self.assertIn("choices_from holds it", errors[1])
|
||||
|
||||
def test_reads_naming_a_platform_need_its_build(self) -> None:
|
||||
_config_reads_without_build = schema_checks(self)._config_reads_without_build
|
||||
config_reads_without_build = schema_checks(self).config_reads_without_build
|
||||
path = REPO_ROOT / "emulators" / "x.yml"
|
||||
reads = [{"file": "a.ini", "platforms": ["rocknix"], "source_ref": "a:1", "keys": []}]
|
||||
self.assertEqual(len(_config_reads_without_build(path, {"config_reads": reads})), 1)
|
||||
self.assertEqual(_config_reads_without_build(
|
||||
self.assertEqual(len(config_reads_without_build(path, {"config_reads": reads})), 1)
|
||||
self.assertEqual(config_reads_without_build(
|
||||
path, {"config_reads": reads, "pin_build": [{"platform": "rocknix"}]}
|
||||
), [])
|
||||
pinned = [{**reads[0], "revision": "c" * 40, "revision_from": "the exe"}]
|
||||
self.assertEqual(_config_reads_without_build(path, {"config_reads": pinned}), [])
|
||||
self.assertEqual(config_reads_without_build(path, {"config_reads": pinned}), [])
|
||||
closed = [{**reads[0], "binary_sha256": "d" * 64, "revision_from": "the archive"}]
|
||||
self.assertEqual(_config_reads_without_build(path, {"config_reads": closed}), [])
|
||||
self.assertEqual(config_reads_without_build(path, {"config_reads": closed}), [])
|
||||
|
||||
|
||||
class ShippedBuild(unittest.TestCase):
|
||||
@@ -395,13 +400,13 @@ class RepositoryRecords(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_every_config_record_carries_its_platform_links(self) -> None:
|
||||
_config_records_without_evidence = schema_checks(self)._config_records_without_evidence
|
||||
config_records_without_evidence = schema_checks(self).config_records_without_evidence
|
||||
for path in sorted((REPO_ROOT / "platforms").glob("*.yml")):
|
||||
if path.name.startswith("_"):
|
||||
continue
|
||||
with self.subTest(platform=path.stem):
|
||||
document = yaml.safe_load(path.read_text(encoding="utf-8"))
|
||||
self.assertEqual(_config_records_without_evidence(path, document), [])
|
||||
self.assertEqual(config_records_without_evidence(path, document), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -43,13 +43,10 @@ SIBLING_IMPORTS: dict[str, frozenset[str]] = {
|
||||
# The launcher archives are written by the pack member writer.
|
||||
"installer_build": frozenset({"packs"}),
|
||||
"devtools": frozenset(),
|
||||
"freshness": frozenset(),
|
||||
"orchestrate": frozenset(),
|
||||
"schemas": frozenset(),
|
||||
"collection": frozenset(),
|
||||
"games": frozenset(),
|
||||
# A job's commit subjects are checked against the repository's commit rules.
|
||||
"unattended": frozenset({"devtools"}),
|
||||
# The installer event schema is checked against the one the build writes.
|
||||
"schemas": frozenset({"installer_build"}),
|
||||
}
|
||||
|
||||
# Top-level files that stay whole at their path although packages import them:
|
||||
|
||||
@@ -650,10 +650,10 @@ class APickReadsTheEntrySystems(unittest.TestCase):
|
||||
|
||||
def test_the_schema_and_the_profile_list(self):
|
||||
try:
|
||||
from scripts import validate_schemas
|
||||
from schemas import profilechecks, validators
|
||||
except ImportError as exc:
|
||||
self.skipTest(f"validate_schemas needs jsonschema: {exc}")
|
||||
validator = validate_schemas._validator("emulator.schema.json")
|
||||
validator = validators.schema_validator("emulator.schema.json")
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
base = {"emulator": "x", "type": "libretro", "systems": ["a", "b"]}
|
||||
both = {**base, "files": [{"name": "x.zip", "system": "a", "systems": ["a", "b"]}]}
|
||||
@@ -663,16 +663,16 @@ class APickReadsTheEntrySystems(unittest.TestCase):
|
||||
fine = {**base, "files": [{"name": "x.zip", "systems": ["a", "b"]}]}
|
||||
self.assertEqual(list(validator.iter_errors(fine)), [])
|
||||
outside = {**base, "files": [{"name": "x.zip", "systems": ["a", "c"]}]}
|
||||
found = validate_schemas._systems_outside_profile(root / "emulators" / "x.yml", outside)
|
||||
found = profilechecks.systems_outside_profile(root / "emulators" / "x.yml", outside)
|
||||
self.assertEqual(len(found), 1)
|
||||
self.assertIn("system c", found[0])
|
||||
single = {**base, "files": [{"name": "x.zip", "system": "c"}]}
|
||||
found = validate_schemas._systems_outside_profile(root / "emulators" / "x.yml", single)
|
||||
found = profilechecks.systems_outside_profile(root / "emulators" / "x.yml", single)
|
||||
self.assertEqual(len(found), 1)
|
||||
self.assertIn("system c", found[0])
|
||||
listed = {**base, "files": [{"name": "x.zip", "system": "a"}]}
|
||||
self.assertEqual(
|
||||
validate_schemas._systems_outside_profile(root / "emulators" / "x.yml", listed), []
|
||||
profilechecks.systems_outside_profile(root / "emulators" / "x.yml", listed), []
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -343,14 +343,14 @@ class ReadAndIndex(Workspace):
|
||||
from jsonschema import Draft202012Validator
|
||||
except ImportError:
|
||||
self.skipTest("jsonschema is not installed")
|
||||
import validate_schemas
|
||||
from schemas import measurements
|
||||
|
||||
self.assertEqual(validate_schemas._measurement_errors(self.tree), [])
|
||||
self.assertEqual(measurements.measurement_errors(self.tree), [])
|
||||
lines = self.tree / mr.records_path("beta")
|
||||
record = json.loads(lines.read_text())
|
||||
record["kind"] = "guess"
|
||||
lines.write_text(mr.line_text(record) + "\n")
|
||||
errors = validate_schemas._measurement_errors(self.tree)
|
||||
errors = measurements.measurement_errors(self.tree)
|
||||
self.assertTrue(any("measurements/beta.jsonl:1" in e and "kind" in e for e in errors), errors)
|
||||
self.assertIsNotNone(Draft202012Validator)
|
||||
|
||||
@@ -375,20 +375,20 @@ class ReadAndIndex(Workspace):
|
||||
def test_a_version_4_record_needs_its_verdicts(self) -> None:
|
||||
if importlib.util.find_spec("jsonschema") is None:
|
||||
self.skipTest("jsonschema is not installed")
|
||||
import validate_schemas
|
||||
from schemas import measurements
|
||||
|
||||
lines = self.tree / mr.records_path("beta")
|
||||
record = json.loads(lines.read_text())
|
||||
del record["variants"][0]["verdict"]
|
||||
del record["variants"][0]["repetitions"][0]["verdict_evidence"]
|
||||
lines.write_text(mr.line_text(record) + "\n")
|
||||
errors = validate_schemas._measurement_errors(self.tree)
|
||||
errors = measurements.measurement_errors(self.tree)
|
||||
self.assertTrue(any("'verdict' is a required property" in e for e in errors), errors)
|
||||
self.assertTrue(any("'verdict_evidence' is a required property" in e for e in errors), errors)
|
||||
old = {**record, "record_version": 3}
|
||||
lines.write_text(mr.line_text(old) + "\n")
|
||||
self.assertFalse(any("required property" in e
|
||||
for e in validate_schemas._measurement_errors(self.tree)))
|
||||
for e in measurements.measurement_errors(self.tree)))
|
||||
|
||||
|
||||
class AppendOnly(Workspace):
|
||||
|
||||
@@ -35,7 +35,7 @@ sys.exit(0 if result.wasSuccessful() else 1)
|
||||
"""
|
||||
|
||||
|
||||
IMPORTS_SCHEMA_CODE = re.compile(r"^\s*(?:import|from)\s+(?:jsonschema|validate_schemas)\b", re.M)
|
||||
IMPORTS_SCHEMA_CODE = re.compile(r"^\s*(?:import|from)\s+(?:jsonschema|validate_schemas|schemas)\b", re.M)
|
||||
|
||||
|
||||
class SuiteWithoutJsonschema(unittest.TestCase):
|
||||
@@ -91,7 +91,8 @@ def _runtime_nodes(node: ast.AST) -> Iterator[ast.AST]:
|
||||
|
||||
def _foreign_imports(source: str, file_name: str, local: set[str]) -> list[str]:
|
||||
"""The top-level packages a script imports at run time beyond the
|
||||
standard library, pyyaml and the repository's own modules."""
|
||||
standard library, pyyaml and the repository's own modules. ``file_name``
|
||||
is the path under scripts/."""
|
||||
allowed = {"yaml"}
|
||||
found = []
|
||||
for node in _runtime_nodes(ast.parse(source)):
|
||||
@@ -104,7 +105,7 @@ def _foreign_imports(source: str, file_name: str, local: set[str]) -> list[str]:
|
||||
for name in names:
|
||||
if name in sys.stdlib_module_names or name in local or name in allowed:
|
||||
continue
|
||||
if name == "jsonschema" and file_name == "validate_schemas.py":
|
||||
if name == "jsonschema" and file_name.startswith("schemas/"):
|
||||
continue
|
||||
if MAINTENANCE_TOOLS.get(file_name) == name:
|
||||
continue
|
||||
@@ -114,9 +115,10 @@ def _foreign_imports(source: str, file_name: str, local: set[str]) -> list[str]:
|
||||
|
||||
class ScriptsNeedOnlyPyyaml(unittest.TestCase):
|
||||
"""The build scripts need the standard library and pyyaml. jsonschema is
|
||||
validate_schemas.py's alone. CI installs jsonschema with its whole tree
|
||||
(attrs, referencing, rpds-py), so an import of any of them would pass
|
||||
there and fail for a contributor following the documented setup."""
|
||||
the schemas package's alone, behind validate_schemas.py. CI installs
|
||||
jsonschema with its whole tree (attrs, referencing, rpds-py), so an
|
||||
import of any of them would pass there and fail for a contributor
|
||||
following the documented setup."""
|
||||
|
||||
def test_no_script_imports_another_package(self):
|
||||
scripts = Path(__file__).resolve().parents[1] / "scripts"
|
||||
@@ -129,7 +131,8 @@ class ScriptsNeedOnlyPyyaml(unittest.TestCase):
|
||||
found = [
|
||||
f"{path.relative_to(scripts)}: {name}"
|
||||
for path in sorted(scripts.rglob("*.py"))
|
||||
for name in _foreign_imports(path.read_text(encoding="utf-8"), path.name, local)
|
||||
for name in _foreign_imports(path.read_text(encoding="utf-8"),
|
||||
path.relative_to(scripts).as_posix(), local)
|
||||
]
|
||||
self.assertEqual(found, [])
|
||||
|
||||
|
||||
@@ -180,12 +180,12 @@ class ThePlatformNamesItsSaveDirectory(unittest.TestCase):
|
||||
"userdata-saves/atari2600/stella/KVS1.WAV")
|
||||
self.assertEqual(SaveLayout("saves", True).in_pack, "saves")
|
||||
try:
|
||||
from validate_schemas import _bios_tree_below
|
||||
from schemas.registry import bios_tree_below
|
||||
except ImportError:
|
||||
self.skipTest("validate_schemas needs jsonschema")
|
||||
self.assertEqual(_bios_tree_below("batocera", "saves"),
|
||||
self.assertEqual(bios_tree_below("batocera", "saves"),
|
||||
"saves/dolphin-emu/Triforce/segaboot.gcm")
|
||||
self.assertEqual(_bios_tree_below("batocera", "userdata-saves"), "")
|
||||
self.assertEqual(bios_tree_below("batocera", "userdata-saves"), "")
|
||||
|
||||
def test_the_systems_a_core_runs_for(self):
|
||||
from packs.paths import libretro_systems
|
||||
@@ -750,14 +750,14 @@ class TheInstallerWritesThem(unittest.TestCase):
|
||||
class TheProfilesFollowTheContract(unittest.TestCase):
|
||||
def test_every_save_dir_entry_has_a_library_name(self):
|
||||
try:
|
||||
from validate_schemas import _save_dir_without_library_name
|
||||
from schemas.profilechecks import save_dir_without_library_name
|
||||
except ImportError:
|
||||
self.skipTest("validate_schemas needs jsonschema")
|
||||
|
||||
for path in sorted((REPO_ROOT / "emulators").glob("*.yml")):
|
||||
document = yaml.safe_load(path.read_text(encoding="utf-8"))
|
||||
with self.subTest(profile=path.name):
|
||||
self.assertEqual(_save_dir_without_library_name(path, document), [])
|
||||
self.assertEqual(save_dir_without_library_name(path, document), [])
|
||||
|
||||
def test_azahar_reads_its_user_folder_below_the_save_directory(self):
|
||||
profile = yaml.safe_load((REPO_ROOT / "emulators" / "azahar.yml").read_text())
|
||||
@@ -769,11 +769,11 @@ class TheProfilesFollowTheContract(unittest.TestCase):
|
||||
|
||||
def test_the_registry_blocks(self):
|
||||
try:
|
||||
from validate_schemas import _save_directory_blocks
|
||||
from schemas.registry import save_directory_blocks
|
||||
except ImportError:
|
||||
self.skipTest("validate_schemas needs jsonschema")
|
||||
|
||||
self.assertEqual(_save_directory_blocks(), [])
|
||||
self.assertEqual(save_directory_blocks(), [])
|
||||
|
||||
def test_the_published_retroarch_list_places_azahar(self):
|
||||
manifest = json.loads((REPO_ROOT / "install" / "retroarch.json").read_text())
|
||||
|
||||
@@ -17,6 +17,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
try:
|
||||
import validate_schemas
|
||||
from schemas import documents, installs
|
||||
except ImportError as exc:
|
||||
validate_schemas = None
|
||||
IMPORT_ERROR = str(exc)
|
||||
@@ -50,7 +51,7 @@ class SemanticManifestValidation(unittest.TestCase):
|
||||
)
|
||||
|
||||
output = io.StringIO()
|
||||
with mock.patch.object(validate_schemas, "REPO_ROOT", root), mock.patch.object(
|
||||
with mock.patch("core.paths.REPO_ROOT", root), mock.patch.object(
|
||||
sys, "argv", ["validate_schemas.py"]
|
||||
), redirect_stdout(output):
|
||||
result = validate_schemas.main()
|
||||
@@ -85,10 +86,10 @@ class SemanticManifestValidation(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory(dir=REPO_ROOT) as directory:
|
||||
path = Path(directory) / "synthetic.json"
|
||||
path.write_text(json.dumps(manifest), encoding="utf-8")
|
||||
errors = validate_schemas._validate_json_files(
|
||||
errors = documents.validate_json_files(
|
||||
[path],
|
||||
"install-manifest.schema.json",
|
||||
validate_schemas._semantic_install_checks,
|
||||
installs.semantic_install_checks,
|
||||
)
|
||||
|
||||
self.assertEqual(len(errors), 1)
|
||||
@@ -105,7 +106,7 @@ class SemanticManifestValidation(unittest.TestCase):
|
||||
def errors(omitted: list[dict]) -> list[str]:
|
||||
manifest = {"files": [], "total_files": 0, "total_size": 0,
|
||||
"omitted_files": omitted, "total_omitted": len(omitted)}
|
||||
return [e for e in validate_schemas._semantic_install_checks(path, manifest)
|
||||
return [e for e in installs.semantic_install_checks(path, manifest)
|
||||
if "omitted destinations" in e]
|
||||
|
||||
self.assertEqual(errors([omission("mame2015"), omission("mame2016")]), [])
|
||||
|
||||
Reference in new issue
Block a user