Skip to content

Commit 5ad234c

Browse files
committed
Ignore sys.stdout type
1 parent dae3154 commit 5ad234c

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Tests/test_file_png.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import warnings
66
import zlib
7-
from io import BytesIO, TextIOWrapper
7+
from io import BytesIO
88
from pathlib import Path
99
from types import ModuleType
1010
from 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:

Tests/test_file_ppm.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4-
from io import BytesIO, TextIOWrapper
4+
from io import BytesIO
55
from pathlib import Path
66

77
import pytest
@@ -369,13 +369,17 @@ def test_mimetypes(tmp_path: Path) -> None:
369369

370370
@pytest.mark.parametrize("buffer", (True, False))
371371
def 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)

0 commit comments

Comments
 (0)