Skip to content

Commit

Permalink
GDriveFileSystem: Raise FIleNotFoundError on ls. (#283)
Browse files Browse the repository at this point in the history
* GDriveFileSystem: Raise `FIleNotFoundError` on `ls`.

Per https://github.com/iterative/dvc/issues/9607

* Update pydrive2/fs/spec.py

Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com>

* black

* Test for empty dir in ls (#284)

* test_ls: create dir

mkdir in GDriveFileSystem is a noop.

---------

Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com>
Co-authored-by: skshetry <18718008+skshetry@users.noreply.github.com>
Co-authored-by: Saugat Pachhai (सौगात) <suagatchhetri@outlook.com>
  • Loading branch information
4 people authored Jun 22, 2023
1 parent ad45ca6 commit 37551b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pydrive2/fs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ def ls(self, path, detail=False):
dir_ids = self._path_to_item_ids(base)

if not dir_ids:
return None
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), path
)

root_path = posixpath.join(bucket, base)
contents = []
Expand Down
12 changes: 10 additions & 2 deletions pydrive2/test/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ def test_rm(fs, remote_dir):
assert not fs.exists(remote_dir + "/dir/c/a")


def test_ls(fs, remote_dir):
fs.mkdir(remote_dir + "dir/")
def test_ls(fs: GDriveFileSystem, remote_dir):
_, base = fs.split_path(remote_dir + "dir/")
fs._path_to_item_ids(base, create=True)
assert fs.ls(remote_dir + "dir/") == []

files = set()
for no in range(8):
file = remote_dir + f"dir/test_{no}"
Expand All @@ -138,6 +141,11 @@ def by_name(details):
assert dirs == expected


def test_ls_non_existing_dir(fs, remote_dir):
with pytest.raises(FileNotFoundError):
fs.ls(remote_dir + "dir/")


def test_find(fs, remote_dir):
fs.mkdir(remote_dir + "/dir")

Expand Down

0 comments on commit 37551b3

Please sign in to comment.