data(train 520·holdout 120), server(발화 생성 서버), eval(grounding_eval), run_eval.py·run_test.sh. logs/ 는 실행 때마다 생기는 기록이라 README.md 만 올리고 나머지는 .gitignore 로 뺀다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from grounding_eval.data import load_items, select_items
|
|
|
|
|
|
def sample(sid, did="DLG-1", turn=2, split="test_holdout", task="strategy_conditioned_response",
|
|
ref="응답"):
|
|
return {"sample_id": sid, "dialogue_id": did, "turn": turn, "split": split, "task_type": task,
|
|
"messages": [{"role": "system", "content": "s"}, {"role": "user", "content": "u"}],
|
|
"reference_response": ref}
|
|
|
|
|
|
def test_selects_holdout_response_samples_only():
|
|
samples = [sample("A"), sample("B", split="train"), sample("C", task="next_strategy"), sample("D", ref="")]
|
|
|
|
assert [i.sample_id for i in select_items(samples)] == ["A"]
|
|
|
|
|
|
def test_items_sorted_by_dialogue_and_turn():
|
|
samples = [sample("A", did="DLG-2", turn=2), sample("B", did="DLG-1", turn=4), sample("C", did="DLG-1", turn=2)]
|
|
|
|
assert [i.sample_id for i in select_items(samples)] == ["C", "B", "A"]
|
|
|
|
|
|
def test_duplicate_sample_id_raises():
|
|
with pytest.raises(ValueError):
|
|
select_items([sample("A"), sample("A", turn=4)])
|
|
|
|
|
|
def test_load_items_reads_jsonl(tmp_path):
|
|
path = tmp_path / "i.jsonl"
|
|
path.write_text("\n".join(json.dumps(s, ensure_ascii=False) for s in [sample("A"), sample("B", split="train")]) + "\n",
|
|
encoding="utf-8")
|
|
|
|
items = load_items(path)
|
|
|
|
assert len(items) == 1 and items[0].reference == "응답"
|
|
|
|
|
|
def test_load_items_reports_bad_line(tmp_path):
|
|
path = tmp_path / "i.jsonl"
|
|
path.write_text('{"sample_id": "A"}\nnot json\n', encoding="utf-8")
|
|
|
|
with pytest.raises(ValueError, match=":2:"):
|
|
load_items(path)
|