Skip to content

Commit

Permalink
Add more encompassing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong committed Jan 8, 2024
1 parent f1be5b5 commit e517de1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/io_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ def test_list_files():
)
assert sorted(get_hidden_files) == [".chan-metadata.tiff"]

# test delimiter functionality of substr matching
with tempfile.TemporaryDirectory() as temp_dir:
filenames = ["fov1.tiff", "fov1_test.tiff", "fov10.tiff", "fov2.tiff", "fov2_test.tiff",
"fov20.tiff", "fov3.tiff", "fov3_test.tiff", "fov30.tiff"]
for filename in filenames:
pathlib.Path(os.path.join(temp_dir, filename)).touch()

# test substrs is not list (single string)
get_txt = io_utils.list_files(temp_dir, substrs="fov1")
assert sorted(get_txt) == sorted(["fov1.tiff", "fov1_test.tiff"])

# test substrs is list
get_test_and_other = io_utils.list_files(temp_dir, substrs=["fov1", "fov2"])
assert sorted(get_test_and_other) == sorted(
["fov1.tiff", "fov1_test.tiff", "fov2.tiff", "fov2_test.tiff"]
)


def test_remove_file_extensions():
# test a mixture of file paths and extensions
Expand Down Expand Up @@ -243,3 +260,24 @@ def test_list_folders():
temp_dir, substrs=".hidden_dir", exact_match=True, ignore_hidden=False
)
assert get_hidden_dirs == [".hidden_dir"]

# test delimiter functionality of substr matching
with tempfile.TemporaryDirectory() as temp_dir:
dirnames = ["test1", "test1_folder", "test10", "test2", "test2_folder",
"test20", "test3", "test3_folder", "test30"]

dirnames.sort()
for dirname in dirnames:
os.mkdir(os.path.join(temp_dir, dirname))

# test substrs is not list (single string)
get_txt = io_utils.list_folders(temp_dir, substrs="test1", exact_match=False)
assert sorted(get_txt) == sorted(["test1", "test1_folder"])

# test substrs is list
get_test_and_other = io_utils.list_folders(
temp_dir, substrs=["test1", "test2"], exact_match=False
)
assert sorted(get_test_and_other) == sorted(
["test1", "test1_folder", "test2", "test2_folder"]
)

0 comments on commit e517de1

Please sign in to comment.