import pytest from dirty_equals import Contains, IsPartialDict from pydantic import TypeAdapter, ValidationError from preference_center.profile.types import BirthdayStr @pytest.mark.parametrize( "value", [ "01/01", "01/31", "12/01", "12/30", "12/31", ], ) def test_profile_birthday_valid(value: str) -> None: tp = TypeAdapter(BirthdayStr) assert tp.validate_python(value) == value @pytest.mark.parametrize( "value", [ "", "invalid", "01/00", "01/32", "00/01", "13/01", "01/01/2021", "01-01", "01-01-2021", ], ) def test_profile_birthday_invalid(value: str) -> None: tp = TypeAdapter(BirthdayStr) with pytest.raises(ValidationError) as exc_info: tp.validate_python(value) assert exc_info.value.errors() == Contains(IsPartialDict({"input": value}))