|
1 | 1 | import array |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | import msgpack |
4 | 6 | from msgpack import ExtType |
5 | 7 |
|
6 | 8 |
|
| 9 | +@pytest.mark.parametrize("ext_hook", [None, 0, "hook", []]) |
| 10 | +def test_unpackb_invalid_ext_hook(ext_hook): |
| 11 | + with pytest.raises(TypeError, match="ext_hook.*callable"): |
| 12 | + msgpack.unpackb(b"\xc0", ext_hook=ext_hook) |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize("ext_hook", [None, 0, "hook", []]) |
| 16 | +def test_unpacker_invalid_ext_hook(ext_hook): |
| 17 | + with pytest.raises(TypeError, match="ext_hook.*callable"): |
| 18 | + msgpack.Unpacker(ext_hook=ext_hook) |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.parametrize("ext_hook", [None, 0, "hook", []]) |
| 22 | +def test_unpacker_reinit_invalid_ext_hook(ext_hook): |
| 23 | + unpacker = msgpack.Unpacker(ext_hook=lambda code, data: (code, data)) |
| 24 | + unpacker.feed(b"\xd4\x42A") |
| 25 | + assert unpacker.unpack() == (0x42, b"A") |
| 26 | + |
| 27 | + with pytest.raises(TypeError, match="ext_hook.*callable"): |
| 28 | + unpacker.__init__(ext_hook=ext_hook) |
| 29 | + |
| 30 | + unpacker.__init__() |
| 31 | + unpacker.feed(b"\xd4\x42A") |
| 32 | + assert unpacker.unpack() == ExtType(0x42, b"A") |
| 33 | + |
| 34 | + |
7 | 35 | def test_pack_ext_type(): |
8 | 36 | def p(s): |
9 | 37 | packer = msgpack.Packer(autoreset=False) |
|
0 commit comments