Skip to content

Commit

Permalink
feat: use a better test for globs
Browse files Browse the repository at this point in the history
  • Loading branch information
john-jam committed Aug 22, 2023
1 parent 0070ddd commit a3c84f1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
27 changes: 18 additions & 9 deletions fsspec/tests/abstract/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,27 @@ def test_copy_directory_without_files_with_same_name_prefix(
fs_join,
fs_target,
fs_dir_and_file_with_same_name_prefix,
supports_empty_directories,
):
# Create the test dirs
source = fs_dir_and_file_with_same_name_prefix
target = fs_target

fs.cp(fs_join(source, "subdir"), fs_target, recursive=True)
# Test without glob
fs.cp(fs_join(source, "subdir"), target, recursive=True)

assert fs.isfile(fs_join(fs_target, "subfile.txt"))
assert not fs.isfile(fs_join(fs_target, "subdir.txt"))
assert fs.isfile(fs_join(target, "subfile.txt"))
assert not fs.isfile(fs_join(target, "subdir.txt"))

# Test if glob still works though
# (maybe not the best place for this test)
test = fs.glob(fs_join(source, "subdir*"))
assert sorted(test) == sorted(
[fs_join(source, "subdir"), fs_join(source, "subdir.txt")]
)
fs.rm([fs_join(target, "subfile.txt")])
if supports_empty_directories:
assert fs.ls(target) == []
else:
assert not fs.exists(target)

# Test with glob
fs.cp(fs_join(source, "subdir*"), target, recursive=True)

assert fs.isdir(fs_join(target, "subdir"))
assert fs.isfile(fs_join(target, "subdir", "subfile.txt"))
assert fs.isfile(fs_join(target, "subdir.txt"))
18 changes: 15 additions & 3 deletions fsspec/tests/abstract/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,20 @@ def test_get_directory_without_files_with_same_name_prefix(
):
# Create the test dirs
source = fs_dir_and_file_with_same_name_prefix
target = local_target

# Test without glob
fs.get(fs_join(source, "subdir"), target, recursive=True)

assert local_fs.isfile(local_join(target, "subfile.txt"))
assert not local_fs.isfile(local_join(target, "subdir.txt"))

local_fs.rm([local_join(target, "subfile.txt")])
assert local_fs.ls(target) == []

fs.get(fs_join(source, "subdir"), local_target, recursive=True)
# Test with glob
fs.get(fs_join(source, "subdir*"), target, recursive=True)

assert local_fs.isfile(local_join(local_target, "subfile.txt"))
assert not local_fs.isfile(local_join(local_target, "subdir.txt"))
assert local_fs.isdir(local_join(target, "subdir"))
assert local_fs.isfile(local_join(target, "subdir", "subfile.txt"))
assert local_fs.isfile(local_join(target, "subdir.txt"))
16 changes: 16 additions & 0 deletions fsspec/tests/abstract/put.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,27 @@ def test_put_directory_without_files_with_same_name_prefix(
fs_target,
local_join,
local_dir_and_file_with_same_name_prefix,
supports_empty_directories,
):
# Create the test dirs
source = local_dir_and_file_with_same_name_prefix
target = fs_target

# Test without glob
fs.put(local_join(source, "subdir"), fs_target, recursive=True)

assert fs.isfile(fs_join(fs_target, "subfile.txt"))
assert not fs.isfile(fs_join(fs_target, "subdir.txt"))

fs.rm([fs_join(target, "subfile.txt")])
if supports_empty_directories:
assert fs.ls(target) == []
else:
assert not fs.exists(target)

# Test with glob
fs.put(local_join(source, "subdir*"), fs_target, recursive=True)

assert fs.isdir(fs_join(fs_target, "subdir"))
assert fs.isfile(fs_join(fs_target, "subdir", "subfile.txt"))
assert fs.isfile(fs_join(fs_target, "subdir.txt"))

0 comments on commit a3c84f1

Please sign in to comment.