diff --git a/fsspec/conftest.py b/fsspec/conftest.py index 393e4c465..47b49c939 100644 --- a/fsspec/conftest.py +++ b/fsspec/conftest.py @@ -17,7 +17,7 @@ def m(): """ m = fsspec.filesystem("memory") m.store.clear() - m.pseudo_dirs.clear() + m.pseudo_dirs = [""] try: yield m finally: diff --git a/fsspec/implementations/memory.py b/fsspec/implementations/memory.py index 334f9db26..9356a56eb 100644 --- a/fsspec/implementations/memory.py +++ b/fsspec/implementations/memory.py @@ -116,6 +116,9 @@ def makedirs(self, path, exist_ok=False): def rmdir(self, path): path = self._strip_protocol(path) + if path == "": + # silently avoid deleting FS root + return if path in self.pseudo_dirs: if not self.ls(path): self.pseudo_dirs.remove(path) @@ -124,7 +127,7 @@ def rmdir(self, path): else: raise FileNotFoundError(path) - def exists(self, path): + def exists(self, path, **kwargs): path = self._strip_protocol(path) return path in self.store or path in self.pseudo_dirs diff --git a/fsspec/implementations/tests/test_memory.py b/fsspec/implementations/tests/test_memory.py index 184c9eeda..c647fac9e 100644 --- a/fsspec/implementations/tests/test_memory.py +++ b/fsspec/implementations/tests/test_memory.py @@ -150,3 +150,9 @@ def test_seekable(m): f.seek(1) assert f.read(1) == "a" assert f.tell() == 2 + + +def test_remove_all(m): + m.touch("afile") + m.rm("/", recursive=True) + assert not m.ls("/")