| import json |
| import os |
| from pathlib import Path |
| import tempfile |
| import unittest |
|
|
| from vwg_bench.metrics import summarize_vwg |
|
|
|
|
| def find_dataset_root() -> Path: |
| if os.environ.get("VWG_DATASET_ROOT"): |
| return Path(os.environ["VWG_DATASET_ROOT"]) |
| for parent in Path(__file__).resolve().parents: |
| if (parent / "data" / "test" / "metadata.jsonl").exists(): |
| return parent |
| sibling = parent / "huggingface" / "VWG-Bench" |
| if (sibling / "data" / "test" / "metadata.jsonl").exists(): |
| return sibling |
| raise FileNotFoundError( |
| "Could not locate VWG-Bench. Set VWG_DATASET_ROOT or place the " |
| "dataset at release/huggingface/VWG-Bench." |
| ) |
|
|
|
|
| DATASET_ROOT = find_dataset_root() |
|
|
|
|
| class MetricsTest(unittest.TestCase): |
| def test_optional_metrics_are_not_zero_filled(self): |
| rows = [ |
| { |
| "id": 160, |
| "seed": 0, |
| "result_id": "160_seed0", |
| "video_quality_score": 4, |
| "progress_consistency_score": 3, |
| "last_frame_goal_score": 5, |
| } |
| ] |
| with tempfile.TemporaryDirectory() as directory: |
| path = Path(directory) / "results.jsonl" |
| path.write_text( |
| "\n".join(json.dumps(row) for row in rows) + "\n", |
| encoding="utf-8", |
| ) |
| summary = summarize_vwg(DATASET_ROOT, path) |
| overall = summary["overall"] |
| self.assertEqual(overall["metrics"]["progress_goal_score"]["count"], 0) |
| self.assertEqual(overall["sample_macro_average"], 4) |
|
|
|
|
| if __name__ == "__main__": |
| unittest.main() |
|
|