예제 #1
0
    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()
예제 #2
0
    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
예제 #3
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}]>")
예제 #4
0
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)
예제 #5
0
    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
예제 #6
0
    def test_path(self, tmpdir):
        fc = FileCache(Path(tmpdir))

        assert isinstance(fc.path, Path)
        assert str(fc.path) == str(tmpdir)
예제 #7
0
 def test_invalid_path(self):
     with pytest.raises(TypeError):
         FileCache(42)