mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Assert image type
This commit is contained in:
parent
cf7dd2f0e9
commit
66e6feeb70
|
@ -12,6 +12,7 @@ from PIL import Image, ImageSequence, PngImagePlugin
|
|||
# (referenced from https://wiki.mozilla.org/APNG_Specification)
|
||||
def test_apng_basic() -> None:
|
||||
with Image.open("Tests/images/apng/single_frame.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
assert im.n_frames == 1
|
||||
assert im.get_format_mimetype() == "image/apng"
|
||||
|
@ -20,6 +21,7 @@ def test_apng_basic() -> None:
|
|||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/single_frame_default.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.is_animated
|
||||
assert im.n_frames == 2
|
||||
assert im.get_format_mimetype() == "image/apng"
|
||||
|
@ -49,6 +51,7 @@ def test_apng_basic() -> None:
|
|||
)
|
||||
def test_apng_fdat(filename: str) -> None:
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
@ -56,31 +59,37 @@ def test_apng_fdat(filename: str) -> None:
|
|||
|
||||
def test_apng_dispose() -> None:
|
||||
with Image.open("Tests/images/apng/dispose_op_none.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_background.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||
assert im.getpixel((64, 32)) == (0, 0, 0, 0)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_background_final.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_previous.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_previous_final.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_previous_first.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||
assert im.getpixel((64, 32)) == (0, 0, 0, 0)
|
||||
|
@ -88,21 +97,25 @@ def test_apng_dispose() -> None:
|
|||
|
||||
def test_apng_dispose_region() -> None:
|
||||
with Image.open("Tests/images/apng/dispose_op_none_region.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_background_before_region.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||
assert im.getpixel((64, 32)) == (0, 0, 0, 0)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_background_region.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 0, 255, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 0, 0, 0)
|
||||
|
||||
with Image.open("Tests/images/apng/dispose_op_previous_region.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
@ -129,6 +142,7 @@ def test_apng_dispose_op_previous_frame() -> None:
|
|||
# ],
|
||||
# )
|
||||
with Image.open("Tests/images/apng/dispose_op_previous_frame.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (255, 0, 0, 255)
|
||||
|
||||
|
@ -142,26 +156,31 @@ def test_apng_dispose_op_background_p_mode() -> None:
|
|||
|
||||
def test_apng_blend() -> None:
|
||||
with Image.open("Tests/images/apng/blend_op_source_solid.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/blend_op_source_transparent.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||
assert im.getpixel((64, 32)) == (0, 0, 0, 0)
|
||||
|
||||
with Image.open("Tests/images/apng/blend_op_source_near_transparent.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 2)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 2)
|
||||
|
||||
with Image.open("Tests/images/apng/blend_op_over.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/blend_op_over_near_transparent.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 97)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
@ -175,6 +194,7 @@ def test_apng_blend_transparency() -> None:
|
|||
|
||||
def test_apng_chunk_order() -> None:
|
||||
with Image.open("Tests/images/apng/fctl_actl.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
@ -230,24 +250,28 @@ def test_apng_num_plays() -> None:
|
|||
|
||||
def test_apng_mode() -> None:
|
||||
with Image.open("Tests/images/apng/mode_16bit.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.mode == "RGBA"
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (0, 0, 128, 191)
|
||||
assert im.getpixel((64, 32)) == (0, 0, 128, 191)
|
||||
|
||||
with Image.open("Tests/images/apng/mode_grayscale.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.mode == "L"
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == 128
|
||||
assert im.getpixel((64, 32)) == 255
|
||||
|
||||
with Image.open("Tests/images/apng/mode_grayscale_alpha.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.mode == "LA"
|
||||
im.seek(im.n_frames - 1)
|
||||
assert im.getpixel((0, 0)) == (128, 191)
|
||||
assert im.getpixel((64, 32)) == (128, 191)
|
||||
|
||||
with Image.open("Tests/images/apng/mode_palette.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.mode == "P"
|
||||
im.seek(im.n_frames - 1)
|
||||
im = im.convert("RGB")
|
||||
|
@ -255,6 +279,7 @@ def test_apng_mode() -> None:
|
|||
assert im.getpixel((64, 32)) == (0, 255, 0)
|
||||
|
||||
with Image.open("Tests/images/apng/mode_palette_alpha.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.mode == "P"
|
||||
im.seek(im.n_frames - 1)
|
||||
im = im.convert("RGBA")
|
||||
|
@ -262,6 +287,7 @@ def test_apng_mode() -> None:
|
|||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/mode_palette_1bit_alpha.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.mode == "P"
|
||||
im.seek(im.n_frames - 1)
|
||||
im = im.convert("RGBA")
|
||||
|
@ -271,25 +297,31 @@ def test_apng_mode() -> None:
|
|||
|
||||
def test_apng_chunk_errors() -> None:
|
||||
with Image.open("Tests/images/apng/chunk_no_actl.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
|
||||
with pytest.warns(UserWarning):
|
||||
with Image.open("Tests/images/apng/chunk_multi_actl.png") as im:
|
||||
im.load()
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
|
||||
with Image.open("Tests/images/apng/chunk_actl_after_idat.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
|
||||
with Image.open("Tests/images/apng/chunk_no_fctl.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
with pytest.raises(SyntaxError):
|
||||
im.seek(im.n_frames - 1)
|
||||
|
||||
with Image.open("Tests/images/apng/chunk_repeat_fctl.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
with pytest.raises(SyntaxError):
|
||||
im.seek(im.n_frames - 1)
|
||||
|
||||
with Image.open("Tests/images/apng/chunk_no_fdat.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
with pytest.raises(SyntaxError):
|
||||
im.seek(im.n_frames - 1)
|
||||
|
||||
|
@ -297,26 +329,31 @@ def test_apng_chunk_errors() -> None:
|
|||
def test_apng_syntax_errors() -> None:
|
||||
with pytest.warns(UserWarning):
|
||||
with Image.open("Tests/images/apng/syntax_num_frames_zero.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
with pytest.raises(OSError):
|
||||
im.load()
|
||||
|
||||
with pytest.warns(UserWarning):
|
||||
with Image.open("Tests/images/apng/syntax_num_frames_zero_default.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
im.load()
|
||||
|
||||
# we can handle this case gracefully
|
||||
with Image.open("Tests/images/apng/syntax_num_frames_low.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
|
||||
with pytest.raises(OSError):
|
||||
with Image.open("Tests/images/apng/syntax_num_frames_high.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
im.load()
|
||||
|
||||
with pytest.warns(UserWarning):
|
||||
with Image.open("Tests/images/apng/syntax_num_frames_invalid.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert not im.is_animated
|
||||
im.load()
|
||||
|
||||
|
@ -336,6 +373,7 @@ def test_apng_syntax_errors() -> None:
|
|||
def test_apng_sequence_errors(test_file: str) -> None:
|
||||
with pytest.raises(SyntaxError):
|
||||
with Image.open(f"Tests/images/apng/{test_file}") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
im.load()
|
||||
|
||||
|
@ -346,6 +384,7 @@ def test_apng_save(tmp_path: Path) -> None:
|
|||
im.save(test_file, save_all=True)
|
||||
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.load()
|
||||
assert not im.is_animated
|
||||
assert im.n_frames == 1
|
||||
|
@ -361,6 +400,7 @@ def test_apng_save(tmp_path: Path) -> None:
|
|||
)
|
||||
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.load()
|
||||
assert im.is_animated
|
||||
assert im.n_frames == 2
|
||||
|
@ -400,6 +440,7 @@ def test_apng_save_split_fdat(tmp_path: Path) -> None:
|
|||
append_images=frames,
|
||||
)
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
im.seek(im.n_frames - 1)
|
||||
im.load()
|
||||
|
||||
|
@ -442,6 +483,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
|
|||
test_file, save_all=True, append_images=[frame, frame], duration=[500, 100, 150]
|
||||
)
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert "duration" not in im.info
|
||||
|
||||
|
@ -453,6 +495,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
|
|||
duration=[500, 100, 150],
|
||||
)
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.n_frames == 2
|
||||
assert im.info["duration"] == 600
|
||||
|
||||
|
@ -463,6 +506,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
|
|||
frame.info["duration"] = 300
|
||||
frame.save(test_file, save_all=True, append_images=[frame, different_frame])
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.n_frames == 2
|
||||
assert im.info["duration"] == 600
|
||||
|
||||
|
|
|
@ -69,12 +69,14 @@ def test_tell() -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, DcxImagePlugin.DcxImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
|
||||
def test_eoferror() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, DcxImagePlugin.DcxImageFile)
|
||||
n_frames = im.n_frames
|
||||
|
||||
# Test seeking past the last frame
|
||||
|
|
|
@ -86,6 +86,8 @@ simple_eps_file_with_long_binary_data = (
|
|||
def test_sanity(filename: str, size: tuple[int, int], scale: int) -> None:
|
||||
expected_size = tuple(s * scale for s in size)
|
||||
with Image.open(filename) as image:
|
||||
assert isinstance(image, EpsImagePlugin.EpsImageFile)
|
||||
|
||||
image.load(scale=scale)
|
||||
assert image.mode == "RGB"
|
||||
assert image.size == expected_size
|
||||
|
@ -223,6 +225,8 @@ def test_showpage() -> None:
|
|||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
def test_transparency() -> None:
|
||||
with Image.open("Tests/images/eps/reqd_showpage.eps") as plot_image:
|
||||
assert isinstance(plot_image, EpsImagePlugin.EpsImageFile)
|
||||
|
||||
plot_image.load(transparency=True)
|
||||
assert plot_image.mode == "RGBA"
|
||||
|
||||
|
@ -304,6 +308,7 @@ def test_render_scale2() -> None:
|
|||
|
||||
# Zero bounding box
|
||||
with Image.open(FILE1) as image1_scale2:
|
||||
assert isinstance(image1_scale2, EpsImagePlugin.EpsImageFile)
|
||||
image1_scale2.load(scale=2)
|
||||
with Image.open(FILE1_COMPARE_SCALE2) as image1_scale2_compare:
|
||||
image1_scale2_compare = image1_scale2_compare.convert("RGB")
|
||||
|
@ -312,6 +317,7 @@ def test_render_scale2() -> None:
|
|||
|
||||
# Non-zero bounding box
|
||||
with Image.open(FILE2) as image2_scale2:
|
||||
assert isinstance(image2_scale2, EpsImagePlugin.EpsImageFile)
|
||||
image2_scale2.load(scale=2)
|
||||
with Image.open(FILE2_COMPARE_SCALE2) as image2_scale2_compare:
|
||||
image2_scale2_compare = image2_scale2_compare.convert("RGB")
|
||||
|
|
|
@ -21,6 +21,8 @@ animated_test_file_with_prefix_chunk = "Tests/images/2422.flc"
|
|||
|
||||
def test_sanity() -> None:
|
||||
with Image.open(static_test_file) as im:
|
||||
assert isinstance(im, FliImagePlugin.FliImageFile)
|
||||
|
||||
im.load()
|
||||
assert im.mode == "P"
|
||||
assert im.size == (128, 128)
|
||||
|
@ -28,6 +30,8 @@ def test_sanity() -> None:
|
|||
assert not im.is_animated
|
||||
|
||||
with Image.open(animated_test_file) as im:
|
||||
assert isinstance(im, FliImagePlugin.FliImageFile)
|
||||
|
||||
assert im.mode == "P"
|
||||
assert im.size == (320, 200)
|
||||
assert im.format == "FLI"
|
||||
|
@ -114,16 +118,19 @@ def test_palette_chunk_second() -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open(static_test_file) as im:
|
||||
assert isinstance(im, FliImagePlugin.FliImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
with Image.open(animated_test_file) as im:
|
||||
assert isinstance(im, FliImagePlugin.FliImageFile)
|
||||
assert im.n_frames == 384
|
||||
assert im.is_animated
|
||||
|
||||
|
||||
def test_eoferror() -> None:
|
||||
with Image.open(animated_test_file) as im:
|
||||
assert isinstance(im, FliImagePlugin.FliImageFile)
|
||||
n_frames = im.n_frames
|
||||
|
||||
# Test seeking past the last frame
|
||||
|
|
|
@ -22,10 +22,11 @@ def test_sanity() -> None:
|
|||
|
||||
def test_close() -> None:
|
||||
with Image.open("Tests/images/input_bw_one_band.fpx") as im:
|
||||
pass
|
||||
assert isinstance(im, FpxImagePlugin.FpxImageFile)
|
||||
assert im.ole.fp.closed
|
||||
|
||||
im = Image.open("Tests/images/input_bw_one_band.fpx")
|
||||
assert isinstance(im, FpxImagePlugin.FpxImageFile)
|
||||
im.close()
|
||||
assert im.ole.fp.closed
|
||||
|
||||
|
|
|
@ -443,10 +443,12 @@ def test_seek_rewind() -> None:
|
|||
def test_n_frames(path: str, n_frames: int) -> None:
|
||||
# Test is_animated before n_frames
|
||||
with Image.open(path) as im:
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert im.is_animated == (n_frames != 1)
|
||||
|
||||
# Test is_animated after n_frames
|
||||
with Image.open(path) as im:
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert im.n_frames == n_frames
|
||||
assert im.is_animated == (n_frames != 1)
|
||||
|
||||
|
@ -456,6 +458,7 @@ def test_no_change() -> None:
|
|||
with Image.open("Tests/images/dispose_bgnd.gif") as im:
|
||||
im.seek(1)
|
||||
expected = im.copy()
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert im.n_frames == 5
|
||||
assert_image_equal(im, expected)
|
||||
|
||||
|
@ -463,17 +466,20 @@ def test_no_change() -> None:
|
|||
with Image.open("Tests/images/dispose_bgnd.gif") as im:
|
||||
im.seek(3)
|
||||
expected = im.copy()
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert im.is_animated
|
||||
assert_image_equal(im, expected)
|
||||
|
||||
with Image.open("Tests/images/comment_after_only_frame.gif") as im:
|
||||
expected = Image.new("P", (1, 1))
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert not im.is_animated
|
||||
assert_image_equal(im, expected)
|
||||
|
||||
|
||||
def test_eoferror() -> None:
|
||||
with Image.open(TEST_GIF) as im:
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
n_frames = im.n_frames
|
||||
|
||||
# Test seeking past the last frame
|
||||
|
@ -493,6 +499,7 @@ def test_first_frame_transparency() -> None:
|
|||
|
||||
def test_dispose_none() -> None:
|
||||
with Image.open("Tests/images/dispose_none.gif") as img:
|
||||
assert isinstance(img, GifImagePlugin.GifImageFile)
|
||||
try:
|
||||
while True:
|
||||
img.seek(img.tell() + 1)
|
||||
|
@ -516,6 +523,7 @@ def test_dispose_none_load_end() -> None:
|
|||
|
||||
def test_dispose_background() -> None:
|
||||
with Image.open("Tests/images/dispose_bgnd.gif") as img:
|
||||
assert isinstance(img, GifImagePlugin.GifImageFile)
|
||||
try:
|
||||
while True:
|
||||
img.seek(img.tell() + 1)
|
||||
|
@ -570,6 +578,7 @@ def test_transparent_dispose(
|
|||
|
||||
def test_dispose_previous() -> None:
|
||||
with Image.open("Tests/images/dispose_prev.gif") as img:
|
||||
assert isinstance(img, GifImagePlugin.GifImageFile)
|
||||
try:
|
||||
while True:
|
||||
img.seek(img.tell() + 1)
|
||||
|
@ -607,6 +616,7 @@ def test_save_dispose(tmp_path: Path) -> None:
|
|||
for method in range(0, 4):
|
||||
im_list[0].save(out, save_all=True, append_images=im_list[1:], disposal=method)
|
||||
with Image.open(out) as img:
|
||||
assert isinstance(img, GifImagePlugin.GifImageFile)
|
||||
for _ in range(2):
|
||||
img.seek(img.tell() + 1)
|
||||
assert img.disposal_method == method
|
||||
|
@ -620,6 +630,7 @@ def test_save_dispose(tmp_path: Path) -> None:
|
|||
)
|
||||
|
||||
with Image.open(out) as img:
|
||||
assert isinstance(img, GifImagePlugin.GifImageFile)
|
||||
for i in range(2):
|
||||
img.seek(img.tell() + 1)
|
||||
assert img.disposal_method == i + 1
|
||||
|
@ -742,6 +753,7 @@ def test_dispose2_background_frame(tmp_path: Path) -> None:
|
|||
im_list[0].save(out, save_all=True, append_images=im_list[1:], disposal=2)
|
||||
|
||||
with Image.open(out) as im:
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert im.n_frames == 3
|
||||
|
||||
|
||||
|
@ -908,6 +920,8 @@ def test_identical_frames(tmp_path: Path) -> None:
|
|||
out, save_all=True, append_images=im_list[1:], duration=duration_list
|
||||
)
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
|
||||
# Assert that the first three frames were combined
|
||||
assert reread.n_frames == 2
|
||||
|
||||
|
@ -937,6 +951,8 @@ def test_identical_frames_to_single_frame(
|
|||
|
||||
im_list[0].save(out, save_all=True, append_images=im_list[1:], duration=duration)
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
|
||||
# Assert that all frames were combined
|
||||
assert reread.n_frames == 1
|
||||
|
||||
|
@ -1123,6 +1139,7 @@ def test_append_images(tmp_path: Path) -> None:
|
|||
im.copy().save(out, save_all=True, append_images=ims)
|
||||
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
assert reread.n_frames == 3
|
||||
|
||||
# Tests appending using a generator
|
||||
|
@ -1132,6 +1149,7 @@ def test_append_images(tmp_path: Path) -> None:
|
|||
im.save(out, save_all=True, append_images=im_generator(ims))
|
||||
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
assert reread.n_frames == 3
|
||||
|
||||
# Tests appending single and multiple frame images
|
||||
|
@ -1140,6 +1158,7 @@ def test_append_images(tmp_path: Path) -> None:
|
|||
im.save(out, save_all=True, append_images=[im2])
|
||||
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
assert reread.n_frames == 10
|
||||
|
||||
|
||||
|
@ -1240,6 +1259,7 @@ def test_bbox(tmp_path: Path) -> None:
|
|||
im.save(out, save_all=True, append_images=ims)
|
||||
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
assert reread.n_frames == 2
|
||||
|
||||
|
||||
|
@ -1252,6 +1272,7 @@ def test_bbox_alpha(tmp_path: Path) -> None:
|
|||
im.save(out, save_all=True, append_images=[im2])
|
||||
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, GifImagePlugin.GifImageFile)
|
||||
assert reread.n_frames == 2
|
||||
|
||||
|
||||
|
@ -1403,6 +1424,7 @@ def test_extents(
|
|||
GifImagePlugin.LOADING_STRATEGY = loading_strategy
|
||||
try:
|
||||
with Image.open("Tests/images/" + test_file) as im:
|
||||
assert isinstance(im, GifImagePlugin.GifImageFile)
|
||||
assert im.size == (100, 100)
|
||||
|
||||
# Check that n_frames does not change the size
|
||||
|
@ -1452,4 +1474,5 @@ def test_p_rgba(tmp_path: Path, params: dict[str, Any]) -> None:
|
|||
im1.save(out, save_all=True, append_images=[im2], **params)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, GifImagePlugin.GifImageFile)
|
||||
assert reloaded.n_frames == 2
|
||||
|
|
|
@ -65,6 +65,7 @@ def test_save_append_images(tmp_path: Path) -> None:
|
|||
assert_image_similar_tofile(im, temp_file, 1)
|
||||
|
||||
with Image.open(temp_file) as reread:
|
||||
assert isinstance(reread, IcnsImagePlugin.IcnsImageFile)
|
||||
reread.size = (16, 16)
|
||||
reread.load(2)
|
||||
assert_image_equal(reread, provided_im)
|
||||
|
@ -86,6 +87,7 @@ def test_sizes() -> None:
|
|||
# Check that we can load all of the sizes, and that the final pixel
|
||||
# dimensions are as expected
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, IcnsImagePlugin.IcnsImageFile)
|
||||
for w, h, r in im.info["sizes"]:
|
||||
wr = w * r
|
||||
hr = h * r
|
||||
|
@ -114,6 +116,7 @@ def test_older_icon() -> None:
|
|||
wr = w * r
|
||||
hr = h * r
|
||||
with Image.open("Tests/images/pillow2.icns") as im2:
|
||||
assert isinstance(im2, IcnsImagePlugin.IcnsImageFile)
|
||||
im2.size = (w, h)
|
||||
im2.load(r)
|
||||
assert im2.mode == "RGBA"
|
||||
|
@ -131,6 +134,7 @@ def test_jp2_icon() -> None:
|
|||
wr = w * r
|
||||
hr = h * r
|
||||
with Image.open("Tests/images/pillow3.icns") as im2:
|
||||
assert isinstance(im2, IcnsImagePlugin.IcnsImageFile)
|
||||
im2.size = (w, h)
|
||||
im2.load(r)
|
||||
assert im2.mode == "RGBA"
|
||||
|
|
|
@ -75,6 +75,7 @@ def test_save_to_bytes() -> None:
|
|||
# The other one
|
||||
output.seek(0)
|
||||
with Image.open(output) as reloaded:
|
||||
assert isinstance(reloaded, IcoImagePlugin.IcoImageFile)
|
||||
reloaded.size = (32, 32)
|
||||
|
||||
assert im.mode == reloaded.mode
|
||||
|
@ -92,6 +93,7 @@ def test_getpixel(tmp_path: Path) -> None:
|
|||
im.save(temp_file, "ico", sizes=[(32, 32), (64, 64)])
|
||||
|
||||
with Image.open(temp_file) as reloaded:
|
||||
assert isinstance(reloaded, IcoImagePlugin.IcoImageFile)
|
||||
reloaded.load()
|
||||
reloaded.size = (32, 32)
|
||||
|
||||
|
@ -165,6 +167,7 @@ def test_save_to_bytes_bmp(mode: str) -> None:
|
|||
# The other one
|
||||
output.seek(0)
|
||||
with Image.open(output) as reloaded:
|
||||
assert isinstance(reloaded, IcoImagePlugin.IcoImageFile)
|
||||
reloaded.size = (32, 32)
|
||||
|
||||
assert "RGBA" == reloaded.mode
|
||||
|
@ -176,6 +179,7 @@ def test_save_to_bytes_bmp(mode: str) -> None:
|
|||
|
||||
def test_incorrect_size() -> None:
|
||||
with Image.open(TEST_ICO_FILE) as im:
|
||||
assert isinstance(im, IcoImagePlugin.IcoImageFile)
|
||||
with pytest.raises(ValueError):
|
||||
im.size = (1, 1)
|
||||
|
||||
|
@ -217,6 +221,7 @@ def test_save_append_images(tmp_path: Path) -> None:
|
|||
im.save(outfile, sizes=[(32, 32), (128, 128)], append_images=[provided_im])
|
||||
|
||||
with Image.open(outfile) as reread:
|
||||
assert isinstance(reread, IcoImagePlugin.IcoImageFile)
|
||||
assert_image_equal(reread, hopper("RGBA"))
|
||||
|
||||
reread.size = (32, 32)
|
||||
|
|
|
@ -68,12 +68,14 @@ def test_tell() -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open(TEST_IM) as im:
|
||||
assert isinstance(im, ImImagePlugin.ImImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
|
||||
def test_eoferror() -> None:
|
||||
with Image.open(TEST_IM) as im:
|
||||
assert isinstance(im, ImImagePlugin.ImImageFile)
|
||||
n_frames = im.n_frames
|
||||
|
||||
# Test seeking past the last frame
|
||||
|
|
|
@ -91,6 +91,7 @@ class TestFileJpeg:
|
|||
def test_app(self) -> None:
|
||||
# Test APP/COM reader (@PIL135)
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
assert im.applist[0] == ("APP0", b"JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00")
|
||||
assert im.applist[1] == (
|
||||
"COM",
|
||||
|
@ -316,6 +317,8 @@ class TestFileJpeg:
|
|||
|
||||
def test_exif_typeerror(self) -> None:
|
||||
with Image.open("Tests/images/exif_typeerror.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
|
||||
# Should not raise a TypeError
|
||||
im._getexif()
|
||||
|
||||
|
@ -500,6 +503,7 @@ class TestFileJpeg:
|
|||
|
||||
def test_mp(self) -> None:
|
||||
with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
assert im._getmp() is None
|
||||
|
||||
def test_quality_keep(self, tmp_path: Path) -> None:
|
||||
|
@ -557,12 +561,14 @@ class TestFileJpeg:
|
|||
with Image.open(test_file) as im:
|
||||
im.save(b, "JPEG", qtables=[[n] * 64] * n)
|
||||
with Image.open(b) as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
assert len(im.quantization) == n
|
||||
reloaded = self.roundtrip(im, qtables="keep")
|
||||
assert im.quantization == reloaded.quantization
|
||||
assert max(reloaded.quantization[0]) <= 255
|
||||
|
||||
with Image.open("Tests/images/hopper.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
qtables = im.quantization
|
||||
reloaded = self.roundtrip(im, qtables=qtables, subsampling=0)
|
||||
assert im.quantization == reloaded.quantization
|
||||
|
@ -662,6 +668,7 @@ class TestFileJpeg:
|
|||
|
||||
def test_load_16bit_qtables(self) -> None:
|
||||
with Image.open("Tests/images/hopper_16bit_qtables.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
assert len(im.quantization) == 2
|
||||
assert len(im.quantization[0]) == 64
|
||||
assert max(im.quantization[0]) > 255
|
||||
|
@ -704,6 +711,7 @@ class TestFileJpeg:
|
|||
@pytest.mark.skipif(not djpeg_available(), reason="djpeg not available")
|
||||
def test_load_djpeg(self) -> None:
|
||||
with Image.open(TEST_FILE) as img:
|
||||
assert isinstance(img, JpegImagePlugin.JpegImageFile)
|
||||
img.load_djpeg()
|
||||
assert_image_similar_tofile(img, TEST_FILE, 5)
|
||||
|
||||
|
@ -908,6 +916,7 @@ class TestFileJpeg:
|
|||
|
||||
def test_photoshop_malformed_and_multiple(self) -> None:
|
||||
with Image.open("Tests/images/app13-multiple.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
assert "photoshop" in im.info
|
||||
assert 24 == len(im.info["photoshop"])
|
||||
apps_13_lengths = [len(v) for k, v in im.applist if k == "APP13"]
|
||||
|
@ -1084,6 +1093,7 @@ class TestFileJpeg:
|
|||
|
||||
def test_deprecation(self) -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert im.huffman_ac == {}
|
||||
with pytest.warns(DeprecationWarning):
|
||||
|
|
|
@ -230,12 +230,14 @@ def test_layers(card: ImageFile.ImageFile) -> None:
|
|||
out.seek(0)
|
||||
|
||||
with Image.open(out) as im:
|
||||
assert isinstance(im, Jpeg2KImagePlugin.Jpeg2KImageFile)
|
||||
im.layers = 1
|
||||
im.load()
|
||||
assert_image_similar(im, card, 13)
|
||||
|
||||
out.seek(0)
|
||||
with Image.open(out) as im:
|
||||
assert isinstance(im, Jpeg2KImagePlugin.Jpeg2KImageFile)
|
||||
im.layers = 3
|
||||
im.load()
|
||||
assert_image_similar(im, card, 0.4)
|
||||
|
|
|
@ -36,6 +36,7 @@ class LibTiffTestCase:
|
|||
im.load()
|
||||
im.getdata()
|
||||
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im._compression == "group4"
|
||||
|
||||
# can we write it back out, in a different form.
|
||||
|
@ -153,6 +154,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
"""Test metadata writing through libtiff"""
|
||||
f = str(tmp_path / "temp.tiff")
|
||||
with Image.open("Tests/images/hopper_g4.tif") as img:
|
||||
assert isinstance(img, TiffImagePlugin.TiffImageFile)
|
||||
img.save(f, tiffinfo=img.tag)
|
||||
|
||||
if legacy_api:
|
||||
|
@ -170,6 +172,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
]
|
||||
|
||||
with Image.open(f) as loaded:
|
||||
assert isinstance(loaded, TiffImagePlugin.TiffImageFile)
|
||||
if legacy_api:
|
||||
reloaded = loaded.tag.named()
|
||||
else:
|
||||
|
@ -212,6 +215,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
# Exclude ones that have special meaning
|
||||
# that we're already testing them
|
||||
with Image.open("Tests/images/hopper_g4.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
for tag in im.tag_v2:
|
||||
try:
|
||||
del core_items[tag]
|
||||
|
@ -317,6 +321,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
im.save(out, tiffinfo=tiffinfo)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
for tag, value in tiffinfo.items():
|
||||
reloaded_value = reloaded.tag_v2[tag]
|
||||
if (
|
||||
|
@ -349,12 +354,14 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
def test_osubfiletype(self, tmp_path: Path) -> None:
|
||||
outfile = str(tmp_path / "temp.tif")
|
||||
with Image.open("Tests/images/g4_orientation_6.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
im.tag_v2[OSUBFILETYPE] = 1
|
||||
im.save(outfile)
|
||||
|
||||
def test_subifd(self, tmp_path: Path) -> None:
|
||||
outfile = str(tmp_path / "temp.tif")
|
||||
with Image.open("Tests/images/g4_orientation_6.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
im.tag_v2[SUBIFD] = 10000
|
||||
|
||||
# Should not segfault
|
||||
|
@ -369,6 +376,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
hopper().save(out, tiffinfo={700: b"xmlpacket tag"})
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
if 700 in reloaded.tag_v2:
|
||||
assert reloaded.tag_v2[700] == b"xmlpacket tag"
|
||||
|
||||
|
@ -430,12 +438,15 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
"""Tests String data in info directory"""
|
||||
test_file = "Tests/images/hopper_g4_500.tif"
|
||||
with Image.open(test_file) as orig:
|
||||
assert isinstance(orig, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
out = str(tmp_path / "temp.tif")
|
||||
|
||||
orig.tag[269] = "temp.tif"
|
||||
orig.save(out)
|
||||
|
||||
with Image.open(out) as reread:
|
||||
assert isinstance(reread, TiffImagePlugin.TiffImageFile)
|
||||
assert "temp.tif" == reread.tag_v2[269]
|
||||
assert "temp.tif" == reread.tag[269][0]
|
||||
|
||||
|
@ -541,6 +552,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
|
||||
with Image.open(out) as reloaded:
|
||||
# colormap/palette tag
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert len(reloaded.tag_v2[320]) == 768
|
||||
|
||||
@pytest.mark.parametrize("compression", ("tiff_ccitt", "group3", "group4"))
|
||||
|
@ -572,6 +584,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
with Image.open("Tests/images/multipage.tiff") as im:
|
||||
# file is a multipage tiff, 10x10 green, 10x10 red, 20x20 blue
|
||||
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
im.seek(0)
|
||||
assert im.size == (10, 10)
|
||||
assert im.convert("RGB").getpixel((0, 0)) == (0, 128, 0)
|
||||
|
@ -591,6 +604,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
# issue #862
|
||||
monkeypatch.setattr(TiffImagePlugin, "READ_LIBTIFF", True)
|
||||
with Image.open("Tests/images/multipage.tiff") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
frames = im.n_frames
|
||||
assert frames == 3
|
||||
for _ in range(frames):
|
||||
|
@ -610,6 +624,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
def test__next(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(TiffImagePlugin, "READ_LIBTIFF", True)
|
||||
with Image.open("Tests/images/hopper.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert not im.tag.next
|
||||
im.load()
|
||||
assert not im.tag.next
|
||||
|
@ -690,21 +705,25 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
im.save(outfile, compression="jpeg")
|
||||
|
||||
with Image.open(outfile) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[530] == (1, 1)
|
||||
assert reloaded.tag_v2[532] == (0, 255, 128, 255, 128, 255)
|
||||
|
||||
def test_exif_ifd(self) -> None:
|
||||
out = io.BytesIO()
|
||||
with Image.open("Tests/images/tiff_adobe_deflate.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.tag_v2[34665] == 125456
|
||||
im.save(out, "TIFF")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert 34665 not in reloaded.tag_v2
|
||||
|
||||
im.save(out, "TIFF", tiffinfo={34665: 125456})
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
if Image.core.libtiff_support_custom_tags:
|
||||
assert reloaded.tag_v2[34665] == 125456
|
||||
|
||||
|
@ -786,6 +805,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
|
||||
def test_multipage_compression(self) -> None:
|
||||
with Image.open("Tests/images/compression.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
im.seek(0)
|
||||
assert im._compression == "tiff_ccitt"
|
||||
assert im.size == (10, 10)
|
||||
|
@ -1079,6 +1099,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
with Image.open("Tests/images/g4_orientation_1.tif") as base_im:
|
||||
for i in range(2, 9):
|
||||
with Image.open("Tests/images/g4_orientation_" + str(i) + ".tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert 274 in im.tag_v2
|
||||
|
||||
im.load()
|
||||
|
|
|
@ -30,11 +30,13 @@ def test_sanity() -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, MicImagePlugin.MicImageFile)
|
||||
assert im.n_frames == 1
|
||||
|
||||
|
||||
def test_is_animated() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, MicImagePlugin.MicImageFile)
|
||||
assert not im.is_animated
|
||||
|
||||
|
||||
|
@ -55,10 +57,11 @@ def test_seek() -> None:
|
|||
|
||||
def test_close() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
pass
|
||||
assert isinstance(im, MicImagePlugin.MicImageFile)
|
||||
assert im.ole.fp.closed
|
||||
|
||||
im = Image.open(TEST_FILE)
|
||||
assert isinstance(im, MicImagePlugin.MicImageFile)
|
||||
im.close()
|
||||
assert im.ole.fp.closed
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import Image, ImageFile, MpoImagePlugin
|
||||
from PIL import Image, ImageFile, JpegImagePlugin, MpoImagePlugin
|
||||
|
||||
from .helper import (
|
||||
assert_image_equal,
|
||||
|
@ -75,6 +75,7 @@ def test_context_manager() -> None:
|
|||
def test_app(test_file: str) -> None:
|
||||
# Test APP/COM reader (@PIL135)
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, MpoImagePlugin.MpoImageFile)
|
||||
assert im.applist[0][0] == "APP1"
|
||||
assert im.applist[1][0] == "APP2"
|
||||
assert (
|
||||
|
@ -215,12 +216,14 @@ def test_seek(test_file: str) -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open("Tests/images/sugarshack.mpo") as im:
|
||||
assert isinstance(im, MpoImagePlugin.MpoImageFile)
|
||||
assert im.n_frames == 2
|
||||
assert im.is_animated
|
||||
|
||||
|
||||
def test_eoferror() -> None:
|
||||
with Image.open("Tests/images/sugarshack.mpo") as im:
|
||||
assert isinstance(im, MpoImagePlugin.MpoImageFile)
|
||||
n_frames = im.n_frames
|
||||
|
||||
# Test seeking past the last frame
|
||||
|
@ -234,6 +237,8 @@ def test_eoferror() -> None:
|
|||
|
||||
def test_adopt_jpeg() -> None:
|
||||
with Image.open("Tests/images/hopper.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
MpoImagePlugin.MpoImageFile.adopt(im)
|
||||
|
||||
|
|
|
@ -580,6 +580,7 @@ class TestFilePng:
|
|||
|
||||
def test_read_private_chunks(self) -> None:
|
||||
with Image.open("Tests/images/exif.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.private_chunks == [(b"orNT", b"\x01")]
|
||||
|
||||
def test_roundtrip_private_chunk(self) -> None:
|
||||
|
@ -602,6 +603,7 @@ class TestFilePng:
|
|||
|
||||
def test_textual_chunks_after_idat(self) -> None:
|
||||
with Image.open("Tests/images/hopper.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert "comment" in im.text
|
||||
for k, v in {
|
||||
"date:create": "2014-09-04T09:37:08+03:00",
|
||||
|
@ -611,11 +613,14 @@ class TestFilePng:
|
|||
|
||||
# Raises a SyntaxError in load_end
|
||||
with Image.open("Tests/images/broken_data_stream.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
with pytest.raises(OSError):
|
||||
assert isinstance(im.text, dict)
|
||||
|
||||
# Raises a UnicodeDecodeError in load_end
|
||||
with Image.open("Tests/images/truncated_image.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
|
||||
# The file is truncated
|
||||
with pytest.raises(OSError):
|
||||
im.text
|
||||
|
@ -625,6 +630,7 @@ class TestFilePng:
|
|||
|
||||
# Raises an EOFError in load_end
|
||||
with Image.open("Tests/images/hopper_idat_after_image_end.png") as im:
|
||||
assert isinstance(im, PngImagePlugin.PngImageFile)
|
||||
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}
|
||||
|
||||
def test_unknown_compression_method(self) -> None:
|
||||
|
@ -730,6 +736,7 @@ class TestFilePng:
|
|||
im.save(test_file)
|
||||
|
||||
with Image.open(test_file) as reloaded:
|
||||
assert isinstance(reloaded, PngImagePlugin.PngImageFile)
|
||||
assert reloaded._getexif() is None
|
||||
|
||||
# Test passing in exif
|
||||
|
|
|
@ -59,17 +59,21 @@ def test_invalid_file() -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open("Tests/images/hopper_merged.psd") as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
for path in [test_file, "Tests/images/negative_layer_count.psd"]:
|
||||
with Image.open(path) as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
assert im.n_frames == 2
|
||||
assert im.is_animated
|
||||
|
||||
|
||||
def test_eoferror() -> None:
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
|
||||
# PSD seek index starts at 1 rather than 0
|
||||
n_frames = im.n_frames + 1
|
||||
|
||||
|
@ -119,11 +123,13 @@ def test_rgba() -> None:
|
|||
|
||||
def test_negative_top_left_layer() -> None:
|
||||
with Image.open("Tests/images/negative_top_left_layer.psd") as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
assert im.layers[0][2] == (-50, -50, 50, 50)
|
||||
|
||||
|
||||
def test_layer_skip() -> None:
|
||||
with Image.open("Tests/images/five_channels.psd") as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
assert im.n_frames == 1
|
||||
|
||||
|
||||
|
@ -175,5 +181,6 @@ def test_crashes(test_file: str, raises: type[Exception]) -> None:
|
|||
def test_layer_crashes(test_file: str) -> None:
|
||||
with open(test_file, "rb") as f:
|
||||
with Image.open(f) as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
with pytest.raises(SyntaxError):
|
||||
im.layers
|
||||
|
|
|
@ -96,6 +96,7 @@ def test_tell() -> None:
|
|||
|
||||
def test_n_frames() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, SpiderImagePlugin.SpiderImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
|
|
|
@ -9,7 +9,13 @@ from types import ModuleType
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import Image, ImageFile, TiffImagePlugin, UnidentifiedImageError
|
||||
from PIL import (
|
||||
Image,
|
||||
ImageFile,
|
||||
JpegImagePlugin,
|
||||
TiffImagePlugin,
|
||||
UnidentifiedImageError,
|
||||
)
|
||||
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
|
||||
|
||||
from .helper import (
|
||||
|
@ -113,6 +119,7 @@ class TestFileTiff:
|
|||
|
||||
with Image.open("Tests/images/hopper_bigtiff.tif") as im:
|
||||
outfile = str(tmp_path / "temp.tif")
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
im.save(outfile, save_all=True, append_images=[im], tiffinfo=im.tag_v2)
|
||||
|
||||
def test_bigtiff_save(self, tmp_path: Path) -> None:
|
||||
|
@ -121,11 +128,13 @@ class TestFileTiff:
|
|||
im.save(outfile, big_tiff=True)
|
||||
|
||||
with Image.open(outfile) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2._bigtiff is True
|
||||
|
||||
im.save(outfile, save_all=True, append_images=[im], big_tiff=True)
|
||||
|
||||
with Image.open(outfile) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2._bigtiff is True
|
||||
|
||||
def test_seek_too_large(self) -> None:
|
||||
|
@ -141,6 +150,8 @@ class TestFileTiff:
|
|||
def test_xyres_tiff(self) -> None:
|
||||
filename = "Tests/images/pil168.tif"
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
# legacy api
|
||||
assert isinstance(im.tag[X_RESOLUTION][0], tuple)
|
||||
assert isinstance(im.tag[Y_RESOLUTION][0], tuple)
|
||||
|
@ -154,6 +165,8 @@ class TestFileTiff:
|
|||
def test_xyres_fallback_tiff(self) -> None:
|
||||
filename = "Tests/images/compression.tif"
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
# v2 api
|
||||
assert isinstance(im.tag_v2[X_RESOLUTION], TiffImagePlugin.IFDRational)
|
||||
assert isinstance(im.tag_v2[Y_RESOLUTION], TiffImagePlugin.IFDRational)
|
||||
|
@ -168,6 +181,8 @@ class TestFileTiff:
|
|||
def test_int_resolution(self) -> None:
|
||||
filename = "Tests/images/pil168.tif"
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
# Try to read a file where X,Y_RESOLUTION are ints
|
||||
im.tag_v2[X_RESOLUTION] = 71
|
||||
im.tag_v2[Y_RESOLUTION] = 71
|
||||
|
@ -182,6 +197,7 @@ class TestFileTiff:
|
|||
with Image.open(
|
||||
"Tests/images/hopper_float_dpi_" + str(resolution_unit) + ".tif"
|
||||
) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.tag_v2.get(RESOLUTION_UNIT) == resolution_unit
|
||||
assert im.info["dpi"] == (dpi, dpi)
|
||||
|
||||
|
@ -199,6 +215,7 @@ class TestFileTiff:
|
|||
with Image.open("Tests/images/10ct_32bit_128.tiff") as im:
|
||||
im.save(b, format="tiff", resolution=123.45)
|
||||
with Image.open(b) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.tag_v2[X_RESOLUTION] == 123.45
|
||||
assert im.tag_v2[Y_RESOLUTION] == 123.45
|
||||
|
||||
|
@ -214,10 +231,12 @@ class TestFileTiff:
|
|||
TiffImagePlugin.PREFIXES.pop()
|
||||
|
||||
def test_bad_exif(self) -> None:
|
||||
with Image.open("Tests/images/hopper_bad_exif.jpg") as i:
|
||||
with Image.open("Tests/images/hopper_bad_exif.jpg") as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
|
||||
# Should not raise struct.error.
|
||||
with pytest.warns(UserWarning):
|
||||
i._getexif()
|
||||
im._getexif()
|
||||
|
||||
def test_save_rgba(self, tmp_path: Path) -> None:
|
||||
im = hopper("RGBA")
|
||||
|
@ -308,11 +327,13 @@ class TestFileTiff:
|
|||
)
|
||||
def test_n_frames(self, path: str, n_frames: int) -> None:
|
||||
with Image.open(path) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.n_frames == n_frames
|
||||
assert im.is_animated == (n_frames != 1)
|
||||
|
||||
def test_eoferror(self) -> None:
|
||||
with Image.open("Tests/images/multipage-lastframe.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
n_frames = im.n_frames
|
||||
|
||||
# Test seeking past the last frame
|
||||
|
@ -356,19 +377,24 @@ class TestFileTiff:
|
|||
def test_frame_order(self) -> None:
|
||||
# A frame can't progress to itself after reading
|
||||
with Image.open("Tests/images/multipage_single_frame_loop.tiff") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.n_frames == 1
|
||||
|
||||
# A frame can't progress to a frame that has already been read
|
||||
with Image.open("Tests/images/multipage_multiple_frame_loop.tiff") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.n_frames == 2
|
||||
|
||||
# Frames don't have to be in sequence
|
||||
with Image.open("Tests/images/multipage_out_of_order.tiff") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.n_frames == 3
|
||||
|
||||
def test___str__(self) -> None:
|
||||
filename = "Tests/images/pil136.tiff"
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
# Act
|
||||
ret = str(im.ifd)
|
||||
|
||||
|
@ -379,6 +405,8 @@ class TestFileTiff:
|
|||
# Arrange
|
||||
filename = "Tests/images/pil136.tiff"
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
# v2 interface
|
||||
v2_tags = {
|
||||
256: 55,
|
||||
|
@ -418,6 +446,7 @@ class TestFileTiff:
|
|||
def test__delitem__(self) -> None:
|
||||
filename = "Tests/images/pil136.tiff"
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
len_before = len(dict(im.ifd))
|
||||
del im.ifd[256]
|
||||
len_after = len(dict(im.ifd))
|
||||
|
@ -450,6 +479,7 @@ class TestFileTiff:
|
|||
|
||||
def test_ifd_tag_type(self) -> None:
|
||||
with Image.open("Tests/images/ifd_tag_type.tiff") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert 0x8825 in im.tag_v2
|
||||
|
||||
def test_exif(self, tmp_path: Path) -> None:
|
||||
|
@ -538,6 +568,7 @@ class TestFileTiff:
|
|||
im = hopper(mode)
|
||||
im.save(filename, tiffinfo={262: 0})
|
||||
with Image.open(filename) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[262] == 0
|
||||
assert_image_equal(im, reloaded)
|
||||
|
||||
|
@ -616,6 +647,8 @@ class TestFileTiff:
|
|||
filename = str(tmp_path / "temp.tif")
|
||||
hopper("RGB").save(filename, "TIFF", **kwargs)
|
||||
with Image.open(filename) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
|
||||
# legacy interface
|
||||
assert im.tag[X_RESOLUTION][0][0] == 72
|
||||
assert im.tag[Y_RESOLUTION][0][0] == 36
|
||||
|
@ -690,6 +723,7 @@ class TestFileTiff:
|
|||
def test_planar_configuration_save(self, tmp_path: Path) -> None:
|
||||
infile = "Tests/images/tiff_tiled_planar_raw.tif"
|
||||
with Image.open(infile) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im._planar_configuration == 2
|
||||
|
||||
outfile = str(tmp_path / "temp.tif")
|
||||
|
@ -722,6 +756,7 @@ class TestFileTiff:
|
|||
|
||||
mp.seek(0, os.SEEK_SET)
|
||||
with Image.open(mp) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.n_frames == 3
|
||||
|
||||
# Test appending images
|
||||
|
@ -732,6 +767,7 @@ class TestFileTiff:
|
|||
|
||||
mp.seek(0, os.SEEK_SET)
|
||||
with Image.open(mp) as reread:
|
||||
assert isinstance(reread, TiffImagePlugin.TiffImageFile)
|
||||
assert reread.n_frames == 3
|
||||
|
||||
# Test appending using a generator
|
||||
|
@ -743,6 +779,7 @@ class TestFileTiff:
|
|||
|
||||
mp.seek(0, os.SEEK_SET)
|
||||
with Image.open(mp) as reread:
|
||||
assert isinstance(reread, TiffImagePlugin.TiffImageFile)
|
||||
assert reread.n_frames == 3
|
||||
|
||||
def test_fixoffsets(self) -> None:
|
||||
|
@ -851,6 +888,7 @@ class TestFileTiff:
|
|||
|
||||
def test_get_photoshop_blocks(self) -> None:
|
||||
with Image.open("Tests/images/lab.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert list(im.get_photoshop_blocks().keys()) == [
|
||||
1061,
|
||||
1002,
|
||||
|
|
|
@ -61,6 +61,7 @@ def test_rt_metadata(tmp_path: Path) -> None:
|
|||
img.save(f, tiffinfo=info)
|
||||
|
||||
with Image.open(f) as loaded:
|
||||
assert isinstance(loaded, TiffImagePlugin.TiffImageFile)
|
||||
assert loaded.tag[ImageJMetaDataByteCounts] == (len(bin_data),)
|
||||
assert loaded.tag_v2[ImageJMetaDataByteCounts] == (len(bin_data),)
|
||||
|
||||
|
@ -80,12 +81,14 @@ def test_rt_metadata(tmp_path: Path) -> None:
|
|||
info[ImageJMetaDataByteCounts] = (8, len(bin_data) - 8)
|
||||
img.save(f, tiffinfo=info)
|
||||
with Image.open(f) as loaded:
|
||||
assert isinstance(loaded, TiffImagePlugin.TiffImageFile)
|
||||
assert loaded.tag[ImageJMetaDataByteCounts] == (8, len(bin_data) - 8)
|
||||
assert loaded.tag_v2[ImageJMetaDataByteCounts] == (8, len(bin_data) - 8)
|
||||
|
||||
|
||||
def test_read_metadata() -> None:
|
||||
with Image.open("Tests/images/hopper_g4.tif") as img:
|
||||
assert isinstance(img, TiffImagePlugin.TiffImageFile)
|
||||
assert {
|
||||
"YResolution": IFDRational(4294967295, 113653537),
|
||||
"PlanarConfiguration": 1,
|
||||
|
@ -128,6 +131,7 @@ def test_read_metadata() -> None:
|
|||
def test_write_metadata(tmp_path: Path) -> None:
|
||||
"""Test metadata writing through the python code"""
|
||||
with Image.open("Tests/images/hopper.tif") as img:
|
||||
assert isinstance(img, TiffImagePlugin.TiffImageFile)
|
||||
f = str(tmp_path / "temp.tiff")
|
||||
del img.tag[278]
|
||||
img.save(f, tiffinfo=img.tag)
|
||||
|
@ -135,6 +139,7 @@ def test_write_metadata(tmp_path: Path) -> None:
|
|||
original = img.tag_v2.named()
|
||||
|
||||
with Image.open(f) as loaded:
|
||||
assert isinstance(loaded, TiffImagePlugin.TiffImageFile)
|
||||
reloaded = loaded.tag_v2.named()
|
||||
|
||||
ignored = ["StripByteCounts", "RowsPerStrip", "PageNumber", "StripOffsets"]
|
||||
|
@ -165,6 +170,7 @@ def test_write_metadata(tmp_path: Path) -> None:
|
|||
def test_change_stripbytecounts_tag_type(tmp_path: Path) -> None:
|
||||
out = str(tmp_path / "temp.tiff")
|
||||
with Image.open("Tests/images/hopper.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
info = im.tag_v2
|
||||
del info[278]
|
||||
|
||||
|
@ -178,6 +184,7 @@ def test_change_stripbytecounts_tag_type(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2.tagtype[TiffImagePlugin.STRIPBYTECOUNTS] == TiffTags.LONG
|
||||
|
||||
|
||||
|
@ -231,6 +238,7 @@ def test_writing_other_types_to_ascii(
|
|||
im.save(out, tiffinfo=info)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[271] == expected
|
||||
|
||||
|
||||
|
@ -248,6 +256,7 @@ def test_writing_other_types_to_bytes(value: int | IFDRational, tmp_path: Path)
|
|||
im.save(out, tiffinfo=info)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[700] == b"\x01"
|
||||
|
||||
|
||||
|
@ -267,6 +276,7 @@ def test_writing_other_types_to_undefined(
|
|||
im.save(out, tiffinfo=info)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[33723] == b"1"
|
||||
|
||||
|
||||
|
@ -311,6 +321,7 @@ def test_iccprofile_binary() -> None:
|
|||
# but probably won't be able to save it.
|
||||
|
||||
with Image.open("Tests/images/hopper.iccprofile_binary.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.tag_v2.tagtype[34675] == 1
|
||||
assert im.info["icc_profile"]
|
||||
|
||||
|
@ -336,6 +347,7 @@ def test_exif_div_zero(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert 0 == reloaded.tag_v2[41988].numerator
|
||||
assert 0 == reloaded.tag_v2[41988].denominator
|
||||
|
||||
|
@ -355,6 +367,7 @@ def test_ifd_unsigned_rational(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert max_long == reloaded.tag_v2[41493].numerator
|
||||
assert 1 == reloaded.tag_v2[41493].denominator
|
||||
|
||||
|
@ -367,6 +380,7 @@ def test_ifd_unsigned_rational(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert max_long == reloaded.tag_v2[41493].numerator
|
||||
assert 1 == reloaded.tag_v2[41493].denominator
|
||||
|
||||
|
@ -385,6 +399,7 @@ def test_ifd_signed_rational(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert numerator == reloaded.tag_v2[37380].numerator
|
||||
assert denominator == reloaded.tag_v2[37380].denominator
|
||||
|
||||
|
@ -397,6 +412,7 @@ def test_ifd_signed_rational(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert numerator == reloaded.tag_v2[37380].numerator
|
||||
assert denominator == reloaded.tag_v2[37380].denominator
|
||||
|
||||
|
@ -410,6 +426,7 @@ def test_ifd_signed_rational(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert 2**31 - 1 == reloaded.tag_v2[37380].numerator
|
||||
assert -1 == reloaded.tag_v2[37380].denominator
|
||||
|
||||
|
@ -424,6 +441,7 @@ def test_ifd_signed_long(tmp_path: Path) -> None:
|
|||
im.save(out, tiffinfo=info, compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[37000] == -60000
|
||||
|
||||
|
||||
|
@ -444,11 +462,13 @@ def test_empty_values() -> None:
|
|||
|
||||
def test_photoshop_info(tmp_path: Path) -> None:
|
||||
with Image.open("Tests/images/issue_2278.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert len(im.tag_v2[34377]) == 70
|
||||
assert isinstance(im.tag_v2[34377], bytes)
|
||||
out = str(tmp_path / "temp.tiff")
|
||||
im.save(out)
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert len(reloaded.tag_v2[34377]) == 70
|
||||
assert isinstance(reloaded.tag_v2[34377], bytes)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
|||
import pytest
|
||||
from packaging.version import parse as parse_version
|
||||
|
||||
from PIL import Image, features
|
||||
from PIL import GifImagePlugin, Image, WebPImagePlugin, features
|
||||
|
||||
from .helper import (
|
||||
assert_image_equal,
|
||||
|
@ -22,10 +22,12 @@ def test_n_frames() -> None:
|
|||
"""Ensure that WebP format sets n_frames and is_animated attributes correctly."""
|
||||
|
||||
with Image.open("Tests/images/hopper.webp") as im:
|
||||
assert isinstance(im, WebPImagePlugin.WebPImageFile)
|
||||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
with Image.open("Tests/images/iss634.webp") as im:
|
||||
assert isinstance(im, WebPImagePlugin.WebPImageFile)
|
||||
assert im.n_frames == 42
|
||||
assert im.is_animated
|
||||
|
||||
|
@ -37,11 +39,13 @@ def test_write_animation_L(tmp_path: Path) -> None:
|
|||
"""
|
||||
|
||||
with Image.open("Tests/images/iss634.gif") as orig:
|
||||
assert isinstance(orig, GifImagePlugin.GifImageFile)
|
||||
assert orig.n_frames > 1
|
||||
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
orig.save(temp_file, save_all=True)
|
||||
with Image.open(temp_file) as im:
|
||||
assert isinstance(im, WebPImagePlugin.WebPImageFile)
|
||||
assert im.n_frames == orig.n_frames
|
||||
|
||||
# Compare first and last frames to the original animated GIF
|
||||
|
@ -69,6 +73,7 @@ def test_write_animation_RGB(tmp_path: Path) -> None:
|
|||
|
||||
def check(temp_file: str) -> None:
|
||||
with Image.open(temp_file) as im:
|
||||
assert isinstance(im, WebPImagePlugin.WebPImageFile)
|
||||
assert im.n_frames == 2
|
||||
|
||||
# Compare first frame to original
|
||||
|
@ -127,6 +132,7 @@ def test_timestamp_and_duration(tmp_path: Path) -> None:
|
|||
)
|
||||
|
||||
with Image.open(temp_file) as im:
|
||||
assert isinstance(im, WebPImagePlugin.WebPImageFile)
|
||||
assert im.n_frames == 5
|
||||
assert im.is_animated
|
||||
|
||||
|
@ -170,6 +176,7 @@ def test_seeking(tmp_path: Path) -> None:
|
|||
)
|
||||
|
||||
with Image.open(temp_file) as im:
|
||||
assert isinstance(im, WebPImagePlugin.WebPImageFile)
|
||||
assert im.n_frames == 5
|
||||
assert im.is_animated
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from types import ModuleType
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
from PIL import Image, WebPImagePlugin
|
||||
|
||||
from .helper import mark_if_feature_version, skip_unless_feature
|
||||
|
||||
|
@ -110,6 +110,7 @@ def test_read_no_exif() -> None:
|
|||
|
||||
test_buffer.seek(0)
|
||||
with Image.open(test_buffer) as webp_image:
|
||||
assert isinstance(webp_image, WebPImagePlugin.WebPImageFile)
|
||||
assert not webp_image._getexif()
|
||||
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ def test_load_float_dpi() -> None:
|
|||
|
||||
def test_load_set_dpi() -> None:
|
||||
with Image.open("Tests/images/drawing.wmf") as im:
|
||||
assert isinstance(im, WmfImagePlugin.WmfStubImageFile)
|
||||
assert im.size == (82, 82)
|
||||
|
||||
if hasattr(Image.core, "drawwmf"):
|
||||
|
|
|
@ -30,6 +30,7 @@ def test_invalid_file() -> None:
|
|||
def test_load_read() -> None:
|
||||
# Arrange
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert isinstance(im, XpmImagePlugin.XpmImageFile)
|
||||
dummy_bytes = 1
|
||||
|
||||
# Act
|
||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import Image, ImageSequence, TiffImagePlugin
|
||||
from PIL import Image, ImageSequence, PsdImagePlugin, TiffImagePlugin
|
||||
|
||||
from .helper import assert_image_equal, hopper, skip_unless_feature
|
||||
|
||||
|
@ -31,6 +31,7 @@ def test_sanity(tmp_path: Path) -> None:
|
|||
|
||||
def test_iterator() -> None:
|
||||
with Image.open("Tests/images/multipage.tiff") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
i = ImageSequence.Iterator(im)
|
||||
for index in range(0, im.n_frames):
|
||||
assert i[index] == next(i)
|
||||
|
@ -42,6 +43,7 @@ def test_iterator() -> None:
|
|||
|
||||
def test_iterator_min_frame() -> None:
|
||||
with Image.open("Tests/images/hopper.psd") as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
i = ImageSequence.Iterator(im)
|
||||
for index in range(1, im.n_frames):
|
||||
assert i[index] == next(i)
|
||||
|
|
|
@ -39,6 +39,7 @@ class TestShellInjection:
|
|||
shutil.copy(TEST_JPG, src_file)
|
||||
|
||||
with Image.open(src_file) as im:
|
||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||
im.load_djpeg()
|
||||
|
||||
@pytest.mark.skipif(not cjpeg_available(), reason="cjpeg not available")
|
||||
|
|
|
@ -72,4 +72,5 @@ def test_ifd_rational_save(
|
|||
im.save(out, dpi=(res, res), compression="raw")
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert float(IFDRational(301, 1)) == float(reloaded.tag_v2[282])
|
||||
|
|
Loading…
Reference in New Issue
Block a user