Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
YasinKaryagdi committed Jun 13, 2024
1 parent a2b378d commit 02cb0d7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,35 @@ async def test_get_find():
mapping = {secrets.token_bytes(32): secrets.token_bytes(32) for _ in range(100)}

# Turn it into a shuffled iterable of pairs
pair = collections.namedtuple('pair', 'key value')
array = [pair(key=k, value=v) for k, v in mapping.items()]
pair = collections.namedtuple('pair', 'key value extra')
array = [pair(key=k, value=v, extra=secrets.token_bytes(32)) for k, v in mapping.items()]
random.shuffle(array)

# Confirm all values can be found
for key, value in mapping.items():
# Sync get
# Sync get with single attribute
item = utils.get(array, key=key)
assert item is not None
assert item.value == value

# Async get
# Async get with single attribute
item = await utils.get(async_iterate(array), key=key)
assert item is not None
assert item.value == value

# Sync get with multiple attributes
extra = next(i.extra for i in array if i.key == key)
item = utils.get(array, key=key, extra=extra)
assert item is not None
assert item.value == value
assert item.extra == extra

# Async get with multiple attributes
item = await utils.get(async_iterate(array), key=key, extra=extra)
assert item is not None
assert item.value == value
assert item.extra == extra

# Sync find
item = utils.find(lambda i: i.key == key, array)
assert item is not None
Expand Down

0 comments on commit 02cb0d7

Please sign in to comment.