Skip to content

Commit

Permalink
test clear() return value
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 committed Sep 21, 2024
1 parent 17323e0 commit de8a5fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
24 changes: 16 additions & 8 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
22 changes: 14 additions & 8 deletions tests/tests_async/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit de8a5fb

Please sign in to comment.