from __future__ import annotations import json, tempfile, unittest from concurrent.futures import ThreadPoolExecutor from pathlib import Path from cadfs_to_cdsl.reports import 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")), []) if __name__ == "__main__": unittest.main()