예제 #1
0
 def test_dumps_and_loads_dict(self):
     d = {'a': [1, 2, ('1', 2)], 'b': {'b': 1, 'c': [1, 2]}}
     assert MsgPackSerializer.loads(MsgPackSerializer.dumps(d)) == {
         'a': [1, 2, ['1', 2]],
         'b': {
             'b': 1,
             'c': [1, 2]
         }
     }
예제 #2
0
 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]
         },
     }
예제 #3
0
 def test_dumps_and_loads_tuple(self):
     serializer = MsgPackSerializer()
     assert serializer.loads(serializer.dumps(Dummy(1, 2))) == [1, 2]
예제 #4
0
 def test_loads_with_none(self):
     assert MsgPackSerializer().loads(None) is None
예제 #5
0
 def test_loads_no_encoding(self):
     assert MsgPackSerializer(encoding=None).loads(b'\xa2hi') == b'hi'
예제 #6
0
 def test_loads(self):
     assert MsgPackSerializer().loads(b'\xa2hi') == 'hi'
예제 #7
0
 def test_dumps_with_none(self):
     assert isinstance(MsgPackSerializer().dumps(None), bytes)
예제 #8
0
 def test_dumps(self):
     assert MsgPackSerializer().dumps('hi') == b'\xa2hi'
예제 #9
0
 def test_set_types(self, obj):
     serializer = MsgPackSerializer()
     assert serializer.loads(serializer.dumps(obj)) == obj
예제 #10
0
 def test_init_use_list(self):
     serializer = MsgPackSerializer(use_list=True)
     assert serializer.use_list is True
예제 #11
0
 def test_init(self):
     serializer = MsgPackSerializer()
     assert isinstance(serializer, BaseSerializer)
     assert serializer.DEFAULT_ENCODING == 'utf-8'
     assert serializer.encoding == 'utf-8'
예제 #12
0
 def test_loads(self):
     assert MsgPackSerializer().loads(b"\xa2hi") == "hi"
예제 #13
0
 def test_dumps(self):
     assert MsgPackSerializer().dumps("hi") == b"\xa2hi"
예제 #14
0
 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"
예제 #15
0
 def test_loads_no_encoding(self):
     MsgPackSerializer.encoding = None
     assert MsgPackSerializer().loads(b'\xa2hi') == b'hi'
     MsgPackSerializer.encoding = 'utf-8'