From de8a5fbf668f3d0702569c14b81daa6cfb2fcf31 Mon Sep 17 00:00:00 2001 From: amirreza Date: Sat, 21 Sep 2024 08:00:59 +0330 Subject: [PATCH] test clear() return value --- tests/test_backend.py | 24 ++++++++++++++++-------- tests/tests_async/test_backend.py | 22 ++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/tests/test_backend.py b/tests/test_backend.py index 2a91792..4f8e8a9 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -790,14 +790,6 @@ def test_touch_default_timeout(self, cache: ValkeyCache): time.sleep(2) assert cache.get("test_key") == "foo" - def test_clear(self, cache: ValkeyCache): - cache.set("foo", "bar") - value_from_cache = cache.get("foo") - assert value_from_cache == "bar" - cache.clear() - value_from_cache_after_clear = cache.get("foo") - assert value_from_cache_after_clear is None - def test_hset(self, cache: ValkeyCache): if isinstance(cache.client, ShardClient): pytest.skip("ShardClient doesn't support get_client") @@ -1082,3 +1074,19 @@ def test_sunionstore(self, cache: ValkeyCache): cache.sadd("foo2", "bar2", "bar3") assert cache.sunionstore("foo3", "foo1", "foo2") == 3 assert cache.smembers("foo3") == {"bar1", "bar2", "bar3"} + + def test_clear(self, cache: ValkeyCache): + cache.set("foo", "bar") + value_from_cache = cache.get("foo") + assert value_from_cache == "bar" + cache.clear() + value_from_cache_after_clear = cache.get("foo") + assert value_from_cache_after_clear is None + + def test_clear_true(self, cache: ValkeyCache): + if isinstance(cache.client, ShardClient): + pytest.skip("ShardClient doesn't return on clear") + cache.set("foo", "bar") + assert cache.get("foo") == "bar" + assert cache.clear() is True + assert cache.get("foo") is None diff --git a/tests/tests_async/test_backend.py b/tests/tests_async/test_backend.py index 5a4dade..8215112 100644 --- a/tests/tests_async/test_backend.py +++ b/tests/tests_async/test_backend.py @@ -813,14 +813,6 @@ async def test_touch_default_timeout(self, cache: AsyncValkeyCache): await asyncio.sleep(2) assert await cache.aget("test_key") == "foo" - async def test_clear(self, cache: AsyncValkeyCache): - await cache.aset("foo", "bar") - value_from_cache = await cache.aget("foo") - assert value_from_cache == "bar" - await cache.aclear() - value_from_cache_after_clear = await cache.aget("foo") - assert value_from_cache_after_clear is None - async def test_hset(self, cache: AsyncValkeyCache): # if isinstance(cache.client, ShardClient): # pytest.skip("ShardClient doesn't support get_client") @@ -1044,3 +1036,17 @@ async def test_sunionstore(self, cache: AsyncValkeyCache): await cache.asadd("foo2", "bar2", "bar3") assert await cache.asunionstore("foo3", "foo1", "foo2") == 3 assert await cache.asmembers("foo3") == {"bar1", "bar2", "bar3"} + + async def test_clear(self, cache: AsyncValkeyCache): + await cache.aset("foo", "bar") + value_from_cache = await cache.aget("foo") + assert value_from_cache == "bar" + await cache.aclear() + value_from_cache_after_clear = await cache.aget("foo") + assert value_from_cache_after_clear is None + + async def test_clear_true(self, cache: AsyncValkeyCache): + await cache.aset("foo", "bar") + assert await cache.aget("foo") == "bar" + assert await cache.aclear() is True + assert await cache.aget("foo") is None