| """Shared fixtures and helpers for report-export tests.""" |
|
|
| import json |
| import tempfile |
| import unittest |
| from pathlib import Path |
| from analysis.letters_reports import ( |
| analyze_modular, |
| export_reports, |
| load_profile as load, |
| ) |
|
|
|
|
| def vlm(letter, qid=1, score=1.0, protocol="base", model="m", frames=32): |
| r = { |
| "model": model, |
| "protocol": protocol, |
| "condition": protocol, |
| "question_id": qid, |
| "scene": "s", |
| "dataset": "d", |
| "question_type": "count", |
| "score": score, |
| "frame_count": frames, |
| "input_token_count": 10, |
| "output_token_count": 2, |
| "generation_seconds": 1.0, |
| "answer_given": "x", |
| "full_prompt": "p", |
| } |
| if letter == "A": |
| r["frame_selection"] = "uniform" |
| elif letter in "BC": |
| r.update( |
| input_selection="uniform", |
| spatial_code_format="explicit", |
| depth="metric", |
| tracking="tracking", |
| ) |
| return r |
|
|
|
|
| def put(root, relative, record): |
| p = root / relative |
| p.parent.mkdir(parents=True, exist_ok=True) |
| p.write_text(json.dumps(record)) |
| return p |
|
|
|
|
| class ReportTestCase(unittest.TestCase): |
| def setUp(self): |
| self.temp = tempfile.TemporaryDirectory() |
| self.root = Path(self.temp.name) |
|
|
| def tearDown(self): |
| self.temp.cleanup() |
|
|
| def directory(self, letter, records): |
| d = self.root / letter |
| d.mkdir() |
| for i, r in enumerate(records): |
| put(d, f"{i}.json", r) |
| return d |
|
|
| def symbolic(self, future=False): |
| d = self.root / ("F_future" if future else "F") |
| d.mkdir(exist_ok=True) |
| prefix = ( |
| "perceived/metric/tracking/uniform/32/explicit" |
| if future |
| else "metric/tracking/uniform/32/explicit" |
| ) |
| put( |
| d, |
| f"{prefix}/s/1.json", |
| { |
| "model": "symbolic", |
| "condition": "metric:tracking:uniform:32:explicit", |
| "question_id": 1, |
| "scene": "s", |
| "dataset": "d", |
| "question_type": "count", |
| "score": 1.0, |
| "spatial_code_format": "explicit", |
| "depth": "metric", |
| "tracking": "tracking", |
| "input": "uniform", |
| "number_of_frames": 32, |
| }, |
| ) |
| return d |
|
|
| def ground_truth_symbolic(self): |
| d = self.root / "F" |
| d.mkdir() |
| put( |
| d, |
| "ground truth/explicit/s/1.json", |
| { |
| "model": "symbolic", |
| "condition": "ground truth:explicit", |
| "question_id": 1, |
| "scene": "s", |
| "dataset": "d", |
| "question_type": "count", |
| "score": 1.0, |
| "spatial_code_format": "explicit", |
| }, |
| ) |
| return d |
|
|
| def analyze(self, letters, dirs, pairs=(), protocols=("base",)): |
| profiles = {l: load(l) for l in letters} |
| per, combined = analyze_modular( |
| {l: dirs[l] for l in letters}, profiles, protocols, pairs |
| ) |
| paths = export_reports(per, combined, self.root / "reports") |
| return per, combined, {p.name for p in paths} |
|
|