Skip to content

Commit

Permalink
Run test cases on hns
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Oct 18, 2024
1 parent 2b75df4 commit 2586871
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
29 changes: 19 additions & 10 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,21 @@ def info(

bucket_type = self._get_bucket_type(bucket)
if bucket_type == TOS_BUCKET_TYPE_FNS:
if info := self._object_info(bucket, key, version_id):
return info
result = self._object_info(bucket, key, version_id)

return self._get_dir_info(bucket, key, path, fullpath)
if not result:
result = self._get_dir_info(bucket, key, fullpath)
else:
# Priority is given to judging dir, followed by file.
if info := self._get_dir_info(bucket, key, path, fullpath):
return info
result = self._get_dir_info(bucket, key, fullpath)

return self._object_info(bucket, key, version_id)
if not result:
result = self._object_info(bucket, key, version_id)

if not result:
raise FileNotFoundError(f"Can not get information for path: {path}")

return result

def exists(self, path: str, **kwargs: Any) -> bool:
"""Check if a path exists in the TOS.
Expand Down Expand Up @@ -1263,6 +1268,9 @@ def cp_file(
bucket, key, vers = self._split_path(path1)

info = self.info(path1, bucket, key, version_id=vers)
if not info:
raise FileNotFoundError(f"Can not get information for path: {path1}")

if info["type"] == "directory":
logger.warning("Do not support copy directory %s.", path1)
return
Expand Down Expand Up @@ -1690,6 +1698,7 @@ def _find_file_dir(
out = [self.info(path)]
except FileNotFoundError:
out = []

dirs = {
self._parent(o["name"]): {
"Key": self._parent(o["name"]).rstrip("/"),
Expand Down Expand Up @@ -1782,7 +1791,7 @@ def _bucket_info(self, bucket: str) -> dict:

def _object_info(
self, bucket: str, key: str, version_id: Optional[str] = None
) -> dict:
) -> Optional[dict]:
"""Get the information of an object.
Parameters
Expand Down Expand Up @@ -1846,9 +1855,9 @@ def _object_info(
except Exception as e:
raise TosfsError(f"Tosfs failed with unknown error: {e}") from e

return {}
return None

def _get_dir_info(self, bucket: str, key: str, path: str, fullpath: str) -> dict:
def _get_dir_info(self, bucket: str, key: str, fullpath: str) -> Optional[dict]:
try:
# We check to see if the path is a directory by attempting to list its
# contexts. If anything is found, it is indeed a directory
Expand All @@ -1871,7 +1880,7 @@ def _get_dir_info(self, bucket: str, key: str, path: str, fullpath: str) -> dict
"type": "directory",
}

return {}
return None
except (TosClientError, TosServerError) as e:
raise e
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion tosfs/tests/test_fsspec_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def test_info(fsspecfs: Any, bucket: str, temporary_workspace: str):
# Some FS might not support 'size' for directories, so it's not strictly checked

# Test non-existent path
fsspecfs.info(f"{bucket}/{temporary_workspace}/non_existent")
with pytest.raises(FileNotFoundError):
fsspecfs.info(f"{bucket}/{temporary_workspace}/non_existent")

# Test protocol stripping
protocol_included_path = fsspecfs._strip_protocol(file_path)
Expand Down

0 comments on commit 2586871

Please sign in to comment.