Skip to content

Commit 00a6434

Browse files
enhance supported format check (#5634) (#5640)
Signed-off-by: function2 <function2-llx@outlook.com> Fixes #5634. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [ ] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [x] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: function2 <function2-llx@outlook.com>
1 parent 025c107 commit 00a6434

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

monai/data/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,8 @@ def is_supported_format(filename: Union[Sequence[PathLike], PathLike], suffixes:
10991099
"""
11001100
filenames: Sequence[PathLike] = ensure_tuple(filename)
11011101
for name in filenames:
1102-
tokens: Sequence[str] = PurePath(name).suffixes
1103-
if len(tokens) == 0 or all("." + s.lower() not in "".join(tokens) for s in suffixes):
1102+
full_suffix = "".join(map(str.lower, PurePath(name).suffixes))
1103+
if all(f".{s.lower()}" not in full_suffix for s in suffixes):
11041104
return False
11051105

11061106
return True

tests/test_is_supported_format.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727

2828
TEST_CASE_6 = [{"filename": "1.3.12.2.1107.5.4.4.145.nii.gz", "suffixes": ["nii.gz"]}, True]
2929

30+
TEST_CASE_7 = [{"filename": "test.PNG", "suffixes": ["bmp", "png"]}, True]
31+
3032

3133
class TestIsSupportedFormat(unittest.TestCase):
32-
@parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, TEST_CASE_5, TEST_CASE_6])
34+
@parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, TEST_CASE_5, TEST_CASE_6, TEST_CASE_7])
3335
def test_value(self, input_param, result):
3436
self.assertEqual(is_supported_format(**input_param), result)
3537

0 commit comments

Comments
 (0)