55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
import tempfile
|
|
import unittest
|
|
from contextlib import redirect_stdout
|
|
from io import StringIO
|
|
from pathlib import Path
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
CATALOG = REPO_ROOT / "skills" / "tester" / "scripts" / "catalog.py"
|
|
|
|
|
|
def load_catalog_module():
|
|
spec = importlib.util.spec_from_file_location("tester_catalog", CATALOG)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class TesterCatalogRootTests(unittest.TestCase):
|
|
def test_discovers_parent_and_nested_project_without_merging_cases(self) -> None:
|
|
catalog = load_catalog_module()
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
root = Path(temp)
|
|
for project, name in ((root, "backend"), (root / "app", "Writes")):
|
|
(project / ".pouch" / "tester").mkdir(parents=True)
|
|
(project / ".pouch" / "tester" / "catalog.yaml").write_text(
|
|
f"project:\n name: {name}\n", encoding="utf-8"
|
|
)
|
|
|
|
self.assertEqual(catalog.discover_catalog_roots(root), [root, root / "app"])
|
|
|
|
def test_roots_command_reports_each_catalog_path(self) -> None:
|
|
catalog = load_catalog_module()
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
root = Path(temp)
|
|
app = root / "app" / ".pouch" / "tester"
|
|
app.mkdir(parents=True)
|
|
(app / "catalog.yaml").write_text("project:\n name: Writes\n", encoding="utf-8")
|
|
output = StringIO()
|
|
with redirect_stdout(output):
|
|
self.assertEqual(catalog.cmd_roots(root), 0)
|
|
payload = json.loads(output.getvalue())
|
|
self.assertEqual(payload["count"], 1)
|
|
self.assertEqual(payload["roots"][0]["relative"], "app")
|
|
self.assertEqual(payload["roots"][0]["project"], "Writes")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|