diff --git a/tosfs/core.py b/tosfs/core.py index 4b2d212..7094b3f 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -892,7 +892,7 @@ def cp_file( info = self.info(path1, bucket, key, version_id=vers) if info["type"] == "directory": - logger.warning(f"Do not support copy directory {path1}.") + logger.warning("Do not support copy directory %s.", path1) return size = info["size"] diff --git a/tosfs/tests/test_fsspec.py b/tosfs/tests/test_fsspec.py index cbfe5bc..3d847c5 100644 --- a/tosfs/tests/test_fsspec.py +++ b/tosfs/tests/test_fsspec.py @@ -347,40 +347,68 @@ def test_walk(fsspecfs: Any, bucket: str, temporary_workspace: str): f.write(b"File 3 content") # Test walk with maxdepth=None and topdown=True - result = list(fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=None, topdown=True)) + result = list( + fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=None, topdown=True) + ) expected = [ - (fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), ["nested_dir_1"], ["file_1.txt"]), + ( + fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), + ["nested_dir_1"], + ["file_1.txt"], + ), (fsspecfs._strip_protocol(nested_dir_1), ["nested_dir_2"], ["file_2.txt"]), (fsspecfs._strip_protocol(nested_dir_2), [], ["file_3.txt"]), ] assert result == expected, f"Expected {expected}, got {result}" # Test walk with maxdepth=1 and topdown=True - result = list(fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=1, topdown=True)) + result = list( + fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=1, topdown=True) + ) expected = [ - (fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), ["nested_dir_1"], ["file_1.txt"]), + ( + fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), + ["nested_dir_1"], + ["file_1.txt"], + ), ] assert result == expected, f"Expected {expected}, got {result}" # Test walk with maxdepth=2 and topdown=True - result = list(fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=2, topdown=True)) + result = list( + fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=2, topdown=True) + ) expected = [ - (fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), ["nested_dir_1"], ["file_1.txt"]), + ( + fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), + ["nested_dir_1"], + ["file_1.txt"], + ), (fsspecfs._strip_protocol(nested_dir_1), ["nested_dir_2"], ["file_2.txt"]), ] assert result == expected, f"Expected {expected}, got {result}" # Test walk with maxdepth=None and topdown=False - result = list(fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=None, topdown=False)) + result = list( + fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=None, topdown=False) + ) expected = [ (fsspecfs._strip_protocol(nested_dir_2), [], ["file_3.txt"]), (fsspecfs._strip_protocol(nested_dir_1), ["nested_dir_2"], ["file_2.txt"]), - (fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), ["nested_dir_1"], ["file_1.txt"]), + ( + fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"), + ["nested_dir_1"], + ["file_1.txt"], + ), ] assert result == expected, f"Expected {expected}, got {result}" # Test walk with detail=True - result = list(fsspecfs.walk(f"{bucket}/{temporary_workspace}", maxdepth=None, topdown=True, detail=True)) + result = list( + fsspecfs.walk( + f"{bucket}/{temporary_workspace}", maxdepth=None, topdown=True, detail=True + ) + ) expected_dir_num = 3 assert ( len(result) == expected_dir_num @@ -518,31 +546,14 @@ def test_du(fsspecfs: Any, bucket: str, temporary_workspace: str): assert sizes == expected_sizes, f"Expected sizes {expected_sizes}, got {sizes}" # Test maxdepth - sizes_maxdepth_1 = fsspecfs.du(f"{bucket}/{temporary_workspace}", total=False, maxdepth=2) + sizes_maxdepth_1 = fsspecfs.du( + f"{bucket}/{temporary_workspace}", total=False, maxdepth=2 + ) expected_sizes_maxdepth_1 = {fsspecfs._strip_protocol(file_path): 13} assert ( sizes_maxdepth_1 == expected_sizes_maxdepth_1 ), f"Expected sizes {expected_sizes_maxdepth_1}, got {sizes_maxdepth_1}" - # Test withdirs=True - # sizes_withdirs = fsspecfs.du(f"{bucket}/{temporary_workspace}", total=False, withdirs=True) - # expected_sizes_withdirs = { - # fsspecfs._strip_protocol(f"{bucket}/{temporary_workspace}"): 27, - # fsspecfs._strip_protocol(dir_path): 27, - # fsspecfs._strip_protocol(file_path): 13, - # fsspecfs._strip_protocol(nested_dir_path): 14, - # fsspecfs._strip_protocol(nested_file_path): 14, - # } - # assert ( - # sizes_withdirs == expected_sizes_withdirs - # ), f"Expected sizes {expected_sizes_withdirs}, got {sizes_withdirs}" - - # total_sizes_withdirs = fsspecfs.du(f"{bucket}/{temporary_workspace}", total=True, withdirs=True) - # expected_total_sizes_withdirs = 95 - # assert ( - # total_sizes_withdirs == expected_total_sizes_withdirs - # ), f"Expected sizes {expected_total_sizes_withdirs}, got {total_sizes_withdirs}" - def test_isdir(fsspecfs: Any, bucket: str, temporary_workspace: str): # Setup