added
This commit is contained in:
commit
df52f578a2
47 files changed
+7328
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# Tests
|
||||
|
||||
Run:
|
||||
|
||||
```text
|
||||
python -m unittest discover -s tests -p "test_*.py"
|
||||
```
|
||||
|
||||
Tests validate the current repository and protect failure cases including identity mismatch, duplicate content IDs, missing indexed reports, and incorrect weekly-report indexing.
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
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"]
|
||||
)
|
||||
)
|
||||
|
||||
def test_duplicate_content_id_fails(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
copy = Path(directory) / "repository"
|
||||
shutil.copytree(ROOT, copy, ignore=shutil.ignore_patterns(".git", "__pycache__"))
|
||||
index_path = copy / "content-index.json"
|
||||
index = json.loads(index_path.read_text(encoding="utf-8"))
|
||||
duplicate = dict(index["items"][0])
|
||||
duplicate["path"] = "docs/README.md"
|
||||
index["items"].append(duplicate)
|
||||
index_path.write_text(json.dumps(index, indent=2) + "\n", encoding="utf-8")
|
||||
result = VALIDATOR.validate(copy)
|
||||
self.assertFalse(result["passed"])
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Duplicate content_id in content-index.json" in item["message"]
|
||||
for item in result["findings"]
|
||||
)
|
||||
)
|
||||
|
||||
def test_missing_indexed_content_fails(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
copy = Path(directory) / "repository"
|
||||
shutil.copytree(ROOT, copy, ignore=shutil.ignore_patterns(".git", "__pycache__"))
|
||||
index_path = copy / "content-index.json"
|
||||
index = json.loads(index_path.read_text(encoding="utf-8"))
|
||||
index["items"][0]["path"] = "docs/missing-document.md"
|
||||
index_path.write_text(json.dumps(index, indent=2) + "\n", encoding="utf-8")
|
||||
result = VALIDATOR.validate(copy)
|
||||
self.assertFalse(result["passed"])
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Indexed content path does not exist" in item["message"]
|
||||
for item in result["findings"]
|
||||
)
|
||||
)
|
||||
|
||||
def test_unindexed_report_fails(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
copy = Path(directory) / "repository"
|
||||
shutil.copytree(ROOT, copy, ignore=shutil.ignore_patterns(".git", "__pycache__"))
|
||||
report = copy / "outdoor-brand-email-analysis" / "2099-01-01-outdoor-brand-innovation-intelligence-report.md"
|
||||
report.write_text("# Synthetic Test Report\n", encoding="utf-8")
|
||||
result = VALIDATOR.validate(copy)
|
||||
self.assertFalse(result["passed"])
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Report is absent from content-index.json" in item["message"]
|
||||
for item in result["findings"]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user