Spaces:
Sleeping
Sleeping
File size: 1,194 Bytes
497c3ef | 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 | from __future__ import annotations
import json
from pathlib import Path
import pytest
from pydantic import ValidationError
from bl_ocr.domain.models import DeliveryNote
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def _example() -> dict:
return json.loads((PROJECT_ROOT / "example.json").read_text(encoding="utf-8"))
def test_models_parse_example():
note = DeliveryNote.model_validate(_example())
assert note.products[0].pharmacist_price_ttc.value == 5.35
assert note.totals.line_count.value == 3
def test_models_forbid_extra_keys():
annotation = _example()
annotation["products"][0]["_repaired"] = "leak"
with pytest.raises(ValidationError):
DeliveryNote.model_validate(annotation)
def test_models_enforce_confidence_bounds():
annotation = _example()
annotation["products"][0]["quantity"]["confidence"] = 1.5
with pytest.raises(ValidationError):
DeliveryNote.model_validate(annotation)
def test_models_allow_null_values():
annotation = _example()
annotation["products"][0]["expiry_date"]["value"] = None
note = DeliveryNote.model_validate(annotation)
assert note.products[0].expiry_date.value is None
|