Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jun 8, 2022
1 parent 7e362a7 commit f39850a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/validators/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from pydantic_core import SchemaValidator, ValidationError
from pydantic_core import SchemaError, SchemaValidator, ValidationError

from ..conftest import Err

Expand All @@ -16,6 +16,8 @@
(b'2022-06-08', date(2022, 6, 8)),
((1,), Err('Value must be a valid date [kind=date_type')),
(Decimal('1654646400'), date(2022, 6, 8)),
(253_402_300_800_000, Err('format YYYY-MM-DD, dates after 9999 are not supported as unix timestamps')),
(-20_000_000_000, Err('format YYYY-MM-DD, dates before 1600 are not supported as unix timestamps')),
],
)
def test_float(input_value, expected):
Expand All @@ -38,6 +40,7 @@ def test_float(input_value, expected):
('wrong', Err('Value must be a valid date in the format YYYY-MM-DD, input is too short [kind=date_parsing')),
('2000-02-29', date(2000, 2, 29)),
('2001-02-29', Err('Value must be a valid date in the format YYYY-MM-DD, day value is outside expected range')),
([1], Err('Value must be a valid date [kind=date_type')),
],
)
def test_float_json(py_or_json, input_value, expected):
Expand Down Expand Up @@ -99,3 +102,8 @@ def test_date_kwargs(kwargs, input_value, expected):
else:
output = v.validate_python(input_value)
assert output == expected


def test_invalid_constraint():
with pytest.raises(SchemaError, match="'str' object cannot be converted to 'PyDate'"):
SchemaValidator({'type': 'date', 'gt': '2000-01-01'})

0 comments on commit f39850a

Please sign in to comment.