Skip to content

Commit

Permalink
Unify redis cm (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
dycw authored Sep 11, 2024
1 parent 93c390f commit e575bb5
Show file tree
Hide file tree
Showing 5 changed files with 587 additions and 1,004 deletions.
59 changes: 29 additions & 30 deletions src/tests/test_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
_ZONED_DATETIMES_LEFT_MOST,
_ZONED_DATETIMES_RIGHT_MOST,
Shape,
YieldRedisContainer,
aiosqlite_engines,
assume_does_not_raise,
bool_arrays,
Expand All @@ -57,7 +56,6 @@
months,
random_states,
redis_cms,
redis_cms_async,
sets_fixed_length,
settings_with_reduced_examples,
setup_hypothesis_profiles,
Expand Down Expand Up @@ -490,37 +488,38 @@ def test_main(self, *, data: DataObject) -> None:

@SKIPIF_CI_AND_NOT_LINUX
class TestRedisCMs:
@given(yield_redis=redis_cms(), value=integers())
def test_sync_core(self, *, yield_redis: YieldRedisContainer, value: int) -> None:
with yield_redis() as redis:
assert not redis.client.exists(redis.key)
_ = redis.client.set(redis.key, value)
result = int(cast(str, redis.client.get(redis.key)))
assert result == value

@given(yield_redis=redis_cms(), value=int32s())
def test_sync_ts(self, *, yield_redis: YieldRedisContainer, value: int) -> None:
with yield_redis() as redis:
assert not redis.client.exists(redis.key)
_ = redis.ts.add(redis.key, "*", value)
res_timestamp, res_value = redis.ts.get(redis.key)
assert isinstance(res_timestamp, int)
assert int(res_value) == value

@given(data=data(), value=integers())
async def test_async_core(self, *, data: DataObject, value: int) -> None:
async with redis_cms_async(data) as redis:
assert not await redis.client.exists(redis.key)
_ = await redis.client.set(redis.key, value)
result = int(cast(str, await redis.client.get(redis.key)))
@given(data=data(), value=int32s())
async def test_core(self, *, data: DataObject, value: int) -> None:
import redis
import redis.asyncio

async with redis_cms(data) as container:
match container.client:
case redis.Redis() as client:
assert not client.exists(container.key)
_ = client.set(container.key, value)
result = int(cast(str, client.get(container.key)))
case redis.asyncio.Redis() as client:
assert not await client.exists(container.key)
_ = await client.set(container.key, value)
result = int(cast(str, await client.get(container.key)))
assert result == value

@given(data=data(), value=int32s())
async def test_async_ts(self, *, data: DataObject, value: int) -> None:
async with redis_cms_async(data) as redis:
assert not await redis.client.exists(redis.key)
_ = await redis.ts.add(redis.key, "*", value)
res_timestamp, res_value = await redis.ts.get(redis.key)
async def test_ts(self, *, data: DataObject, value: int) -> None:
import redis
import redis.asyncio

async with redis_cms(data) as container:
match container.client:
case redis.Redis() as client:
assert not client.exists(container.key)
_ = container.ts.add(container.key, "*", value)
res_timestamp, res_value = container.ts.get(container.key)
case redis.asyncio.Redis() as client:
assert not await client.exists(container.key)
_ = await container.ts.add(container.key, "*", value)
res_timestamp, res_value = await container.ts.get(container.key)
assert isinstance(res_timestamp, int)
assert int(res_value) == value

Expand Down
Loading

0 comments on commit e575bb5

Please sign in to comment.