From 4814bee6c0b99b4e00fa08a5d15663f8238f063a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 23 Jan 2024 21:42:36 +1100 Subject: [PATCH] Use Path instead of PosixPath --- Tests/check_j2k_overflow.py | 4 ++-- Tests/check_large_memory.py | 8 ++++---- Tests/check_large_memory_numpy.py | 8 ++++---- Tests/test_font_pcf.py | 14 +++++++------- Tests/test_font_pcf_charsets.py | 16 +++++----------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Tests/check_j2k_overflow.py b/Tests/check_j2k_overflow.py index 8a85783fccb..dbdd5a4f557 100644 --- a/Tests/check_j2k_overflow.py +++ b/Tests/check_j2k_overflow.py @@ -1,13 +1,13 @@ from __future__ import annotations -from pathlib import PosixPath +from pathlib import Path import pytest from PIL import Image -def test_j2k_overflow(tmp_path: PosixPath) -> None: +def test_j2k_overflow(tmp_path: Path) -> None: im = Image.new("RGBA", (1024, 131584)) target = str(tmp_path / "temp.jpc") with pytest.raises(OSError): diff --git a/Tests/check_large_memory.py b/Tests/check_large_memory.py index 2c8c77800bb..a9ce79e57e6 100644 --- a/Tests/check_large_memory.py +++ b/Tests/check_large_memory.py @@ -1,7 +1,7 @@ from __future__ import annotations import sys -from pathlib import PosixPath +from pathlib import Path from types import ModuleType import pytest @@ -31,18 +31,18 @@ pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system") -def _write_png(tmp_path: PosixPath, xdim: int, ydim: int) -> None: +def _write_png(tmp_path: Path, xdim: int, ydim: int) -> None: f = str(tmp_path / "temp.png") im = Image.new("L", (xdim, ydim), 0) im.save(f) -def test_large(tmp_path: PosixPath) -> None: +def test_large(tmp_path: Path) -> None: """succeeded prepatch""" _write_png(tmp_path, XDIM, YDIM) -def test_2gpx(tmp_path: PosixPath) -> None: +def test_2gpx(tmp_path: Path) -> None: """failed prepatch""" _write_png(tmp_path, XDIM, XDIM) diff --git a/Tests/check_large_memory_numpy.py b/Tests/check_large_memory_numpy.py index 8609fe6d07b..f4ca8d0aa68 100644 --- a/Tests/check_large_memory_numpy.py +++ b/Tests/check_large_memory_numpy.py @@ -1,7 +1,7 @@ from __future__ import annotations import sys -from pathlib import PosixPath +from pathlib import Path import pytest @@ -25,7 +25,7 @@ pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system") -def _write_png(tmp_path: PosixPath, xdim: int, ydim: int) -> None: +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") @@ -33,11 +33,11 @@ def _write_png(tmp_path: PosixPath, xdim: int, ydim: int) -> None: im.save(f) -def test_large(tmp_path: PosixPath) -> None: +def test_large(tmp_path: Path) -> None: """succeeded prepatch""" _write_png(tmp_path, XDIM, YDIM) -def test_2gpx(tmp_path: PosixPath) -> None: +def test_2gpx(tmp_path: Path) -> None: """failed prepatch""" _write_png(tmp_path, XDIM, XDIM) diff --git a/Tests/test_font_pcf.py b/Tests/test_font_pcf.py index 0f1eabdce39..997809e463b 100644 --- a/Tests/test_font_pcf.py +++ b/Tests/test_font_pcf.py @@ -1,7 +1,7 @@ from __future__ import annotations import os -from pathlib import PosixPath +from pathlib import Path import pytest @@ -21,7 +21,7 @@ pytestmark = skip_unless_feature("zlib") -def save_font(request: pytest.FixtureRequest, tmp_path: PosixPath) -> str: +def save_font(request: pytest.FixtureRequest, tmp_path: Path) -> str: with open(fontname, "rb") as test_file: font = PcfFontFile.PcfFontFile(test_file) assert isinstance(font, FontFile.FontFile) @@ -48,7 +48,7 @@ def delete_tempfile() -> None: return tempname -def test_sanity(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: +def test_sanity(request: pytest.FixtureRequest, tmp_path: Path) -> None: save_font(request, tmp_path) @@ -66,7 +66,7 @@ def test_invalid_file() -> None: PcfFontFile.PcfFontFile(fp) -def test_draw(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: +def test_draw(request: pytest.FixtureRequest, tmp_path: Path) -> None: tempname = save_font(request, tmp_path) font = ImageFont.load(tempname) im = Image.new("L", (130, 30), "white") @@ -75,7 +75,7 @@ def test_draw(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: assert_image_similar_tofile(im, "Tests/images/test_draw_pbm_target.png", 0) -def test_textsize(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: +def test_textsize(request: pytest.FixtureRequest, tmp_path: Path) -> None: tempname = save_font(request, tmp_path) font = ImageFont.load(tempname) for i in range(255): @@ -92,7 +92,7 @@ def test_textsize(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: def _test_high_characters( - request: pytest.FixtureRequest, tmp_path: PosixPath, message: str | bytes + request: pytest.FixtureRequest, tmp_path: Path, message: str | bytes ) -> None: tempname = save_font(request, tmp_path) font = ImageFont.load(tempname) @@ -102,7 +102,7 @@ def _test_high_characters( assert_image_similar_tofile(im, "Tests/images/high_ascii_chars.png", 0) -def test_high_characters(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: +def test_high_characters(request: pytest.FixtureRequest, tmp_path: Path) -> None: message = "".join(chr(i + 1) for i in range(140, 232)) _test_high_characters(request, tmp_path, message) # accept bytes instances. diff --git a/Tests/test_font_pcf_charsets.py b/Tests/test_font_pcf_charsets.py index 894d4eb56bf..895458d9d82 100644 --- a/Tests/test_font_pcf_charsets.py +++ b/Tests/test_font_pcf_charsets.py @@ -1,7 +1,7 @@ from __future__ import annotations import os -from pathlib import PosixPath +from pathlib import Path from typing import TypedDict import pytest @@ -45,9 +45,7 @@ class Charset(TypedDict): pytestmark = skip_unless_feature("zlib") -def save_font( - request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str -) -> str: +def save_font(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) -> str: with open(fontname, "rb") as test_file: font = PcfFontFile.PcfFontFile(test_file, encoding) assert isinstance(font, FontFile.FontFile) @@ -75,16 +73,12 @@ def delete_tempfile() -> None: @pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250")) -def test_sanity( - request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str -) -> None: +def test_sanity(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) -> None: save_font(request, tmp_path, encoding) @pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250")) -def test_draw( - request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str -) -> None: +def test_draw(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) -> None: tempname = save_font(request, tmp_path, encoding) font = ImageFont.load(tempname) im = Image.new("L", (150, 30), "white") @@ -96,7 +90,7 @@ def test_draw( @pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250")) def test_textsize( - request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str + request: pytest.FixtureRequest, tmp_path: Path, encoding: str ) -> None: tempname = save_font(request, tmp_path, encoding) font = ImageFont.load(tempname)