Skip to content

Commit

Permalink
make sure match_paths can sub-select
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter committed May 16, 2024
1 parent c54c052 commit 5c7b751
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/test_internals/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os

from roiextractors.utils import match_paths
from tempfile import TemporaryDirectory


def test_match_paths():
# create temporary directory
with TemporaryDirectory() as tmpdir:
# create temporary files
files = [
"split_1.tif",
"split_2.tif",
"split_3.tif",
"split_4.tif",
"split_5.tif",
"split_6.tif",
"split_7.tif",
"split_8.tif",
"split_9.tif",
"split_10.tif",
]
for file in files:
with open(os.path.join(tmpdir, file), "w") as f:
f.write("")

# test match_paths
out = match_paths(tmpdir, "split_{split:d}.tif")
assert list(out.keys()) == [os.path.join(tmpdir, x) for x in files]
assert list([x["split"] for x in out.values()]) == list(range(1, 11))


def test_match_paths_sub_select():
# create temporary directory
with TemporaryDirectory() as tmpdir:
# create temporary files
files = [
"chanA_split_1.tif",
"chanA_split_2.tif",
"chanA_split_3.tif",
"chanA_split_4.tif",
"chanA_split_5.tif",
"chanB_split_1.tif",
"chanB_split_2.tif",
"chanB_split_3.tif",
"chanB_split_4.tif",
"chanB_split_5.tif",
]
for file in files:
with open(os.path.join(tmpdir, file), "w") as f:
f.write("")

# test match_paths
out = match_paths(tmpdir, "chanA_split_{split:d}.tif")
assert list(out.keys()) == [os.path.join(tmpdir, x) for x in files[:5]]
assert list([x["split"] for x in out.values()]) == list(range(1, 6))

0 comments on commit 5c7b751

Please sign in to comment.