Ejemplo n.º 1
0
 def test_loads_with_none(self):
     assert PickleSerializer().loads(None) is None
Ejemplo n.º 2
0
 def test_dumps_and_loads(self):
     obj = Dummy(1, 2)
     serializer = PickleSerializer()
     assert serializer.loads(serializer.dumps(obj)) == obj
Ejemplo n.º 3
0
 def test_dumps_with_none(self):
     assert isinstance(PickleSerializer().dumps(None), bytes)
Ejemplo n.º 4
0
 def test_loads(self):
     assert PickleSerializer().loads(b"\x80\x03X\x02\x00\x00\x00hiq\x00.") == "hi"
Ejemplo n.º 5
0
 def test_dumps(self):
     assert PickleSerializer().dumps("hi") == b"\x80\x03X\x02\x00\x00\x00hiq\x00."
Ejemplo n.º 6
0
 def test_set_types(self, obj):
     serializer = PickleSerializer()
     assert serializer.loads(serializer.dumps(obj)) == obj
Ejemplo n.º 7
0
 def test_init(self):
     serializer = PickleSerializer()
     assert isinstance(serializer, BaseSerializer)
     assert serializer.DEFAULT_ENCODING is None
     assert serializer.encoding is None
Ejemplo n.º 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()
Ejemplo n.º 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()