Pillow/Tests/test_imagewin.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
2.3 KiB
Python
Raw Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
2020-03-02 17:02:19 +03:00
import pytest
from PIL import ImageWin
2020-03-02 17:02:19 +03:00
from .helper import hopper, is_win32
2014-06-10 13:10:47 +04:00
2020-03-02 17:02:19 +03:00
class TestImageWin:
def test_sanity(self) -> None:
2014-06-10 13:10:47 +04:00
dir(ImageWin)
def test_hdc(self) -> None:
# Arrange
dc = 50
# Act
hdc = ImageWin.HDC(dc)
dc2 = int(hdc)
# Assert
assert dc2 == 50
def test_hwnd(self) -> None:
# Arrange
wnd = 50
# Act
hwnd = ImageWin.HWND(wnd)
wnd2 = int(hwnd)
# Assert
assert wnd2 == 50
2014-06-10 13:10:47 +04:00
2020-03-02 17:02:19 +03:00
@pytest.mark.skipif(not is_win32(), reason="Windows only")
class TestImageWinDib:
def test_dib_image(self) -> None:
2014-09-18 18:50:31 +04:00
# Arrange
im = hopper()
# Act
dib = ImageWin.Dib(im)
# Assert
assert dib.size == im.size
2014-09-18 18:50:31 +04:00
def test_dib_mode_string(self) -> None:
2014-09-18 18:50:31 +04:00
# Arrange
mode = "RGBA"
size = (128, 128)
# Act
dib = ImageWin.Dib(mode, size)
# Assert
assert dib.size == (128, 128)
2014-09-18 18:50:31 +04:00
def test_dib_paste(self) -> None:
2014-09-18 18:50:31 +04:00
# Arrange
im = hopper()
mode = "RGBA"
size = (128, 128)
dib = ImageWin.Dib(mode, size)
# Act
dib.paste(im)
# Assert
assert dib.size == (128, 128)
2014-09-18 18:50:31 +04:00
def test_dib_paste_bbox(self) -> None:
2014-09-18 18:50:31 +04:00
# Arrange
im = hopper()
bbox = (0, 0, 10, 10)
mode = "RGBA"
size = (128, 128)
dib = ImageWin.Dib(mode, size)
# Act
dib.paste(im, bbox)
# Assert
assert dib.size == (128, 128)
2014-09-18 18:50:31 +04:00
def test_dib_frombytes_tobytes_roundtrip(self) -> None:
2014-09-18 18:50:31 +04:00
# Arrange
# Make two different DIB images
im = hopper()
dib1 = ImageWin.Dib(im)
mode = "RGB"
size = (128, 128)
dib2 = ImageWin.Dib(mode, size)
# Confirm they're different
assert dib1.tobytes() != dib2.tobytes()
2014-09-18 18:50:31 +04:00
# Act
# Make one the same as the using tobytes()/frombytes()
2015-04-24 11:24:52 +03:00
test_buffer = dib1.tobytes()
for datatype in ("bytes", "memoryview"):
if datatype == "memoryview":
test_buffer = memoryview(test_buffer)
dib2.frombytes(test_buffer)
# Assert
# Confirm they're the same
assert dib1.tobytes() == dib2.tobytes()