diff options
| author | Inada Naoki <songofacandy@gmail.com> | 2020-02-06 22:11:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-06 22:11:04 +0900 |
| commit | 9d79351e99e435b8ca749d57a313441783f67133 (patch) | |
| tree | 06d165456f90898aa74048ec86319213b35aff1f /test/test_timestamp.py | |
| parent | ff1f5f89d997b40e60472c2820ea55cab752c779 (diff) | |
| download | msgpack-python-9d79351e99e435b8ca749d57a313441783f67133.tar.gz | |
Add some test for timestamp (#403)
Diffstat (limited to 'test/test_timestamp.py')
| -rw-r--r-- | test/test_timestamp.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_timestamp.py b/test/test_timestamp.py index ba5611c..823fe04 100644 --- a/test/test_timestamp.py +++ b/test/test_timestamp.py @@ -46,6 +46,33 @@ def test_timestamp(): assert ts == unpacked +def test_unpack_timestamp(): + # timestamp 32 + assert msgpack.unpackb(b"\xd6\xff\x00\x00\x00\x00") == Timestamp(0) + + # timestamp 64 + assert msgpack.unpackb(b"\xd7\xff" + b"\x00" * 8) == Timestamp(0) + with pytest.raises(ValueError): + msgpack.unpackb(b"\xd7\xff" + b"\xff" * 8) + + # timestamp 96 + assert msgpack.unpackb(b"\xc7\x0c\xff" + b"\x00" * 12) == Timestamp(0) + with pytest.raises(ValueError): + msgpack.unpackb(b"\xc7\x0c\xff" + b"\xff" * 12) == Timestamp(0) + + # Undefined + with pytest.raises(ValueError): + msgpack.unpackb(b"\xd4\xff\x00") # fixext 1 + with pytest.raises(ValueError): + msgpack.unpackb(b"\xd5\xff\x00\x00") # fixext 2 + with pytest.raises(ValueError): + msgpack.unpackb(b"\xc7\x00\xff") # ext8 (len=0) + with pytest.raises(ValueError): + msgpack.unpackb(b"\xc7\x03\xff\0\0\0") # ext8 (len=3) + with pytest.raises(ValueError): + msgpack.unpackb(b"\xc7\x05\xff\0\0\0\0\0") # ext8 (len=5) + + def test_timestamp_from(): t = Timestamp(42, 14000) assert Timestamp.from_unix(42.000014) == t |
