Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
serializer = MsgPackSerializer()
assert isinstance(serializer, BaseSerializer)
assert serializer.DEFAULT_ENCODING == "utf-8"
assert serializer.encoding == "utf-8"
def test_loads(self):
assert MsgPackSerializer().loads(b"\xa2hi") == "hi"
def test_init_fails_if_msgpack_not_installed(self):
with mock.patch("aiocache.serializers.serializers.msgpack", None):
with pytest.raises(RuntimeError):
MsgPackSerializer()
assert JsonSerializer(), "Other serializers should still initialize"
def test_init_use_list(self):
serializer = MsgPackSerializer(use_list=True)
assert serializer.use_list is True
def test_set_types(self, obj):
serializer = MsgPackSerializer()
assert serializer.loads(serializer.dumps(obj)) == obj
def test_dumps(self):
assert MsgPackSerializer().dumps("hi") == b"\xa2hi"
def test_dumps_and_loads_dict(self):
serializer = MsgPackSerializer()
d = {"a": [1, 2, ("1", 2)], "b": {"b": 1, "c": [1, 2]}}
assert serializer.loads(serializer.dumps(d)) == {
"a": [1, 2, ["1", 2]],
"b": {"b": 1, "c": [1, 2]},
}
def test_loads_with_none(self):
assert MsgPackSerializer().loads(None) is None
def test_dumps_and_loads_tuple(self):
serializer = MsgPackSerializer()
assert serializer.loads(serializer.dumps(Dummy(1, 2))) == [1, 2]
def test_dumps_with_none(self):
assert isinstance(MsgPackSerializer().dumps(None), bytes)