def test_cache_maximum_size_1(self): cache = Cache(max_cache_size=2) cache.update(key='a', data=self.data_dict['a']) cache.update(key='b', data=self.data_dict['b']) # override is True by default, but this makes it explicit that it is testing for this (default) situation cache.update(key='c', data=self.data_dict['c'], override=True) self.assertFalse('a' in cache)
def __init__(self, antibody_objects=None, path=None, verbose=True, show_progressbar=True, n_threads=10): super().__init__(antibody_objects=antibody_objects) if antibody_objects: self.load() else: self.__init__(antibody_objects=ChainCollection.load_from_file( path=path, verbose=verbose, show_progressbar=show_progressbar, n_threads=n_threads)) self._cache = Cache(max_cache_size=5)
def test_cache_maximum_size_exception(self): cache = Cache(max_cache_size=2) cache.update(key='a', data=self.data_dict['a']) cache.update(key='b', data=self.data_dict['b']) self.assertRaises(ValueError, cache.update, 'c', self.data_dict['c'], False)
def test_cache_maximum_size_2(self): cache = Cache(max_cache_size=2) cache.update(key='a', data=self.data_dict['a']) cache.update(key='b', data=self.data_dict['b']) cache.update(key='c', data=self.data_dict['c'], override=True) self.assertEqual(len(cache), 2)
def test_cache_empty(self): cache = Cache() cache.update(key='a', data=self.data_dict['a']) cache.update(key='b', data=self.data_dict['b']) cache.empty_cache() self.assertEqual(len(cache), 0)
def test_cache_remove_key(self): cache = Cache() cache.update(key='a', data=self.data_dict['a']) cache.update(key='b', data=self.data_dict['b']) cache.remove('a') self.assertFalse('a' in cache)
def test_contains(self): cache = Cache() cache.update(key='a', data=self.data_dict['a']) self.assertTrue('a' in cache)
def test_cache_update_2(self): # check if cache works when adding a second item cache = Cache() cache.update(key='a', data=self.data_dict['a']) cache.update(key='b', data=self.data_dict['b']) self.assertEqual(cache['b'], self.data_dict['b'])
def test_cache_update_1(self): cache = Cache() cache.update(key='a', data=self.data_dict['a']) self.assertEqual(cache['a'], self.data_dict['a'])
def test_cache_instantiation(self): cache = Cache() self.assertIsInstance(cache, Cache)