32 lines
1020 B
Python
32 lines
1020 B
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
import importlib.util
|
||
|
|
from pathlib import Path
|
||
|
|
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"])
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|