added
This commit is contained in:
1 parent
eac3d5dc45
commit
2a2b00733b
83 files changed
+4840
No files matched your search
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VALIDATOR_PATH = ROOT / "scripts" / "validate_repository.py"
|
||||
SPEC = importlib.util.spec_from_file_location("validate_repository", VALIDATOR_PATH)
|
||||
VALIDATOR = importlib.util.module_from_spec(SPEC)
|
||||
assert SPEC.loader is not None
|
||||
SPEC.loader.exec_module(VALIDATOR)
|
||||
|
||||
|
||||
class RepositoryValidationTests(unittest.TestCase):
|
||||
def test_current_repository_passes(self) -> None:
|
||||
result = VALIDATOR.validate(ROOT)
|
||||
self.assertTrue(result["passed"], result["findings"])
|
||||
|
||||
def test_missing_repository_fails(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
result = VALIDATOR.validate(Path(directory))
|
||||
self.assertFalse(result["passed"])
|
||||
self.assertTrue(
|
||||
any("Missing required path" in item["message"] for item in result["findings"])
|
||||
)
|
||||
|
||||
def test_variable_identity_mismatch_fails(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
copy = Path(directory) / "repository"
|
||||
shutil.copytree(ROOT, copy, ignore=shutil.ignore_patterns(".git", "__pycache__"))
|
||||
variables_path = copy / "repository-variables.json"
|
||||
variables = json.loads(variables_path.read_text(encoding="utf-8"))
|
||||
variables["identity"]["publisher"]["name"] = "Different Publisher"
|
||||
variables_path.write_text(json.dumps(variables, indent=2) + "\n", encoding="utf-8")
|
||||
result = VALIDATOR.validate(copy)
|
||||
self.assertFalse(result["passed"])
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Publisher differs between repository-variables.json and repository.json"
|
||||
in item["message"]
|
||||
for item in result["findings"]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user