def test_clear(self): "Test clear reset counter" lru_dict = LRUDictTransaction(48) Transaction().counter += 1 lru_dict.clear() self.assertEqual(lru_dict.counter, Transaction().counter)
def instanciate_values(Target, value): from ..modelstorage import ModelStorage, cache_size kwargs = {} ids = [] if issubclass(Target, ModelStorage): kwargs['_local_cache'] = LRUDictTransaction(cache_size()) kwargs['_ids'] = ids def instance(data): if isinstance(data, Target): return data elif isinstance(data, dict): if data.get('id', -1) >= 0: values = {} values.update(data) values.update(kwargs) ids.append(data['id']) else: values = data return Target(**values) else: ids.append(data) return Target(data, **kwargs) return tuple(instance(x) for x in (value or []))
def test_refresh(self): "Test refresh" lru_dict = LRUDictTransaction(48) lru_dict['foo'] = 'foo' lru_dict.refresh() self.assertEqual(lru_dict, {'foo': 'foo'}) Transaction().counter += 1 lru_dict.refresh() self.assertEqual(lru_dict, {}) self.assertEqual(lru_dict.counter, Transaction().counter)
def test_init(self): "Test init set to transaction counter" lru_dict = LRUDictTransaction(48) self.assertEqual(lru_dict.counter, Transaction().counter)