Angelo Gladding
lahacker.net

dlv5vbq7lzlthol5 4b942a3185b37d00

angelo@lahacker.net

South Pasadena, California, United States currently feels like 68.15°F

Home CodekvFiles

tests.py

Download raw file

import pytest

import kv
from kv import setup_module, teardown_module  # noqa


class TestString:

    @pytest.fixture
    def db(self):
        db = kv.Database("/tmp/kv-test", schema={"foo": "string"})
        del db["foo"]
        return db

    def test_basic(self, db):
        db["foo"] = "bar"
        assert str(db["foo"]) == "bar"

    def test_length(self, db):
        db["foo"] = "bar"
        assert len(db["foo"]) == 3

    def test_addition(self, db):
        db["foo"] = 3
        db["foo"] += 5
        assert int(db["foo"]) == 8

        db["foo"] += 3.5
        assert float(db["foo"]) == 11.5

        db["foo"] = "bar"
        db["foo"] += "bat"
        assert str(db["foo"]) == "barbat"


class TestList:

    @pytest.fixture
    def db(self):
        db = kv.Database("/tmp/kv-test", schema={"foo": "list"})
        del db["foo"]
        return db

    def test_basic(self, db):
        db["foo"] = ["bar", "bat"]
        assert list(db["foo"]) == ["bar", "bat"]


class TestHash:

    @pytest.fixture
    def db(self):
        db = kv.Database("/tmp/kv-test", schema={"foo": "hash"})
        del db["foo"]
        return db

    def test_basic(self, db):
        db["foo"] = {"bar": "bat"}
        assert dict(db["foo"].items()) == {"bar": "bat"}

    def test_length(self, db):
        db["foo"] = {"bar": "bat"}
        assert len(db["foo"]) == 1


# class TestSet:
#
#     schema = {"foo": "set"}


# class TestZset:
#
#     schema = {"foo": "zset"}