def test_bad_argument(self): with pytest.raises( ValueError, match=r"The argument type of `dataset` " r"should be either a dict/YAML representation " r"of the dataset, or the actual dataset object", ): _ = CachedDataSet(dataset="BadArgument")
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
def cached_ds(): wrapped = MemoryDataSet() return CachedDataSet(wrapped)
def test_str(self): assert ( str(CachedDataSet(MemoryDataSet(42))) == "CachedDataSet(cache={}, " "dataset={'data': <int>})" )