-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#209: Add tests for custom LRU cache
- Loading branch information
1 parent
6acfd48
commit cad5677
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from cachetools import cached | ||
|
||
from datagateway_api.common.config import config | ||
from datagateway_api.common.icat.lru_cache import ExtendedLRUCache | ||
|
||
|
||
class TestLRUCache: | ||
def test_valid_cache_creation(self): | ||
test_cache = ExtendedLRUCache() | ||
assert test_cache.maxsize == config.get_client_cache_size() | ||
|
||
def test_valid_popitem(self, icat_client): | ||
test_cache = ExtendedLRUCache() | ||
|
||
test_cache.popitem = MagicMock(side_effect=test_cache.popitem) | ||
|
||
@cached(cache=test_cache) | ||
def get_cached_client(cache_number): | ||
return icat_client | ||
|
||
for cache_number in range(config.get_client_cache_size() + 1): | ||
get_cached_client(cache_number) | ||
|
||
assert test_cache.popitem.called |