File size: 836 Bytes
b8ea052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Contract validation helpers."""

from __future__ import annotations

from pvr_eval.core.schema import EvalContract


def validate_contract(contract: EvalContract) -> None:
    if not contract.case_id:
        raise ValueError("contract.case_id is required")
    if not contract.atomic_checks:
        raise ValueError(f"contract {contract.case_id!r} has no atomic checks")
    seen: set[str] = set()
    for check in contract.atomic_checks:
        if check.check_id in seen:
            raise ValueError(f"duplicate atomic check id {check.check_id!r} in {contract.case_id}")
        seen.add(check.check_id)
        if check.weight < 0:
            raise ValueError(f"atomic check {check.check_id!r} has negative weight")
        if not check.checker:
            raise ValueError(f"atomic check {check.check_id!r} has no checker")