Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDriveFileSystem: Raise FIleNotFoundError on ls. #283

Merged
merged 5 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/") == []
Comment on lines +120 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, fs.mkdir() is not implemented in GDriveFileSystem. I was not sure if it was needed as it has been working fine for so long. So I only fixed in test to create a directory.


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/")
skshetry marked this conversation as resolved.
Show resolved Hide resolved


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

Expand Down