Skip to content

Commit 3a5c1d0

Browse files
committed
TEST: Validate issue gh-1137
1 parent 2838c06 commit 3a5c1d0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

nibabel/tests/test_loadsave.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ..loadsave import load, read_img_data, _signature_matches_extension
1414
from ..filebasedimages import ImageFileError
1515
from ..tmpdirs import InTemporaryDirectory, TemporaryDirectory
16+
from ..openers import Opener
1617

1718
from ..optpkg import optional_package
1819
_, have_scipy, _ = optional_package('scipy')
@@ -82,6 +83,15 @@ def test_load_bad_compressed_extension(tmp_path, extension):
8283
load(file_path)
8384

8485

86+
@pytest.mark.parametrize("extension", [".gz", ".bz2"])
87+
def test_load_good_extension_with_bad_data(tmp_path, extension):
88+
file_path = tmp_path / f"img.nii{extension}"
89+
with Opener(file_path, "wb") as fobj:
90+
fobj.write(b"bad")
91+
with pytest.raises(ImageFileError, match="Cannot work out file type of .*"):
92+
load(file_path)
93+
94+
8595
def test_signature_matches_extension(tmp_path):
8696
gz_signature = b"\x1f\x8b"
8797
good_file = tmp_path / "good.gz"

0 commit comments

Comments
 (0)