Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MsgPackSerializer-related acceptance tests #836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of the failures are related to the test itself (specifically msgpack.loads(msgpack.dumps(obj)))?
https://github.com/aio-libs/aiocache/actions/runs/8513779973/job/23320587633?pr=836#step:7:82

Copy link
Author

@nottmtt nottmtt Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the test itself is causing issues here; adding

assert msgpack.loads(msgpack.dumps(obj)) == obj

right before the other asserts in TestMsgPackSerializer doesn't raise any error.

My guess would be that TypeError: a bytes-like object is required, not 'str' is raised because of the same encoding issues as the UnicodeDecodeError ones. But it's not raised by msgpack itself, that's for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess would be that TypeError: a bytes-like object is required, not 'str' is raised because of the same encoding issues as the UnicodeDecodeError ones. But it's not raised by msgpack itself, that's for sure.

That's the one I was linking to. ;)


@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
Loading