-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search_benchmark_tools.py
More file actions
61 lines (48 loc) · 2.11 KB
/
Copy pathtest_search_benchmark_tools.py
File metadata and controls
61 lines (48 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from __future__ import annotations
import json
import tempfile
import unittest
from pathlib import Path
from tools.build_search_benchmark import build_two_step_windows
from tools.split_search_benchmark import _read_jsonl, _write_jsonl
from dataset_pipeline import split_records
class SearchBenchmarkToolTests(unittest.TestCase):
def test_build_two_step_windows_includes_family_and_category(self) -> None:
rows = build_two_step_windows()
self.assertTrue(rows)
sample = rows[0]
self.assertIn("program_name", sample)
self.assertIn("split_family", sample)
self.assertIn("category", sample)
self.assertEqual(sample["dataset_type"], "next_2_steps_search_benchmark")
def test_family_split_keeps_each_family_in_one_split(self) -> None:
rows = build_two_step_windows()
splits = split_records(rows, seed=7)
family_to_split: dict[str, str] = {}
for split_name, split_rows in splits.items():
for row in split_rows:
family = row["split_family"]
if family in family_to_split:
self.assertEqual(family_to_split[family], split_name)
family_to_split[family] = split_name
def test_jsonl_helpers_round_trip_rows(self) -> None:
rows = [
{"program_name": "a", "split_family": "fam_a", "category": "branch"},
{"program_name": "b", "split_family": "fam_b", "category": "loop"},
]
with tempfile.TemporaryDirectory() as tmpdir:
path = Path(tmpdir) / "rows.jsonl"
_write_jsonl(path, rows)
loaded = _read_jsonl(path)
self.assertEqual(rows, loaded)
def test_split_manifest_shape_is_json_serializable(self) -> None:
rows = build_two_step_windows()
splits = split_records(rows, seed=7)
manifest = {
"split_counts": {split_name: len(split_rows) for split_name, split_rows in splits.items()}
}
payload = json.dumps(manifest)
self.assertIn("train", payload)
self.assertIn("test", payload)
if __name__ == "__main__":
unittest.main()