From 53258a9ffd869dd958fd818874b2c8406acca143 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 19 Jun 2020 09:48:14 +0200 Subject: [PATCH] [tests] add pytest for util.store see #642 --- pytests/util/test_store.py | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 pytests/util/test_store.py diff --git a/pytests/util/test_store.py b/pytests/util/test_store.py new file mode 100644 index 0000000..9128edd --- /dev/null +++ b/pytests/util/test_store.py @@ -0,0 +1,48 @@ +import pytest + +import util.store + + +@pytest.fixture +def emptyStore(): + return util.store.Store() + + +@pytest.fixture +def store(): + return util.store.Store() + + +def test_get_of_unset_key(emptyStore): + assert emptyStore.get("any-key") == None + assert emptyStore.get("any-key", "default-value") == "default-value" + + +def test_get_of_set_key(store): + store.set("key", "value") + assert store.get("key") == "value" + + +def test_overwrite_set(store): + store.set("key", "value 1") + store.set("key", "value 2") + + assert store.get("key") == "value 2" + + +def test_unused_keys(store): + store.set("key 1", "value x") + store.set("key 2", "value y") + + assert store.unused_keys() == sorted(["key 1", "key 2"]) + + store.get("key 2") + + assert store.unused_keys() == ["key 1"] + + store.get("key 1") + + assert store.unused_keys() == [] + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4