|
| 1 | +from typing import List |
| 2 | + |
| 3 | +from eval_protocol.models import EvaluationRow, Message |
| 4 | +from eval_protocol.pytest.default_no_op_rollout_processor import NoOpRolloutProcessor |
| 5 | +from tests.pytest.test_markdown_highlighting import markdown_dataset_to_evaluation_row |
| 6 | + |
| 7 | + |
| 8 | +async def test_evaluation_test_decorator_ids_single(): |
| 9 | + from eval_protocol.pytest.evaluation_test import evaluation_test |
| 10 | + |
| 11 | + row_ids = set() |
| 12 | + |
| 13 | + input_dataset = [ |
| 14 | + "tests/pytest/data/markdown_dataset.jsonl", |
| 15 | + "tests/pytest/data/markdown_dataset.jsonl", |
| 16 | + ] |
| 17 | + completion_params_list = [ |
| 18 | + {"temperature": 0.0, "model": "dummy/local-model"}, |
| 19 | + {"temperature": 1.0, "model": "dummy/local-model"}, |
| 20 | + ] |
| 21 | + |
| 22 | + @evaluation_test( |
| 23 | + input_dataset=input_dataset, |
| 24 | + completion_params=completion_params_list, |
| 25 | + dataset_adapter=markdown_dataset_to_evaluation_row, |
| 26 | + rollout_processor=NoOpRolloutProcessor(), |
| 27 | + mode="pointwise", |
| 28 | + combine_datasets=False, |
| 29 | + num_runs=5, |
| 30 | + ) |
| 31 | + def eval_fn(row: EvaluationRow) -> EvaluationRow: |
| 32 | + row_ids.add(row.input_metadata.row_id) |
| 33 | + return row |
| 34 | + |
| 35 | + # Manually invoke all parameter combinations within a single test |
| 36 | + for ds_path in input_dataset: |
| 37 | + for params in completion_params_list: |
| 38 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 39 | + |
| 40 | + # Second invocation to ensure that IDs are stable across multiple invocations |
| 41 | + for ds_path in input_dataset: |
| 42 | + for params in completion_params_list: |
| 43 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 44 | + |
| 45 | + # Assertions on IDs generated by the decorator logic |
| 46 | + assert len(row_ids) == 19 # from the markdown dataset |
| 47 | + |
| 48 | + |
| 49 | +async def test_evaluation_test_generated_row_ids_without_dataset_keys(): |
| 50 | + from eval_protocol.pytest.evaluation_test import evaluation_test |
| 51 | + |
| 52 | + # Adapter that does NOT set row_id; lets evaluation_test generate IDs |
| 53 | + def markdown_dataset_no_row_id_adapter(data: List[dict]) -> List[EvaluationRow]: |
| 54 | + return [ |
| 55 | + EvaluationRow( |
| 56 | + messages=[Message(role="user", content=row["prompt"])], |
| 57 | + ground_truth=str(row["num_highlights"]), |
| 58 | + ) |
| 59 | + for row in data |
| 60 | + ] |
| 61 | + |
| 62 | + row_ids = set() |
| 63 | + |
| 64 | + input_dataset = ["tests/pytest/data/markdown_dataset.jsonl", "tests/pytest/data/markdown_dataset.jsonl"] |
| 65 | + completion_params = [ |
| 66 | + {"temperature": 0.0, "model": "dummy/local-model"}, |
| 67 | + {"temperature": 1.0, "model": "dummy/local-model"}, |
| 68 | + ] |
| 69 | + |
| 70 | + @evaluation_test( |
| 71 | + input_dataset=input_dataset, |
| 72 | + completion_params=completion_params, |
| 73 | + dataset_adapter=markdown_dataset_no_row_id_adapter, |
| 74 | + rollout_processor=NoOpRolloutProcessor(), |
| 75 | + mode="pointwise", |
| 76 | + combine_datasets=False, |
| 77 | + num_runs=5, |
| 78 | + ) |
| 79 | + def eval_fn(row: EvaluationRow) -> EvaluationRow: |
| 80 | + # row_id should be auto-generated by evaluation_test/InputMetadata |
| 81 | + assert row.input_metadata is not None |
| 82 | + assert row.input_metadata.row_id is not None and isinstance(row.input_metadata.row_id, str) |
| 83 | + row_ids.add(row.input_metadata.row_id) |
| 84 | + return row |
| 85 | + |
| 86 | + # Single invocation (one dataset, one param set) with multiple runs |
| 87 | + for ds_path in input_dataset: |
| 88 | + for params in completion_params: |
| 89 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 90 | + |
| 91 | + # Second invocation to ensure that IDs are stable across multiple invocations |
| 92 | + for ds_path in input_dataset: |
| 93 | + for params in completion_params: |
| 94 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 95 | + |
| 96 | + # Even with multiple runs, generated row_ids should be stable within the invocation |
| 97 | + assert len(row_ids) == 19 # equals dataset size when IDs are generated once and preserved across runs |
0 commit comments