57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import csv
|
|
import importlib.util
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
CASES = REPO_ROOT / "skills" / "tester" / "scripts" / "generate_cases_csv.py"
|
|
RUNS = REPO_ROOT / "skills" / "tester" / "scripts" / "generate_run_csv.py"
|
|
sys.path.insert(0, str(RUNS.parent))
|
|
|
|
|
|
def load_module(name: str, path: Path):
|
|
spec = importlib.util.spec_from_file_location(name, path)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class TesterRunRecordTests(unittest.TestCase):
|
|
def test_cases_csv_contains_definitions_only(self) -> None:
|
|
cases = load_module("tester_cases_csv", CASES)
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
root = Path(temp)
|
|
cases_dir = root / ".pouch" / "tester" / "cases"
|
|
cases_dir.mkdir(parents=True)
|
|
(root / ".pouch" / "tester" / "catalog.yaml").write_text(
|
|
"categories:\n - id: smoke\n title: Smoke\n",
|
|
encoding="utf-8",
|
|
)
|
|
(cases_dir / "smoke.yaml").write_text(
|
|
"category: smoke\ncases:\n - id: TC-1\n title: One\n what: one\n lifecycle: active\n tag: smoke\n risk: readonly\n how: {steps: [open]}\n expected: [{kind: visible-text, value: ready}]\n",
|
|
encoding="utf-8",
|
|
)
|
|
output = cases.export_cases_csv(root)
|
|
with output.open(encoding="utf-8-sig", newline="") as handle:
|
|
rows = list(csv.DictReader(handle))
|
|
self.assertEqual(rows[0]["id"], "TC-1")
|
|
self.assertNotIn("last_result", rows[0])
|
|
self.assertNotIn("last_executed", rows[0])
|
|
|
|
def test_run_id_has_random_collision_suffix(self) -> None:
|
|
runs = load_module("tester_run_csv", RUNS)
|
|
first = runs.new_run_id("smoke")
|
|
second = runs.new_run_id("smoke")
|
|
self.assertNotEqual(first, second)
|
|
self.assertRegex(first, r"^\d{8}T\d{6}Z-smoke-[0-9a-f]{6}$")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|