Skip to content

Commit

Permalink
tests: explicitly test annotated field validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jvansanten committed Nov 29, 2024
1 parent 4dc1052 commit 71bfd4d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_AmpelUnit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import warnings
from collections.abc import Sequence
from typing import Annotated

import pytest
from annotated_types import MinLen

from ampel.base.AmpelBaseModel import AmpelBaseModel
from ampel.base.AmpelUnit import AmpelUnit
Expand Down Expand Up @@ -196,3 +198,15 @@ class Unit(AmpelUnit):
assert Unit(a=[1, 2, 3], c=Model()).dict(exclude={"a"}, exclude_defaults=True) == {
"c": {"param": 1},
}


def test_annotated_fields():
"""Annotated fields are validated"""

class Annie(AmpelUnit):
a: Annotated[list[int], MinLen(1)]

with pytest.raises(TypeError):
Annie(a=[])

assert Annie(a=[1]).a == [1]

0 comments on commit 71bfd4d

Please sign in to comment.