From 71bfd4d8df08503f537113f4cf74274c968e580e Mon Sep 17 00:00:00 2001 From: Jakob van Santen Date: Fri, 29 Nov 2024 09:44:28 +0100 Subject: [PATCH] tests: explicitly test annotated field validation --- tests/test_AmpelUnit.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_AmpelUnit.py b/tests/test_AmpelUnit.py index 4c1e4e40..14fa0877 100644 --- a/tests/test_AmpelUnit.py +++ b/tests/test_AmpelUnit.py @@ -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 @@ -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]