Skip to content

Commit

Permalink
#209: Add tests for custom LRU cache
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Apr 6, 2021
1 parent 6acfd48 commit cad5677
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/icat/test_lru_cache.py
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

0 comments on commit cad5677

Please sign in to comment.