Skip to content

Commit 5de3c0b

Browse files
committed
Add test for field regex/pattern parameter
1 parent 2d6bb87 commit 5de3c0b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_pydantic/test_field.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ class Model(SQLModel):
5555

5656
instance = Model(id=123, foo="bar")
5757
assert "foo=" not in repr(instance)
58+
59+
60+
@pytest.mark.parametrize("param", ["regex", "pattern"])
61+
def test_field_regex_param(param: str):
62+
class DateModel(SQLModel):
63+
date_1: str = Field(**{param: r"^\d{2}-\d{2}-\d{4}$"})
64+
date_2: str = Field(schema_extra={param: r"^\d{2}-\d{2}-\d{4}$"})
65+
66+
DateModel(date_1="12-31-2024", date_2="12-31-2024")
67+
# Validates correctly
68+
69+
with pytest.raises(ValidationError):
70+
DateModel(date_1="2024-12-31", date_2="2024-12-31")
71+
# This should raise a ValueError due to regex mismatch

0 commit comments

Comments
 (0)