Skip to content

Commit

Permalink
autotyping: --annotate-named-param tmp_path:pathlib.Path
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jan 27, 2024
1 parent c42825d commit e3e83b9
Show file tree
Hide file tree
Showing 47 changed files with 379 additions and 317 deletions.
18 changes: 10 additions & 8 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pathlib import Path

import pytest

from PIL import Image, ImageSequence, PngImagePlugin
Expand Down Expand Up @@ -343,7 +345,7 @@ def test_apng_sequence_errors(test_file) -> None:
im.load()


def test_apng_save(tmp_path) -> 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")
im.save(test_file, save_all=True)
Expand Down Expand Up @@ -374,7 +376,7 @@ def test_apng_save(tmp_path) -> None:
assert im.getpixel((64, 32)) == (0, 255, 0, 255)


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

im = Image.new("RGBA", (1, 1), (255, 0, 0, 255))
Expand All @@ -388,7 +390,7 @@ def test_apng_save_alpha(tmp_path) -> None:
assert reloaded.getpixel((0, 0)) == (255, 0, 0, 127)


def test_apng_save_split_fdat(tmp_path) -> None:
def test_apng_save_split_fdat(tmp_path: Path) -> None:
# test to make sure we do not generate sequence errors when writing
# frames with image data spanning multiple fdAT chunks (in this case
# both the default image and first animation frame will span multiple
Expand All @@ -412,7 +414,7 @@ def test_apng_save_split_fdat(tmp_path) -> None:
assert exception is None


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


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


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


def test_apng_save_blend(tmp_path) -> None:
def test_apng_save_blend(tmp_path: Path) -> None:
test_file = str(tmp_path / "temp.png")
size = (128, 64)
red = Image.new("RGBA", size, (255, 0, 0, 255))
Expand Down Expand Up @@ -679,7 +681,7 @@ def test_seek_after_close() -> None:
@pytest.mark.parametrize("default_image", (True, False))
@pytest.mark.parametrize("duplicate", (True, False))
def test_different_modes_in_later_frames(
mode, default_image, duplicate, tmp_path
mode, default_image, duplicate, tmp_path: Path
) -> None:
test_file = str(tmp_path / "temp.png")

Expand Down
4 changes: 3 additions & 1 deletion Tests/test_file_blp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pathlib import Path

import pytest

from PIL import Image
Expand Down Expand Up @@ -35,7 +37,7 @@ def test_load_blp2_dxt1a() -> None:
assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1a.png")


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

for version in ("BLP1", "BLP2"):
Expand Down
13 changes: 7 additions & 6 deletions Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import io
from pathlib import Path

import pytest

Expand All @@ -14,7 +15,7 @@
)


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

Expand Down Expand Up @@ -60,7 +61,7 @@ def test_save_to_bytes() -> None:
assert reloaded.format == "BMP"


def test_small_palette(tmp_path) -> None:
def test_small_palette(tmp_path: Path) -> None:
im = Image.new("P", (1, 1))
colors = [0, 0, 0, 125, 125, 125, 255, 255, 255]
im.putpalette(colors)
Expand All @@ -72,7 +73,7 @@ def test_small_palette(tmp_path) -> None:
assert reloaded.getpalette() == colors


def test_save_too_large(tmp_path) -> None:
def test_save_too_large(tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.bmp")
with Image.new("RGB", (1, 1)) as im:
im._size = (37838, 37838)
Expand All @@ -92,7 +93,7 @@ def test_dpi() -> None:
assert reloaded.info["dpi"] == (72.008961115161, 72.008961115161)


def test_save_bmp_with_dpi(tmp_path) -> None:
def test_save_bmp_with_dpi(tmp_path: Path) -> None:
# Test for #1301
# Arrange
outfile = str(tmp_path / "temp.jpg")
Expand All @@ -110,7 +111,7 @@ def test_save_bmp_with_dpi(tmp_path) -> None:
assert reloaded.format == "JPEG"


def test_save_float_dpi(tmp_path) -> None:
def test_save_float_dpi(tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.bmp")
with Image.open("Tests/images/hopper.bmp") as im:
im.save(outfile, dpi=(72.21216100543306, 72.21216100543306))
Expand All @@ -127,7 +128,7 @@ def test_load_dib() -> None:
assert_image_equal_tofile(im, "Tests/images/clipboard_target.png")


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

with Image.open("Tests/images/clipboard.dib") as im:
Expand Down
6 changes: 4 additions & 2 deletions Tests/test_file_bufrstub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pathlib import Path

import pytest

from PIL import BufrStubImagePlugin, Image
Expand Down Expand Up @@ -37,7 +39,7 @@ def test_load() -> None:
im.load()


def test_save(tmp_path) -> None:
def test_save(tmp_path: Path) -> None:
# Arrange
im = hopper()
tmpfile = str(tmp_path / "temp.bufr")
Expand All @@ -47,7 +49,7 @@ def test_save(tmp_path) -> None:
im.save(tmpfile)


def test_handler(tmp_path) -> None:
def test_handler(tmp_path: Path) -> None:
class TestHandler:
opened = False
loaded = False
Expand Down
5 changes: 3 additions & 2 deletions Tests/test_file_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from io import BytesIO
from pathlib import Path

import pytest

Expand Down Expand Up @@ -363,7 +364,7 @@ def test_not_implemented(test_file) -> None:
pass


def test_save_unsupported_mode(tmp_path) -> None:
def test_save_unsupported_mode(tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
im = hopper("HSV")
with pytest.raises(OSError):
Expand All @@ -379,7 +380,7 @@ def test_save_unsupported_mode(tmp_path) -> None:
("RGBA", "Tests/images/pil123rgba.png"),
],
)
def test_save(mode, test_file, tmp_path) -> None:
def test_save(mode, test_file, tmp_path: Path) -> None:
out = str(tmp_path / "temp.dds")
with Image.open(test_file) as im:
assert im.mode == mode
Expand Down
7 changes: 4 additions & 3 deletions Tests/test_file_eps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import io
from pathlib import Path

import pytest

Expand Down Expand Up @@ -225,7 +226,7 @@ def test_transparency() -> None:


@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
def test_file_object(tmp_path) -> 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:
Expand All @@ -251,7 +252,7 @@ def test_1_mode() -> None:
assert im.mode == "1"


def test_image_mode_not_supported(tmp_path) -> None:
def test_image_mode_not_supported(tmp_path: Path) -> None:
im = hopper("RGBA")
tmpfile = str(tmp_path / "temp.eps")
with pytest.raises(ValueError):
Expand Down Expand Up @@ -328,7 +329,7 @@ def test_read_binary_preview() -> None:
pass


def test_readline_psfile(tmp_path) -> None:
def test_readline_psfile(tmp_path: Path) -> None:
# check all the freaking line endings possible from the spec
# test_string = u'something\r\nelse\n\rbaz\rbif\n'
line_endings = ["\r\n", "\n", "\n\r", "\r"]
Expand Down
Loading

0 comments on commit e3e83b9

Please sign in to comment.