Skip to content

Commit ab67947

Browse files
test: add tests for encode_value(date, ISO8601) explicit type path
The explicit-type path (value_type=ValueType.ISO8601 with datetime.date) uses value.isoformat() rather than _format_datetime_iso8601. These tests pin the behavior, including the type asymmetry where date encodes but decodes back as datetime, and a pre-epoch edge case. Closes #114 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ffe2c57 commit ab67947

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/test_types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,32 @@ def test_encode_date_as_iso8601(self) -> None:
353353
assert decoded.month == 1
354354
assert decoded.day == 15
355355

356+
def test_encode_date_explicit_iso8601(self) -> None:
357+
"""114: datetime.date with explicit ValueType.ISO8601 must work."""
358+
import datetime
359+
360+
d = datetime.date(2024, 1, 15)
361+
encoded, vtype = encode_value(d, ValueType.ISO8601)
362+
assert vtype == ValueType.ISO8601
363+
decoded, _ = decode_value(encoded, ValueType.ISO8601)
364+
# Round-trip produces datetime, not date
365+
assert isinstance(decoded, datetime.datetime)
366+
assert decoded.year == 2024
367+
assert decoded.month == 1
368+
assert decoded.day == 15
369+
370+
def test_encode_date_explicit_iso8601_pre_epoch(self) -> None:
371+
"""114: pre-epoch date with explicit ISO8601 type."""
372+
import datetime
373+
374+
d = datetime.date(1, 1, 1)
375+
encoded, vtype = encode_value(d, ValueType.ISO8601)
376+
assert vtype == ValueType.ISO8601
377+
decoded, _ = decode_value(encoded, ValueType.ISO8601)
378+
assert decoded.year == 1
379+
assert decoded.month == 1
380+
assert decoded.day == 1
381+
356382
def test_decode_integer(self) -> None:
357383
value, consumed = decode_value(encode_int64(42), ValueType.INTEGER)
358384
assert value == 42

0 commit comments

Comments
 (0)