Skip to content

Commit c1fe591

Browse files
committed
test: validate parsing boundary values JSON Dates
Relates to #80
1 parent 05243e4 commit c1fe591

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_model_v2.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,32 @@ def test_traits_datetime():
487487
assert testdate.second == 0
488488
assert testdate.microsecond == 0
489489

490+
# parsing the lowest value
491+
with pytest.raises(OverflowError):
492+
typ.traits.from_json("/Date(-62135596800001)/")
493+
494+
testdate = typ.traits.from_json("/Date(-62135596800000)/")
495+
assert testdate.year == 1
496+
assert testdate.month == 1
497+
assert testdate.day == 1
498+
assert testdate.hour == 0
499+
assert testdate.minute == 0
500+
assert testdate.second == 0
501+
assert testdate.microsecond == 0
502+
503+
# parsing the highest value
504+
with pytest.raises(OverflowError):
505+
typ.traits.from_json("/Date(253402300800000)/")
506+
507+
testdate = typ.traits.from_json("/Date(253402300799999)/")
508+
assert testdate.year == 9999
509+
assert testdate.month == 12
510+
assert testdate.day == 31
511+
assert testdate.hour == 23
512+
assert testdate.minute == 59
513+
assert testdate.second == 59
514+
assert testdate.microsecond == 999000
515+
490516
# parsing invalid value
491517
with pytest.raises(PyODataModelError) as e_info:
492518
typ.traits.from_json("xyz")

0 commit comments

Comments
 (0)