|
23 | 23 | from .. import __version__ |
24 | 24 | from ..arrayproxy import ArrayProxy, get_obj_dtype, is_proxy, reshape_dataobj |
25 | 25 | from ..deprecator import ExpiredDeprecationError |
26 | | -from ..nifti1 import Nifti1Header |
| 26 | +from ..nifti1 import Nifti1Header, Nifti1Image |
27 | 27 | from ..openers import ImageOpener |
28 | 28 | from ..testing import memmap_after_ufunc |
29 | 29 | from ..tmpdirs import InTemporaryDirectory |
@@ -586,3 +586,20 @@ def test_copy(): |
586 | 586 | copied = proxy.copy() |
587 | 587 | assert islock(copied._lock) |
588 | 588 | assert proxy._lock is copied._lock |
| 589 | + |
| 590 | + |
| 591 | +def test_copy_with_indexed_gzip_handle(tmp_path): |
| 592 | + indexed_gzip = pytest.importorskip('indexed_gzip') |
| 593 | + |
| 594 | + spec = ((50, 50, 50, 50), np.float32, 352, 1, 0) |
| 595 | + data = np.arange(np.prod(spec[0]), dtype=spec[1]).reshape(spec[0]) |
| 596 | + fname = str(tmp_path / 'test.nii.gz') |
| 597 | + Nifti1Image(data, np.eye(4)).to_filename(fname) |
| 598 | + |
| 599 | + with indexed_gzip.IndexedGzipFile(fname) as fobj: |
| 600 | + proxy = ArrayProxy(fobj, spec) |
| 601 | + copied = proxy.copy() |
| 602 | + |
| 603 | + assert proxy.file_like is copied.file_like |
| 604 | + assert np.array_equal(proxy[0, 0, 0], copied[0, 0, 0]) |
| 605 | + assert np.array_equal(proxy[-1, -1, -1], copied[-1, -1, -1]) |
0 commit comments