mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Use Path instead of PosixPath
This commit is contained in:
		
							parent
							
								
									16fd934b00
								
							
						
					
					
						commit
						4814bee6c0
					
				| 
						 | 
					@ -1,13 +1,13 @@
 | 
				
			||||||
from __future__ import annotations
 | 
					from __future__ import annotations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from pathlib import PosixPath
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from PIL import Image
 | 
					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))
 | 
					    im = Image.new("RGBA", (1024, 131584))
 | 
				
			||||||
    target = str(tmp_path / "temp.jpc")
 | 
					    target = str(tmp_path / "temp.jpc")
 | 
				
			||||||
    with pytest.raises(OSError):
 | 
					    with pytest.raises(OSError):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
from __future__ import annotations
 | 
					from __future__ import annotations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
from pathlib import PosixPath
 | 
					from pathlib import Path
 | 
				
			||||||
from types import ModuleType
 | 
					from types import ModuleType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
| 
						 | 
					@ -31,18 +31,18 @@ XDIM = 48000
 | 
				
			||||||
pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system")
 | 
					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")
 | 
					    f = str(tmp_path / "temp.png")
 | 
				
			||||||
    im = Image.new("L", (xdim, ydim), 0)
 | 
					    im = Image.new("L", (xdim, ydim), 0)
 | 
				
			||||||
    im.save(f)
 | 
					    im.save(f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_large(tmp_path: PosixPath) -> None:
 | 
					def test_large(tmp_path: Path) -> None:
 | 
				
			||||||
    """succeeded prepatch"""
 | 
					    """succeeded prepatch"""
 | 
				
			||||||
    _write_png(tmp_path, XDIM, YDIM)
 | 
					    _write_png(tmp_path, XDIM, YDIM)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_2gpx(tmp_path: PosixPath) -> None:
 | 
					def test_2gpx(tmp_path: Path) -> None:
 | 
				
			||||||
    """failed prepatch"""
 | 
					    """failed prepatch"""
 | 
				
			||||||
    _write_png(tmp_path, XDIM, XDIM)
 | 
					    _write_png(tmp_path, XDIM, XDIM)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
from __future__ import annotations
 | 
					from __future__ import annotations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
from pathlib import PosixPath
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ XDIM = 48000
 | 
				
			||||||
pytestmark = pytest.mark.skipif(sys.maxsize <= 2**32, reason="requires 64-bit system")
 | 
					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
 | 
					    dtype = np.uint8
 | 
				
			||||||
    a = np.zeros((xdim, ydim), dtype=dtype)
 | 
					    a = np.zeros((xdim, ydim), dtype=dtype)
 | 
				
			||||||
    f = str(tmp_path / "temp.png")
 | 
					    f = str(tmp_path / "temp.png")
 | 
				
			||||||
| 
						 | 
					@ -33,11 +33,11 @@ def _write_png(tmp_path: PosixPath, xdim: int, ydim: int) -> None:
 | 
				
			||||||
    im.save(f)
 | 
					    im.save(f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_large(tmp_path: PosixPath) -> None:
 | 
					def test_large(tmp_path: Path) -> None:
 | 
				
			||||||
    """succeeded prepatch"""
 | 
					    """succeeded prepatch"""
 | 
				
			||||||
    _write_png(tmp_path, XDIM, YDIM)
 | 
					    _write_png(tmp_path, XDIM, YDIM)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_2gpx(tmp_path: PosixPath) -> None:
 | 
					def test_2gpx(tmp_path: Path) -> None:
 | 
				
			||||||
    """failed prepatch"""
 | 
					    """failed prepatch"""
 | 
				
			||||||
    _write_png(tmp_path, XDIM, XDIM)
 | 
					    _write_png(tmp_path, XDIM, XDIM)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
from __future__ import annotations
 | 
					from __future__ import annotations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from pathlib import PosixPath
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@ message = "hello, world"
 | 
				
			||||||
pytestmark = skip_unless_feature("zlib")
 | 
					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:
 | 
					    with open(fontname, "rb") as test_file:
 | 
				
			||||||
        font = PcfFontFile.PcfFontFile(test_file)
 | 
					        font = PcfFontFile.PcfFontFile(test_file)
 | 
				
			||||||
    assert isinstance(font, FontFile.FontFile)
 | 
					    assert isinstance(font, FontFile.FontFile)
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ def save_font(request: pytest.FixtureRequest, tmp_path: PosixPath) -> str:
 | 
				
			||||||
    return tempname
 | 
					    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)
 | 
					    save_font(request, tmp_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ def test_invalid_file() -> None:
 | 
				
			||||||
            PcfFontFile.PcfFontFile(fp)
 | 
					            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)
 | 
					    tempname = save_font(request, tmp_path)
 | 
				
			||||||
    font = ImageFont.load(tempname)
 | 
					    font = ImageFont.load(tempname)
 | 
				
			||||||
    im = Image.new("L", (130, 30), "white")
 | 
					    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)
 | 
					    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)
 | 
					    tempname = save_font(request, tmp_path)
 | 
				
			||||||
    font = ImageFont.load(tempname)
 | 
					    font = ImageFont.load(tempname)
 | 
				
			||||||
    for i in range(255):
 | 
					    for i in range(255):
 | 
				
			||||||
| 
						 | 
					@ -92,7 +92,7 @@ def test_textsize(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _test_high_characters(
 | 
					def _test_high_characters(
 | 
				
			||||||
    request: pytest.FixtureRequest, tmp_path: PosixPath, message: str | bytes
 | 
					    request: pytest.FixtureRequest, tmp_path: Path, message: str | bytes
 | 
				
			||||||
) -> None:
 | 
					) -> None:
 | 
				
			||||||
    tempname = save_font(request, tmp_path)
 | 
					    tempname = save_font(request, tmp_path)
 | 
				
			||||||
    font = ImageFont.load(tempname)
 | 
					    font = ImageFont.load(tempname)
 | 
				
			||||||
| 
						 | 
					@ -102,7 +102,7 @@ def _test_high_characters(
 | 
				
			||||||
    assert_image_similar_tofile(im, "Tests/images/high_ascii_chars.png", 0)
 | 
					    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))
 | 
					    message = "".join(chr(i + 1) for i in range(140, 232))
 | 
				
			||||||
    _test_high_characters(request, tmp_path, message)
 | 
					    _test_high_characters(request, tmp_path, message)
 | 
				
			||||||
    # accept bytes instances.
 | 
					    # accept bytes instances.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
from __future__ import annotations
 | 
					from __future__ import annotations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from pathlib import PosixPath
 | 
					from pathlib import Path
 | 
				
			||||||
from typing import TypedDict
 | 
					from typing import TypedDict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
| 
						 | 
					@ -45,9 +45,7 @@ charsets: dict[str, Charset] = {
 | 
				
			||||||
pytestmark = skip_unless_feature("zlib")
 | 
					pytestmark = skip_unless_feature("zlib")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def save_font(
 | 
					def save_font(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) -> str:
 | 
				
			||||||
    request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str
 | 
					 | 
				
			||||||
) -> str:
 | 
					 | 
				
			||||||
    with open(fontname, "rb") as test_file:
 | 
					    with open(fontname, "rb") as test_file:
 | 
				
			||||||
        font = PcfFontFile.PcfFontFile(test_file, encoding)
 | 
					        font = PcfFontFile.PcfFontFile(test_file, encoding)
 | 
				
			||||||
    assert isinstance(font, FontFile.FontFile)
 | 
					    assert isinstance(font, FontFile.FontFile)
 | 
				
			||||||
| 
						 | 
					@ -75,16 +73,12 @@ def save_font(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
 | 
					@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
 | 
				
			||||||
def test_sanity(
 | 
					def test_sanity(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) -> None:
 | 
				
			||||||
    request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str
 | 
					 | 
				
			||||||
) -> None:
 | 
					 | 
				
			||||||
    save_font(request, tmp_path, encoding)
 | 
					    save_font(request, tmp_path, encoding)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
 | 
					@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
 | 
				
			||||||
def test_draw(
 | 
					def test_draw(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) -> None:
 | 
				
			||||||
    request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str
 | 
					 | 
				
			||||||
) -> None:
 | 
					 | 
				
			||||||
    tempname = save_font(request, tmp_path, encoding)
 | 
					    tempname = save_font(request, tmp_path, encoding)
 | 
				
			||||||
    font = ImageFont.load(tempname)
 | 
					    font = ImageFont.load(tempname)
 | 
				
			||||||
    im = Image.new("L", (150, 30), "white")
 | 
					    im = Image.new("L", (150, 30), "white")
 | 
				
			||||||
| 
						 | 
					@ -96,7 +90,7 @@ def test_draw(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
 | 
					@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
 | 
				
			||||||
def test_textsize(
 | 
					def test_textsize(
 | 
				
			||||||
    request: pytest.FixtureRequest, tmp_path: PosixPath, encoding: str
 | 
					    request: pytest.FixtureRequest, tmp_path: Path, encoding: str
 | 
				
			||||||
) -> None:
 | 
					) -> None:
 | 
				
			||||||
    tempname = save_font(request, tmp_path, encoding)
 | 
					    tempname = save_font(request, tmp_path, encoding)
 | 
				
			||||||
    font = ImageFont.load(tempname)
 | 
					    font = ImageFont.load(tempname)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user