def _get_cache(self): cache = self.cache if cache is None: cache = _ImageCache.get_instance() elif cache == False: return None return cache
def _get_cache(self) -> Optional[ImageCache]: if self._cache is True: cache = ImageCache.get_instance() elif self._cache is False: cache = None else: cache = self._cache return cache
def test_cache_fifo_displacement(self): capacity = 2 cache = ImageCache(capacity) loaders = [lazy_image(None, loader=lambda p: object(), cache=cache) for _ in range(capacity + 1)] first_request = [loader() for loader in loaders[1 : ]] loaders[0]() # pop something from the cache second_request = [loader() for loader in loaders[2 : ]] second_request.insert(0, loaders[1]()) matches = sum([a is b for a, b in zip(first_request, second_request)]) self.assertEqual(matches, len(first_request) - 1)
def _get_cache(cache): if cache is None: cache = _ImageCache.get_instance() elif cache == False: return None return cache
def tearDown(self) -> None: ImageCache.get_instance().clear() return super().tearDown()
def setUp(self) -> None: ImageCache.get_instance().clear() return super().setUp()
def test_global_cache_is_accessible(self): loader = lazy_image(None, loader=lambda p: object()) self.assertTrue(loader() is loader()) self.assertEqual(ImageCache.get_instance().size(), 1)