Files
cdsl-cad/cadfs_to_cdsl/tests/test_reports.py
T

55 lines
2.5 KiB
Python

from __future__ import annotations
import json, tempfile, unittest
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from cadfs_to_cdsl.dataset import Sample
from cadfs_to_cdsl.operation_registry import build_operation_registry
from cadfs_to_cdsl.reports import generate_markdown_report, write_json
class ReportTests(unittest.TestCase):
def test_parallel_json_writes_use_unique_temporary_paths(self):
with tempfile.TemporaryDirectory() as temporary:
path = Path(temporary) / "summary.json"
with ThreadPoolExecutor(max_workers=8) as executor:
list(executor.map(lambda index: write_json(path, {"index": index}), range(64)))
payload = json.loads(path.read_text(encoding="utf-8"))
self.assertIn(payload["index"], range(64))
self.assertEqual(list(path.parent.glob(".summary.json.*.tmp")), [])
def test_operation_registry_distinguishes_absent_roadmap_work_items(self):
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
source = root / "00000001.txt"
source.write_text(
'FeatureScript 1511; export const f = defineFeature(function(context, id, definition) {'
' extrude(context, id + "F1", {"depth": 1 * mm}); });',
encoding="utf-8",
)
registry = build_operation_registry([Sample("00000001", files={"featurescript": str(source)})])
self.assertEqual(registry["schema"], "cadfs_to_cdsl.operation_registry.v1")
self.assertEqual(registry["operations"]["extrude"]["feature_count"], 1)
self.assertEqual(registry["operations"]["transform"]["state"], "not_observed_in_current_source")
self.assertEqual(registry["operations"]["thicken"]["feature_count"], 0)
def test_markdown_report_uses_source_registry_instead_of_static_operation_claims(self):
with tempfile.TemporaryDirectory() as temporary:
output = Path(temporary)
write_json(output / "operation_registry.json", {
"operations": {
"transform": {"roadmap_work_item": True, "state": "observed"},
"thicken": {"roadmap_work_item": True, "state": "not_observed_in_current_source"},
},
})
report = generate_markdown_report(output, [])
text = report.read_text(encoding="utf-8")
self.assertIn("thicken", text)
self.assertNotIn("draft, thicken, split", text)
if __name__ == "__main__": unittest.main()