File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -178,9 +178,9 @@ def test_default_num_resolutions(
178178
179179def test_reduce () -> None :
180180 with Image .open ("Tests/images/test-card-lossless.jp2" ) as im :
181- assert callable (im . reduce )
181+ assert isinstance (im , Jpeg2KImagePlugin . Jpeg2KImageFile )
182182
183- im .reduce = 2 # type: ignore[assignment, method-assign]
183+ im .reduce = 2
184184 assert im .reduce == 2
185185
186186 im .load ()
Original file line number Diff line number Diff line change 44import sys
55import warnings
66import zlib
7- from io import BytesIO
7+ from io import BytesIO , TextIOWrapper
88from pathlib import Path
99from types import ModuleType
1010from typing import Any , cast
@@ -821,19 +821,15 @@ def test_seek(self) -> None:
821821 @pytest .mark .parametrize ("buffer" , (True , False ))
822822 def test_save_stdout (self , buffer : bool , monkeypatch : pytest .MonkeyPatch ) -> None :
823823
824- class MyStdOut :
825- buffer = BytesIO ()
826-
827- mystdout : MyStdOut | BytesIO = MyStdOut () if buffer else BytesIO ()
824+ fp = BytesIO ()
825+ mystdout = TextIOWrapper (fp ) if buffer else fp
828826
829827 monkeypatch .setattr (sys , "stdout" , mystdout )
830828
831829 with Image .open (TEST_PNG_FILE ) as im :
832830 im .save (sys .stdout , "PNG" ) # type: ignore[arg-type]
833831
834- if isinstance (mystdout , MyStdOut ):
835- mystdout = mystdout .buffer
836- with Image .open (mystdout ) as reloaded :
832+ with Image .open (fp ) as reloaded :
837833 assert_image_equal_tofile (reloaded , TEST_PNG_FILE )
838834
839835 def test_truncated_end_chunk (self , monkeypatch : pytest .MonkeyPatch ) -> None :
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import sys
4- from io import BytesIO
4+ from io import BytesIO , TextIOWrapper
55from pathlib import Path
66
77import pytest
@@ -381,17 +381,13 @@ def test_mimetypes(tmp_path: Path) -> None:
381381@pytest .mark .parametrize ("buffer" , (True , False ))
382382def test_save_stdout (buffer : bool , monkeypatch : pytest .MonkeyPatch ) -> None :
383383
384- class MyStdOut :
385- buffer = BytesIO ()
386-
387- mystdout : MyStdOut | BytesIO = MyStdOut () if buffer else BytesIO ()
384+ fp = BytesIO ()
385+ mystdout = TextIOWrapper (fp ) if buffer else fp
388386
389387 monkeypatch .setattr (sys , "stdout" , mystdout )
390388
391389 with Image .open (TEST_FILE ) as im :
392390 im .save (sys .stdout , "PPM" ) # type: ignore[arg-type]
393391
394- if isinstance (mystdout , MyStdOut ):
395- mystdout = mystdout .buffer
396- with Image .open (mystdout ) as reloaded :
392+ with Image .open (fp ) as reloaded :
397393 assert_image_equal_tofile (reloaded , TEST_FILE )
You can’t perform that action at this time.
0 commit comments