Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/check_j2k_overflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

def test_j2k_overflow(tmp_path: Path) -> None:
im = Image.new("RGBA", (1024, 131584))
target = str(tmp_path / "temp.jpc")
target = tmp_path / "temp.jpc"
with pytest.raises(OSError):
im.save(target)
2 changes: 1 addition & 1 deletion Tests/check_large_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


def _write_png(tmp_path: Path, xdim: int, ydim: int) -> None:
f = str(tmp_path / "temp.png")
f = tmp_path / "temp.png"
im = Image.new("L", (xdim, ydim), 0)
im.save(f)

Expand Down
2 changes: 1 addition & 1 deletion Tests/check_large_memory_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def _write_png(tmp_path: Path, xdim: int, ydim: int) -> None:
dtype = np.uint8
a = np.zeros((xdim, ydim), dtype=dtype)
f = str(tmp_path / "temp.png")
f = tmp_path / "temp.png"
im = Image.fromarray(a, "L")
im.save(f)

Expand Down
8 changes: 6 additions & 2 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from collections.abc import Sequence
from functools import lru_cache
from io import BytesIO
from pathlib import Path
from typing import Any, Callable

import pytest
Expand Down Expand Up @@ -95,7 +96,10 @@ def assert_image_equal(a: Image.Image, b: Image.Image, msg: str | None = None) -


def assert_image_equal_tofile(
a: Image.Image, filename: str, msg: str | None = None, mode: str | None = None
a: Image.Image,
filename: str | Path,
msg: str | None = None,
mode: str | None = None,
) -> None:
with Image.open(filename) as img:
if mode:
Expand Down Expand Up @@ -136,7 +140,7 @@ def assert_image_similar(

def assert_image_similar_tofile(
a: Image.Image,
filename: str,
filename: str | Path,
epsilon: float,
msg: str | None = None,
) -> None:
Expand Down
20 changes: 10 additions & 10 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def test_apng_sequence_errors(test_file: str) -> None:

def test_apng_save(tmp_path: Path) -> None:
with Image.open("Tests/images/apng/single_frame.png") as im:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"
im.save(test_file, save_all=True)

with Image.open(test_file) as im:
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_apng_save(tmp_path: Path) -> None:


def test_apng_save_alpha(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"

im = Image.new("RGBA", (1, 1), (255, 0, 0, 255))
im2 = Image.new("RGBA", (1, 1), (255, 0, 0, 127))
Expand All @@ -393,7 +393,7 @@ def test_apng_save_split_fdat(tmp_path: Path) -> None:
# frames with image data spanning multiple fdAT chunks (in this case
# both the default image and first animation frame will span multiple
# data chunks)
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"
with Image.open("Tests/images/old-style-jpeg-compression.png") as im:
frames = [im.copy(), Image.new("RGBA", im.size, (255, 0, 0, 255))]
im.save(
Expand All @@ -408,7 +408,7 @@ def test_apng_save_split_fdat(tmp_path: Path) -> None:


def test_apng_save_duration_loop(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"
with Image.open("Tests/images/apng/delay.png") as im:
frames = []
durations = []
Expand Down Expand Up @@ -471,7 +471,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:


def test_apng_save_disposal(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"
size = (128, 64)
red = Image.new("RGBA", size, (255, 0, 0, 255))
green = Image.new("RGBA", size, (0, 255, 0, 255))
Expand Down Expand Up @@ -572,7 +572,7 @@ def test_apng_save_disposal(tmp_path: Path) -> None:


def test_apng_save_disposal_previous(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"
size = (128, 64)
blue = Image.new("RGBA", size, (0, 0, 255, 255))
red = Image.new("RGBA", size, (255, 0, 0, 255))
Expand All @@ -594,7 +594,7 @@ def test_apng_save_disposal_previous(tmp_path: Path) -> None:


def test_apng_save_blend(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"
size = (128, 64)
red = Image.new("RGBA", size, (255, 0, 0, 255))
green = Image.new("RGBA", size, (0, 255, 0, 255))
Expand Down Expand Up @@ -662,7 +662,7 @@ def test_apng_save_blend(tmp_path: Path) -> None:


def test_apng_save_size(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"

im = Image.new("L", (100, 100))
im.save(test_file, save_all=True, append_images=[Image.new("L", (200, 200))])
Expand All @@ -686,7 +686,7 @@ def test_seek_after_close() -> None:
def test_different_modes_in_later_frames(
mode: str, default_image: bool, duplicate: bool, tmp_path: Path
) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"

im = Image.new("L", (1, 1))
im.save(
Expand All @@ -700,7 +700,7 @@ def test_different_modes_in_later_frames(


def test_different_durations(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
test_file = tmp_path / "temp.png"

with Image.open("Tests/images/apng/different_durations.png") as im:
for _ in range(3):
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_blp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_invalid_file() -> None:


def test_save(tmp_path: Path) -> None:
f = str(tmp_path / "temp.blp")
f = tmp_path / "temp.blp"

for version in ("BLP1", "BLP2"):
im = hopper("P")
Expand All @@ -56,7 +56,7 @@ def test_save(tmp_path: Path) -> None:
assert_image_equal(im.convert("RGB"), reloaded)

with Image.open("Tests/images/transparent.png") as im:
f = str(tmp_path / "temp.blp")
f = tmp_path / "temp.blp"
im.convert("P").save(f, blp_version=version)

with Image.open(f) as reloaded:
Expand Down
12 changes: 6 additions & 6 deletions Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def test_sanity(tmp_path: Path) -> None:
def roundtrip(im: Image.Image) -> None:
outfile = str(tmp_path / "temp.bmp")
outfile = tmp_path / "temp.bmp"

im.save(outfile, "BMP")

Expand Down Expand Up @@ -66,15 +66,15 @@ def test_small_palette(tmp_path: Path) -> None:
colors = [0, 0, 0, 125, 125, 125, 255, 255, 255]
im.putpalette(colors)

out = str(tmp_path / "temp.bmp")
out = tmp_path / "temp.bmp"
im.save(out)

with Image.open(out) as reloaded:
assert reloaded.getpalette() == colors


def test_save_too_large(tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.bmp")
outfile = tmp_path / "temp.bmp"
with Image.new("RGB", (1, 1)) as im:
im._size = (37838, 37838)
with pytest.raises(ValueError):
Expand All @@ -96,7 +96,7 @@ def test_dpi() -> None:
def test_save_bmp_with_dpi(tmp_path: Path) -> None:
# Test for #1301
# Arrange
outfile = str(tmp_path / "temp.jpg")
outfile = tmp_path / "temp.jpg"
with Image.open("Tests/images/hopper.bmp") as im:
assert im.info["dpi"] == (95.98654816726399, 95.98654816726399)

Expand All @@ -112,7 +112,7 @@ def test_save_bmp_with_dpi(tmp_path: Path) -> None:


def test_save_float_dpi(tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.bmp")
outfile = tmp_path / "temp.bmp"
with Image.open("Tests/images/hopper.bmp") as im:
im.save(outfile, dpi=(72.21216100543306, 72.21216100543306))
with Image.open(outfile) as reloaded:
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_dib_header_size(header_size: int, path: str) -> None:


def test_save_dib(tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.dib")
outfile = tmp_path / "temp.dib"

with Image.open("Tests/images/clipboard.dib") as im:
im.save(outfile)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_bufrstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_load() -> None:
def test_save(tmp_path: Path) -> None:
# Arrange
im = hopper()
tmpfile = str(tmp_path / "temp.bufr")
tmpfile = tmp_path / "temp.bufr"

# Act / Assert: stub cannot save without an implemented handler
with pytest.raises(OSError):
Expand Down Expand Up @@ -79,7 +79,7 @@ def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None:
im.load()
assert handler.is_loaded()

temp_file = str(tmp_path / "temp.bufr")
temp_file = tmp_path / "temp.bufr"
im.save(temp_file)
assert handler.saved

Expand Down
18 changes: 9 additions & 9 deletions Tests/test_file_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_sanity_ati1_bc4u(image_path: str) -> None:


def test_dx10_bc2(tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(TEST_FILE_DXT3) as im:
im.save(out, pixel_format="BC2")

Expand All @@ -129,7 +129,7 @@ def test_dx10_bc2(tmp_path: Path) -> None:


def test_dx10_bc3(tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(TEST_FILE_DXT5) as im:
im.save(out, pixel_format="BC3")

Expand Down Expand Up @@ -400,7 +400,7 @@ def test_not_implemented(test_file: str) -> None:


def test_save_unsupported_mode(tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
im = hopper("HSV")
with pytest.raises(OSError, match="cannot write mode HSV as DDS"):
im.save(out)
Expand All @@ -416,7 +416,7 @@ def test_save_unsupported_mode(tmp_path: Path) -> None:
],
)
def test_save(mode: str, test_file: str, tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(test_file) as im:
assert im.mode == mode
im.save(out)
Expand All @@ -425,15 +425,15 @@ def test_save(mode: str, test_file: str, tmp_path: Path) -> None:


def test_save_unsupported_pixel_format(tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
im = hopper()
with pytest.raises(OSError, match="cannot write pixel format UNKNOWN"):
im.save(out, pixel_format="UNKNOWN")


def test_save_dxt1(tmp_path: Path) -> None:
# RGB
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(TEST_FILE_DXT1) as im:
im.convert("RGB").save(out, pixel_format="DXT1")
assert_image_similar_tofile(im, out, 1.84)
Expand All @@ -458,7 +458,7 @@ def test_save_dxt1(tmp_path: Path) -> None:

def test_save_dxt3(tmp_path: Path) -> None:
# RGB
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(TEST_FILE_DXT3) as im:
im_rgb = im.convert("RGB")
im_rgb.save(out, pixel_format="DXT3")
Expand All @@ -481,7 +481,7 @@ def test_save_dxt3(tmp_path: Path) -> None:

def test_save_dxt5(tmp_path: Path) -> None:
# RGB
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(TEST_FILE_DXT1) as im:
im.convert("RGB").save(out, pixel_format="DXT5")
assert_image_similar_tofile(im, out, 1.84)
Expand All @@ -503,7 +503,7 @@ def test_save_dxt5(tmp_path: Path) -> None:


def test_save_dx10_bc5(tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
out = tmp_path / "temp.dds"
with Image.open(TEST_FILE_DX10_BC5_TYPELESS) as im:
im.save(out, pixel_format="BC5")
assert_image_similar_tofile(im, out, 9.56)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_transparency() -> None:
def test_file_object(tmp_path: Path) -> None:
# issue 479
with Image.open(FILE1) as image1:
with open(str(tmp_path / "temp.eps"), "wb") as fh:
with open(tmp_path / "temp.eps", "wb") as fh:
image1.save(fh, "EPS")


Expand Down Expand Up @@ -274,7 +274,7 @@ def test_1(filename: str) -> None:

def test_image_mode_not_supported(tmp_path: Path) -> None:
im = hopper("RGBA")
tmpfile = str(tmp_path / "temp.eps")
tmpfile = tmp_path / "temp.eps"
with pytest.raises(ValueError):
im.save(tmpfile)

Expand Down
Loading
Loading