Skip to content

Commit

Permalink
Add MsgPackSerializer-related acceptance tests
Browse files Browse the repository at this point in the history
See issue aio-libs#834.
  • Loading branch information
nottmtt committed Apr 1, 2024
1 parent 63fb637 commit 84d70b1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/acceptance/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
from typing import Any

import msgpack
import pytest
from marshmallow import Schema, fields, post_load

Expand All @@ -13,6 +14,7 @@
from aiocache.serializers import (
BaseSerializer,
JsonSerializer,
MsgPackSerializer,
NullSerializer,
PickleSerializer,
StringSerializer,
Expand Down Expand Up @@ -141,6 +143,28 @@ async def test_multi_set_multi_get_types(self, cache, obj):
assert await cache.multi_get([Keys.KEY]) == [pickle.loads(pickle.dumps(obj))]


class TestMsgPackSerializer:
TYPES = (1, 2.0, "hi", True, ["1", 1], {"key": "value"})

@pytest.mark.parametrize("obj", TYPES)
async def test_set_get_types(self, cache, obj):
cache.serializer = MsgPackSerializer()
assert await cache.set(Keys.KEY, obj) is True
assert await cache.get(Keys.KEY) == msgpack.loads(msgpack.dumps(obj))

@pytest.mark.parametrize("obj", TYPES)
async def test_add_get_types(self, cache, obj):
cache.serializer = MsgPackSerializer()
assert await cache.add(Keys.KEY, obj) is True
assert await cache.get(Keys.KEY) == msgpack.loads(msgpack.dumps(obj))

@pytest.mark.parametrize("obj", TYPES)
async def test_multi_set_multi_get_types(self, cache, obj):
cache.serializer = MsgPackSerializer()
assert await cache.multi_set([(Keys.KEY, obj)]) is True
assert await cache.multi_get([Keys.KEY]) == [msgpack.loads(msgpack.dumps(obj))]


class TestAltSerializers:
async def test_get_set_alt_serializer_functions(self, cache):
cache.serializer = StringSerializer()
Expand Down

0 comments on commit 84d70b1

Please sign in to comment.