pinterest / pymemcache

A comprehensive, fast, pure-Python memcached client.
https://pymemcache.readthedocs.io/
Apache License 2.0
778 stars 179 forks source link

MockMemcacheClient return string as bytes #470

Closed iurisilvio closed 1 year ago

iurisilvio commented 1 year ago

This test fails because it returns b"world" instead of a string.

import pytest
import pymemcache
from pymemcache.test.utils import MockMemcacheClient

@pytest.mark.unit()
def test_get_set_string():
    client = MockMemcacheClient(serde=pymemcache.serde.pickle_serde)
    assert client.get("hello") is None

    client.set("hello", "world")
    assert client.get("hello") == "world"

(updated this example using serde)

iurisilvio commented 1 year ago

Oh this is behavior of the client too. Unexpected for me...

iurisilvio commented 1 year ago

Oops, it really happens. I was trying the real client without serde defined. They are really working different.

import pymemcache
from pymemcache.test.utils import MockMemcacheClient

def test_client(client_class):
    client = client_class("localhost", serde=pymemcache.serde.pickle_serde)
    client.set("abc", "abc")
    value = client.get("abc")
    assert value == "abc"

test_client(pymemcache.Client)
test_client(MockMemcacheClient)