Skip to content

Commit 9cbfaf5

Browse files
committed
Update tests/test_tifffile.py
1 parent ef07b21 commit 9cbfaf5

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

tests/test_tifffile.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Public data files can be requested from the author.
3838
Private data files are not available due to size and copyright restrictions.
3939

40-
:Version: 2025.5.26
40+
:Version: 2025.6.1
4141

4242
"""
4343

@@ -17933,6 +17933,56 @@ def strips():
1793317933
assert_array_equal(imread(fname), data)
1793417934

1793517935

17936+
@pytest.mark.parametrize('compression', [1, 8])
17937+
def test_write_iter_tiles_tuple(compression):
17938+
"""Test write tiles from iterator of tuple of bytes and bytecount."""
17939+
# https://github.com/cgohlke/tifffile/issues/301
17940+
data = random_data(numpy.uint16, (5, 3, 15, 17))
17941+
align = 4096
17942+
17943+
with TempFileName(f'write_iter_tiles_tuple_{compression}') as fname:
17944+
imwrite(
17945+
fname + 'f',
17946+
data,
17947+
tile=(16, 16),
17948+
compression=compression,
17949+
planarconfig='separate',
17950+
photometric='rgb',
17951+
)
17952+
17953+
def tiles():
17954+
with TiffFile(fname + 'f') as tif:
17955+
fh = tif.filehandle
17956+
for page in tif.pages:
17957+
for offset, bytecount in zip(
17958+
page.dataoffsets, page.databytecounts
17959+
):
17960+
fh.seek(offset)
17961+
strip = fh.read(bytecount)
17962+
strip += b'\x00' * (align - (len(strip) % align))
17963+
assert len(strip) % align == 0
17964+
yield strip, bytecount
17965+
17966+
imwrite(
17967+
fname,
17968+
tiles(),
17969+
shape=data.shape,
17970+
dtype=data.dtype,
17971+
tile=(16, 16),
17972+
compression=compression,
17973+
planarconfig='separate',
17974+
photometric='rgb',
17975+
align=align,
17976+
)
17977+
assert_array_equal(imread(fname), data)
17978+
with TiffFile(fname) as tif:
17979+
for page in tif.pages:
17980+
assert page.is_tiled
17981+
assert not page.is_contiguous
17982+
for offset in page.dataoffsets:
17983+
assert align % 4096 == 0
17984+
17985+
1793617986
@pytest.mark.parametrize('compression', [1, 8])
1793717987
@pytest.mark.parametrize('rowsperstrip', [5, 16])
1793817988
def test_write_iter_pages_none(compression, rowsperstrip):

0 commit comments

Comments
 (0)