def test_clear_works(self, tmpdir): fc = FileCache(Path(tmpdir)) fc["foo"] = 42 assert Path(fc.path).exists() fc.clear() assert len(fc) == 0 assert not Path(tmpdir).exists()
def test_add_empty_value(self, tmpdir, val: Optional[pd.DataFrame]): fc = FileCache(Path(tmpdir)) fc["foo"] = val assert "foo" not in fc assert len(fc) == 0
def test_str_repr(self, tmpdir): fc = FileCache(Path(tmpdir)) assert ( str(fc) == f"<{fc.__class__.__name__}[size={len(fc)}, path={str(tmpdir)!r}]>") assert ( repr(fc) == f"<{fc.__class__.__name__}[size={len(fc)}, path={str(tmpdir)!r}]>")
def _cache_converter(value: Optional[Union[str, Path, Cache]]) -> Cache: """Convert ``value`` to :class:`omnipath._core.cache.Cache`.""" if isinstance(value, Cache): return value if value is None: return MemoryCache() return FileCache(value)
def test_cache_works(self, tmpdir): fc = FileCache(Path(tmpdir)) sentinel = object() assert "foo" not in fc fc["foo"] = 42 fc["bar.pickle"] = sentinel assert "foo" in fc assert "foo.pickle" in fc assert fc["bar.pickle"] is not sentinel
def test_path(self, tmpdir): fc = FileCache(Path(tmpdir)) assert isinstance(fc.path, Path) assert str(fc.path) == str(tmpdir)
def test_invalid_path(self): with pytest.raises(TypeError): FileCache(42)