From 6b0a704b97ee37128cb7e553446aa565c2cf769a Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 21 Oct 2024 10:43:50 +0300 Subject: [PATCH] test: update `test_clear` and `test_clear_nocache` to test the new cachemap 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. --- tests/test_dataloaders.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_dataloaders.py b/tests/test_dataloaders.py index adee76dfb9..e277e9971e 100644 --- a/tests/test_dataloaders.py +++ b/tests/test_dataloaders.py @@ -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(): @@ -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) @@ -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():