Skip to content

Commit

Permalink
TEST: Check IndexedGzipFile ArrayProxys are copied properly
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Dec 6, 2023
1 parent 65228f0 commit 1c1845f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion nibabel/tests/test_arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .. import __version__
from ..arrayproxy import ArrayProxy, get_obj_dtype, is_proxy, reshape_dataobj
from ..deprecator import ExpiredDeprecationError
from ..nifti1 import Nifti1Header
from ..nifti1 import Nifti1Header, Nifti1Image
from ..openers import ImageOpener
from ..testing import memmap_after_ufunc
from ..tmpdirs import InTemporaryDirectory
Expand Down Expand Up @@ -586,3 +586,20 @@ def test_copy():
copied = proxy.copy()
assert islock(copied._lock)
assert proxy._lock is copied._lock


def test_copy_with_indexed_gzip_handle(tmp_path):
indexed_gzip = pytest.importorskip('indexed_gzip')

spec = ((50, 50, 50, 50), np.float32, 352, 1, 0)
data = np.arange(np.prod(spec[0]), dtype=spec[1]).reshape(spec[0])
fname = str(tmp_path / 'test.nii.gz')
Nifti1Image(data, np.eye(4)).to_filename(fname)

with indexed_gzip.IndexedGzipFile(fname) as fobj:
proxy = ArrayProxy(fobj, spec)
copied = proxy.copy()

assert proxy.file_like is copied.file_like
assert np.array_equal(proxy[0, 0, 0], copied[0, 0, 0])
assert np.array_equal(proxy[-1, -1, -1], copied[-1, -1, -1])

0 comments on commit 1c1845f

Please sign in to comment.