Skip to content

Commit bb9822e

Browse files
committed
test(listdir): add tests for invalid regex and recursive matching
* Implement test for invalid regex returning an empty list. * Add test for recursive regex matching that verifies absolute paths. CODECOV_TESTING
1 parent 4e63c39 commit bb9822e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/test_pathtools.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,28 @@ def test_listdir_matching_various(tmpdir):
157157
# expected alphanumeric order
158158
assert res_sorted.index("img1.tif") < res_sorted.index("img2.tif")
159159
assert res_sorted.index("img2.tif") < res_sorted.index("img10.tif")
160+
161+
162+
def test_listdir_matching_invalid_regex(tmpdir):
163+
"""Invalid regular expressions should result in an empty list."""
164+
base = tmpdir.mkdir("base_invalid_regex")
165+
base.join("a.tif").write("x")
166+
167+
# invalid regex should not raise but simply return an empty list
168+
res = listdir_matching(str(base), "([", regex=True)
169+
assert res == []
170+
171+
172+
def test_listdir_matching_recursive_regex_fullpath(tmpdir):
173+
"""Recursive search with regex and fullpath should return absolute paths."""
174+
base = tmpdir.mkdir("base_recursive")
175+
sub = base.mkdir("subdir")
176+
sub.join("s.tif").write("x")
177+
178+
# recursive + regex + fullpath should return absolute path including subdir
179+
res = listdir_matching(
180+
str(base), r".*\.tif$", regex=True, recursive=True, fullpath=True
181+
)
182+
assert any(os.path.isabs(x) for x in res)
183+
expected = os.path.join(str(sub), "s.tif")
184+
assert expected in res

0 commit comments

Comments
 (0)