mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 05:34:36 +03:00
Add tests for saving to stdout
This commit is contained in:
parent
f55ccd9563
commit
0f11d22cce
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -870,6 +871,33 @@ class TestFileJpeg:
|
||||||
with Image.open("Tests/images/hopper.jpg") as im:
|
with Image.open("Tests/images/hopper.jpg") as im:
|
||||||
assert im.getxmp() == {}
|
assert im.getxmp() == {}
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("buffer", (True, False))
|
||||||
|
def test_save_stdout(self, buffer):
|
||||||
|
old_stdout = sys.stdout
|
||||||
|
|
||||||
|
if buffer:
|
||||||
|
|
||||||
|
class MyStdOut:
|
||||||
|
buffer = BytesIO()
|
||||||
|
|
||||||
|
mystdout = MyStdOut()
|
||||||
|
else:
|
||||||
|
mystdout = BytesIO()
|
||||||
|
|
||||||
|
sys.stdout = mystdout
|
||||||
|
|
||||||
|
with Image.open(TEST_FILE) as im:
|
||||||
|
im.save(sys.stdout, "JPEG")
|
||||||
|
im_roundtrip = self.roundtrip(im)
|
||||||
|
|
||||||
|
# Reset stdout
|
||||||
|
sys.stdout = old_stdout
|
||||||
|
|
||||||
|
if buffer:
|
||||||
|
mystdout = mystdout.buffer
|
||||||
|
reloaded = Image.open(mystdout)
|
||||||
|
assert_image_equal(reloaded, im_roundtrip)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
||||||
@skip_unless_feature("jpg")
|
@skip_unless_feature("jpg")
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import sys
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
@ -80,3 +83,30 @@ def test_mimetypes(tmp_path):
|
||||||
f.write("PyCMYK\n128 128\n255")
|
f.write("PyCMYK\n128 128\n255")
|
||||||
with Image.open(path) as im:
|
with Image.open(path) as im:
|
||||||
assert im.get_format_mimetype() == "image/x-portable-anymap"
|
assert im.get_format_mimetype() == "image/x-portable-anymap"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("buffer", (True, False))
|
||||||
|
def test_save_stdout(buffer):
|
||||||
|
old_stdout = sys.stdout
|
||||||
|
|
||||||
|
if buffer:
|
||||||
|
|
||||||
|
class MyStdOut:
|
||||||
|
buffer = BytesIO()
|
||||||
|
|
||||||
|
mystdout = MyStdOut()
|
||||||
|
else:
|
||||||
|
mystdout = BytesIO()
|
||||||
|
|
||||||
|
sys.stdout = mystdout
|
||||||
|
|
||||||
|
with Image.open(TEST_FILE) as im:
|
||||||
|
im.save(sys.stdout, "PPM")
|
||||||
|
|
||||||
|
# Reset stdout
|
||||||
|
sys.stdout = old_stdout
|
||||||
|
|
||||||
|
if buffer:
|
||||||
|
mystdout = mystdout.buffer
|
||||||
|
reloaded = Image.open(mystdout)
|
||||||
|
assert_image_equal_tofile(reloaded, TEST_FILE)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user