def test_without_preload(engine, loader): cache = caching.FactCache(engine, 'test', loader=loader, preload=False) # Check the engine with the compound key, expecting None assert_that(engine.get('testempty'), none()) # On get, the data is loaded in background, key returned immediately assert_that(cache.get('empty'), equal_to(False)) wait_for(cache) assert_that(engine.get('testhit'), not_none())
def _cache_with_mock_engine(engine, preload=True): def loads(): return {str(n): 'is ' + str(n) for n in range(0, 20)} cache = caching.FactCache(engine, prefix='test_', loader=loads, preload=preload) return cache
def _cache(engine, loader, preload=True): return caching.FactCache(engine, 'test', loader=loader, preload=preload)
def test_with_preload(engine, loader): cache = caching.FactCache(engine, 'test', loader=loader, preload=True) wait_for(cache) assert_that(engine.get('testhit'), not_none())
def test_get_dict(engine, loader): cache = caching.FactCache(engine, 'test', loader=loader, preload=True) wait_for(cache) assert_that(cache.get('dict'), equal_to({'foo': 'bar'}))
def test_get_list(engine, loader): cache = caching.FactCache(engine, 'test', loader=loader, preload=True) wait_for(cache) assert_that(cache.get('list'), equal_to([1, 2, 3]))
def test_get_miss(engine, loader): cache = caching.FactCache(engine, 'test', loader=loader, preload=True) wait_for(cache) assert_that(cache.get('miss'), none())