示例#1
0
 def test_loads_with_none(self):
     assert PickleSerializer().loads(None) is None
示例#2
0
 def test_dumps_and_loads(self):
     obj = Dummy(1, 2)
     serializer = PickleSerializer()
     assert serializer.loads(serializer.dumps(obj)) == obj
示例#3
0
 def test_dumps_with_none(self):
     assert isinstance(PickleSerializer().dumps(None), bytes)
示例#4
0
 def test_loads(self):
     assert PickleSerializer().loads(b"\x80\x03X\x02\x00\x00\x00hiq\x00.") == "hi"
示例#5
0
 def test_dumps(self):
     assert PickleSerializer().dumps("hi") == b"\x80\x03X\x02\x00\x00\x00hiq\x00."
示例#6
0
 def test_set_types(self, obj):
     serializer = PickleSerializer()
     assert serializer.loads(serializer.dumps(obj)) == obj
示例#7
0
 def test_init(self):
     serializer = PickleSerializer()
     assert isinstance(serializer, BaseSerializer)
     assert serializer.DEFAULT_ENCODING is None
     assert serializer.encoding is None
示例#8
0
from collections import namedtuple

from pycached import cached, RedisCache
from pycached.serializers import PickleSerializer

Result = namedtuple('Result', "content, status")


@cached(ttl=10,
        cache=RedisCache,
        key="key",
        serializer=PickleSerializer(),
        port=6379,
        namespace="main")
def cached_call():
    return Result("content", 200)


def test_cached():
    cache = RedisCache(endpoint="127.0.0.1", port=6379, namespace="main")
    cached_call()
    assert cache.exists("key") is True
    cache.delete("key")
    cache.close()


if __name__ == "__main__":
    test_cached()
示例#9
0
from collections import namedtuple

from pycached import Cache
from pycached.serializers import PickleSerializer

MyObject = namedtuple("MyObject", ["x", "y"])
cache = Cache(Cache.REDIS, serializer=PickleSerializer(), namespace="main")


def complex_object():
    obj = MyObject(x=1, y=2)
    cache.set("key", obj)
    my_object = cache.get("key")

    assert my_object.x == 1
    assert my_object.y == 2


def test_python_object():
    complex_object()
    cache.delete("key")
    cache.close()


if __name__ == "__main__":
    test_python_object()