diff --git a/gufe/storage/stagingregistry.py b/gufe/storage/stagingregistry.py index 51d2696b..40b311a9 100644 --- a/gufe/storage/stagingregistry.py +++ b/gufe/storage/stagingregistry.py @@ -32,7 +32,7 @@ def _safe_to_delete_file( class StagingRegistry: - """PathLike local representation of an :class:`.ExternalStorage`. + """Local representation of an :class:`.ExternalStorage`. This connects objects on a local filesystem to the key-value store of a (possibly remote) :class:`.ExternalStorage`. It presents a FileLike @@ -202,9 +202,6 @@ def _load_file_from_external(self, external: ExternalStorage, def __truediv__(self, path: Union[PathLike, str]): return StagingPath(root=self, path=path) - def __fspath__(self): - return str(self.staging_dir) - def __repr__(self): return ( f"{self.__class__.__name__}('{self.scratch}', {self.external})" diff --git a/gufe/tests/storage/test_stagingregistry.py b/gufe/tests/storage/test_stagingregistry.py index 392d34d9..d5e5d71e 100644 --- a/gufe/tests/storage/test_stagingregistry.py +++ b/gufe/tests/storage/test_stagingregistry.py @@ -42,7 +42,7 @@ def read_only_with_overwritten(root_with_contents): delete_staging=root_with_contents.delete_staging, read_only=True ) - filename = pathlib.Path(read_only) / "old_unit/data.txt" + filename = (read_only / "old_unit/data.txt").as_path() assert not filename.exists() staged = read_only / "old_unit/data.txt" assert not filename.exists() @@ -140,6 +140,12 @@ def test_repr(self, root): assert r.startswith("SharedStaging") assert "MemoryStorage" in r + def test_fspath_fail(self, root): + # ensure that we get an error on os.path.join (or really, anything + # that hits os.fspath) + with pytest.raises(TypeError): + os.path.join(root, "filename.txt") + @pytest.mark.parametrize('pathlist', [ ['file.txt'], ['dir', 'file.txt'] ]) @@ -266,8 +272,7 @@ def test_transfer_read_only(self, read_only_with_overwritten, caplog): def test_cleanup(self, root_with_contents): root_with_contents.delete_staging = True # slightly naughty - root_path = pathlib.Path(root_with_contents.__fspath__()) - path = root_path / "new_unit/data.txt" + path = (root_with_contents / "new_unit/data.txt").as_path() assert path.exists() root_with_contents.cleanup() assert not path.exists() @@ -303,7 +308,7 @@ def test_cleanup_directory(self, root, caplog): assert "During staging cleanup, the directory" in caplog.text def test_register_cleanup_preexisting_file(self, root): - filename = pathlib.Path(root.__fspath__()) / "new_unit/foo.txt" + filename = (root / "new_unit/foo.txt").as_path() filename.parent.mkdir(parents=True, exist_ok=True) filename.touch() root.external.store_bytes("new_unit/foo.txt", b"") @@ -350,7 +355,7 @@ def test_delete_file_safe(self, tmp_path, is_safe): assert permanent._delete_file_safe(my_file) is is_safe def test_load_missing_for_transfer(self, permanent): - fname = pathlib.Path(permanent) / "old_unit/data.txt" + fname = (permanent / "old_unit/data.txt").as_path() assert not fname.exists() staging = permanent / "old_unit/data.txt" staging.__fspath__()