File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 44import sys
55import warnings
66import zlib
7- from io import BytesIO , TextIOWrapper
7+ from io import BytesIO
88from pathlib import Path
99from types import ModuleType
1010from typing import Any , cast
@@ -811,15 +811,19 @@ def test_seek(self) -> None:
811811
812812 @pytest .mark .parametrize ("buffer" , (True , False ))
813813 def test_save_stdout (self , buffer : bool , monkeypatch : pytest .MonkeyPatch ) -> None :
814- b = BytesIO ()
815- mystdout : TextIOWrapper | BytesIO = TextIOWrapper (b ) if buffer else b
814+ class MyStdOut :
815+ buffer = BytesIO ()
816+
817+ mystdout : MyStdOut | BytesIO = MyStdOut () if buffer else BytesIO ()
816818
817819 monkeypatch .setattr (sys , "stdout" , mystdout )
818820
819821 with Image .open (TEST_PNG_FILE ) as im :
820- im .save (sys .stdout , "PNG" )
822+ im .save (sys .stdout , "PNG" ) # type: ignore[arg-type]
821823
822- with Image .open (b ) as reloaded :
824+ if isinstance (mystdout , MyStdOut ):
825+ mystdout = mystdout .buffer
826+ with Image .open (mystdout ) as reloaded :
823827 assert_image_equal_tofile (reloaded , TEST_PNG_FILE )
824828
825829 def test_truncated_end_chunk (self ) -> None :
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import sys
4- from io import BytesIO , TextIOWrapper
4+ from io import BytesIO
55from pathlib import Path
66
77import pytest
@@ -369,13 +369,17 @@ def test_mimetypes(tmp_path: Path) -> None:
369369
370370@pytest .mark .parametrize ("buffer" , (True , False ))
371371def test_save_stdout (buffer : bool , monkeypatch : pytest .MonkeyPatch ) -> None :
372- b = BytesIO ()
373- mystdout : TextIOWrapper | BytesIO = TextIOWrapper (b ) if buffer else b
372+ class MyStdOut :
373+ buffer = BytesIO ()
374+
375+ mystdout : MyStdOut | BytesIO = MyStdOut () if buffer else BytesIO ()
374376
375377 monkeypatch .setattr (sys , "stdout" , mystdout )
376378
377379 with Image .open (TEST_FILE ) as im :
378- im .save (sys .stdout , "PPM" )
380+ im .save (sys .stdout , "PPM" ) # type: ignore[arg-type]
379381
380- with Image .open (b ) as reloaded :
382+ if isinstance (mystdout , MyStdOut ):
383+ mystdout = mystdout .buffer
384+ with Image .open (mystdout ) as reloaded :
381385 assert_image_equal_tofile (reloaded , TEST_FILE )
You can’t perform that action at this time.
0 commit comments