Ejemplo n.º 1
0
def test_expire_set():
    ledis = Ledis()
    ledis.sadd("set_type", 1, 2, 3)
    assert ledis.expire("set_type", 1) == 1
    sleep(2)

    # The key will only be lazy-deleted
    # if the key is called in any operations
    assert "set_type" in ledis.storage
    assert ledis.get("set_type") is None
    assert "set_type" not in ledis.storage
Ejemplo n.º 2
0
def test_restore(test_snapshot_filename):
    ledis = Ledis()
    ledis.set("hello", "world")
    ledis.sadd("set_type", 1, 2, 3)
    ledis.save(test_snapshot_filename)

    # Clear current state
    ledis.storage = {}
    assert ledis.get("hello") is None
    assert ledis.get("set_type") is None

    # Restore from persistent data
    ledis.restore(test_snapshot_filename)
    assert ledis.get("hello") == "world"
    assert ledis.smembers("set_type") == [1, 2, 3]
Ejemplo n.º 3
0
def test_srem():
    ledis = Ledis()
    ledis.sadd("set_type", *{1, 2, 3})

    ledis.srem("set_type", *{2, 3})
    assert ledis.storage["set_type"].data == {1}
Ejemplo n.º 4
0
def test_srem_str_value():
    ledis = Ledis()
    ledis.sadd("hello", 1, 2, 3)
    ledis.srem("hello", "world")

    assert ledis.storage["hello"] == Set({1, 2, 3})
Ejemplo n.º 5
0
import pytest

from ledis import Ledis
from ledis.exceptions import InvalidType

ledis = Ledis()
ledis.set("hello", "world")
ledis.sadd("set_type", 1, 2, 3)


def test_get():
    assert ledis.get("hello") == "world"


def test_get_key_not_exist():
    assert ledis.get("key_not_found") is None


def test_get_key_set_type():
    with pytest.raises(InvalidType):
        ledis.get("set_type")
Ejemplo n.º 6
0
def test_sadd_empty():
    ledis = Ledis()
    ledis.sadd("set_type", 1, 2, 3)
    assert ledis.storage["set_type"] == Set({1, 2, 3})
Ejemplo n.º 7
0
def test_sadd_to_str():
    ledis = Ledis()
    ledis.set("hello", "world")

    with pytest.raises(InvalidType):
        ledis.sadd("hello", {2, 3, 4})
Ejemplo n.º 8
0
def test_sadd_str_value():
    ledis = Ledis()
    ledis.sadd("hello", "world")

    assert ledis.storage["hello"] == Set({"world"})
Ejemplo n.º 9
0
def test_sadd_exist():
    ledis = Ledis()
    ledis.sadd("set_type", 1, 2, 3)
    ledis.sadd("set_type", 2, 3, 4)
    assert ledis.storage["set_type"] == Set({1, 2, 3, 4})
Ejemplo n.º 10
0
def test_keys():
    ledis = Ledis()
    ledis.set("str_type", "hello")
    ledis.sadd("set_type", 1, 2, 3)

    assert ledis.keys() == ["str_type", "set_type"]
Ejemplo n.º 11
0
def test_delete_set():
    ledis = Ledis()
    ledis.sadd("set_type", 1, 2, 3)
    ledis.delete("set_type")
    assert "set_type" not in ledis.storage