summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBenjamin Egelund-Müller <b@egelund-muller.com>2021-11-16 09:49:47 +0100
committerGitHub <noreply@github.com>2021-11-16 17:49:47 +0900
commite464cb44fa3af5ad3ecd83f9c045b16981d01bb2 (patch)
tree060cdcdc6d87d0e3763daa52cf40c4d4675a3fb3 /test
parentcfa05d3fdc6290b4847e4781a06ac0668ea9dc18 (diff)
downloadmsgpack-python-e464cb44fa3af5ad3ecd83f9c045b16981d01bb2.tar.gz
Nicer error when packing a datetime without tzinfo (#466)
Diffstat (limited to 'test')
-rw-r--r--test/test_timestamp.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/test_timestamp.py b/test/test_timestamp.py
index 6a29be7..4e26489 100644
--- a/test/test_timestamp.py
+++ b/test/test_timestamp.py
@@ -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