mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-06 09:50:01 +00:00
Nicer error when packing a datetime without tzinfo (#466)
This commit is contained in:
parent
cfa05d3fdc
commit
e464cb44fa
3 changed files with 22 additions and 0 deletions
|
|
@ -140,3 +140,19 @@ def test_issue451():
|
|||
|
||||
unpacked = msgpack.unpackb(packed, timestamp=3)
|
||||
assert dt == unpacked
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_pack_datetime_without_tzinfo():
|
||||
dt = datetime.datetime(1970, 1, 1, 0, 0, 42, 14)
|
||||
with pytest.raises(ValueError, match="where tzinfo=None"):
|
||||
packed = msgpack.packb(dt, datetime=True)
|
||||
|
||||
dt = datetime.datetime(1970, 1, 1, 0, 0, 42, 14)
|
||||
packed = msgpack.packb(dt, datetime=True, default=lambda x: None)
|
||||
assert packed == msgpack.packb(None)
|
||||
|
||||
dt = datetime.datetime(1970, 1, 1, 0, 0, 42, 14, tzinfo=_utc)
|
||||
packed = msgpack.packb(dt, datetime=True)
|
||||
unpacked = msgpack.unpackb(packed, timestamp=3)
|
||||
assert unpacked == dt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue