Exemplo n.º 1
0
 def _get_cache(self):
     cache = self.cache
     if cache is None:
         cache = _ImageCache.get_instance()
     elif cache == False:
         return None
     return cache
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 def _get_cache(cache):
     if cache is None:
         cache = _ImageCache.get_instance()
     elif cache == False:
         return None
     return cache
Exemplo n.º 5
0
 def tearDown(self) -> None:
     ImageCache.get_instance().clear()
     return super().tearDown()
Exemplo n.º 6
0
 def setUp(self) -> None:
     ImageCache.get_instance().clear()
     return super().setUp()
Exemplo n.º 7
0
    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)