Skip to content

Commit 0f462db

Browse files
committed
add create_profile() test for image creation_options
1 parent c23de59 commit 0f462db

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/test_common.py

+59
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,65 @@ def test_create_profile_image(
555555
)
556556

557557

558+
@pytest.mark.parametrize(
559+
'driver, creation_options',
560+
[
561+
(
562+
Driver.gtiff,
563+
dict(
564+
tiled=True,
565+
blockxsize=256,
566+
blockysize=256,
567+
compress='jpeg',
568+
photometric='ycbcr',
569+
jpeg_quality=90,
570+
),
571+
),
572+
(Driver.cog, dict(blocksize=256, compress='jpeg', quality=90)),
573+
],
574+
)
575+
def test_create_profile_image_creation_options(
576+
tmp_path: Path, driver: Driver, creation_options: dict
577+
):
578+
"""Test the ``create_profile()`` profile with ``creation_options`` generates an image with the
579+
correct configuration.
580+
"""
581+
shape = (3, 1, 1)
582+
dtype = 'uint8'
583+
write_mask = True
584+
profile, write_mask = common.create_profile(
585+
driver=driver,
586+
shape=shape,
587+
dtype=dtype,
588+
write_mask=write_mask,
589+
creation_options=creation_options,
590+
)
591+
array = 100 * np.ones(shape, dtype=dtype)
592+
test_file = tmp_path.joinpath('test.tif')
593+
with rio.open(test_file, 'w', **profile) as im:
594+
im.write(array)
595+
if write_mask:
596+
im.write_mask(array > 0)
597+
598+
with rio.open(test_file, 'r') as im:
599+
# driver
600+
assert im.driver.lower() == 'gtiff'
601+
im_struct = im.tags(ns='IMAGE_STRUCTURE')
602+
if driver is Driver.gtiff:
603+
assert 'LAYOUT' not in im_struct or im_struct['LAYOUT'].lower() != 'cog'
604+
else:
605+
assert im_struct['LAYOUT'].lower() == 'cog'
606+
607+
# tiling
608+
assert im.profile['tiled'] == True
609+
assert im.profile['blockxsize'] == im.profile['blockysize'] == 256
610+
611+
# compression
612+
assert im.compression.value.lower() == 'jpeg'
613+
assert im.photometric is PhotometricInterp.ycbcr
614+
assert im_struct['JPEG_QUALITY'] == '90'
615+
616+
558617
@pytest.mark.parametrize(
559618
'src_dtype, dst_dtype',
560619
[

0 commit comments

Comments
 (0)