def test_load_empty_cache(self, mocker): wrapped = MemoryDataSet(-42) mocker.spy(wrapped, "load") cached_ds = CachedDataSet(wrapped) mocker.spy(cached_ds._cache, "load") assert cached_ds.load() == -42 assert wrapped.load.call_count == 1 assert cached_ds._cache.load.call_count == 0
def test_save_load_caching(self, mocker): wrapped = MemoryDataSet(-42) mocker.spy(wrapped, "load") mocker.spy(wrapped, "save") cached_ds = CachedDataSet(wrapped) mocker.spy(cached_ds._cache, "save") mocker.spy(cached_ds._cache, "load") cached_ds.save(42) assert cached_ds.load() == 42 assert wrapped.load.call_count == 0 assert wrapped.save.call_count == 1 assert cached_ds._cache.load.call_count == 1 assert cached_ds._cache.save.call_count == 1