Skip to content

Commit

Permalink
Use Path instead of PosixPath
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 23, 2024
1 parent 16fd934 commit 4814bee
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Tests/check_j2k_overflow.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 4 additions & 4 deletions Tests/check_large_memory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
from pathlib import PosixPath
from pathlib import Path
from types import ModuleType

import pytest
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions Tests/check_large_memory_numpy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
from pathlib import PosixPath
from pathlib import Path

import pytest

Expand All @@ -25,19 +25,19 @@
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")
im = Image.fromarray(a, "L")
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)
14 changes: 7 additions & 7 deletions Tests/test_font_pcf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
from pathlib import PosixPath
from pathlib import Path

import pytest

Expand All @@ -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)
Expand All @@ -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)


Expand All @@ -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")
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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.
Expand Down
16 changes: 5 additions & 11 deletions Tests/test_font_pcf_charsets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
from pathlib import PosixPath
from pathlib import Path
from typing import TypedDict

import pytest
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 4814bee

Please sign in to comment.