Skip to content

Commit

Permalink
test: update test_clear and test_clear_nocache to test the new ca…
Browse files Browse the repository at this point in the history
…chemap deletion behaviour

These tests call `.clear()` on a non-existent cache key.
Previously, this would have resulted in an exception being thrown.
The new behaviour should be to throw no exceptions.
  • Loading branch information
dartt0n committed Oct 21, 2024
1 parent 708013f commit 6b0a704
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/test_dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ async def idx(keys: List[int]) -> List[Tuple[int, int]]:

assert await loader.load_many([1, 2, 3]) == [(1, 4), (2, 4), (3, 4)]

loader.clear(-1)

assert await loader.load_many([1, 2, 3]) == [(1, 4), (2, 4), (3, 4)]


@pytest.mark.asyncio
async def test_clear_nocache():
Expand All @@ -301,11 +305,6 @@ async def idx(keys: List[int]) -> List[Tuple[int, int]]:

loader = DataLoader(load_fn=idx, cache=False)

try:
loader.clean(1) # no effect on non-cached values
except Exception as e:
raise AssertionError("clean non-cached values does not raise KeyError")

assert await loader.load_many([1, 2, 3]) == [(1, 1), (2, 1), (3, 1)]

loader.clear(1)
Expand All @@ -320,6 +319,10 @@ async def idx(keys: List[int]) -> List[Tuple[int, int]]:

assert await loader.load_many([1, 2, 3]) == [(1, 4), (2, 4), (3, 4)]

loader.clear(-1)

assert await loader.load_many([1, 2, 3]) == [(1, 5), (2, 5), (3, 5)]


@pytest.mark.asyncio
async def test_dont_dispatch_cancelled():
Expand Down

0 comments on commit 6b0a704

Please sign in to comment.