加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_imagewin.py 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
LLL 提交于 2022-06-27 15:20 . Import Upstream version 7.0.0
import unittest
from PIL import ImageWin
from .helper import PillowTestCase, hopper, is_win32
class TestImageWin(PillowTestCase):
def test_sanity(self):
dir(ImageWin)
def test_hdc(self):
# Arrange
dc = 50
# Act
hdc = ImageWin.HDC(dc)
dc2 = int(hdc)
# Assert
self.assertEqual(dc2, 50)
def test_hwnd(self):
# Arrange
wnd = 50
# Act
hwnd = ImageWin.HWND(wnd)
wnd2 = int(hwnd)
# Assert
self.assertEqual(wnd2, 50)
@unittest.skipUnless(is_win32(), "Windows only")
class TestImageWinDib(PillowTestCase):
def test_dib_image(self):
# Arrange
im = hopper()
# Act
dib = ImageWin.Dib(im)
# Assert
self.assertEqual(dib.size, im.size)
def test_dib_mode_string(self):
# Arrange
mode = "RGBA"
size = (128, 128)
# Act
dib = ImageWin.Dib(mode, size)
# Assert
self.assertEqual(dib.size, (128, 128))
def test_dib_paste(self):
# Arrange
im = hopper()
mode = "RGBA"
size = (128, 128)
dib = ImageWin.Dib(mode, size)
# Act
dib.paste(im)
# Assert
self.assertEqual(dib.size, (128, 128))
def test_dib_paste_bbox(self):
# Arrange
im = hopper()
bbox = (0, 0, 10, 10)
mode = "RGBA"
size = (128, 128)
dib = ImageWin.Dib(mode, size)
# Act
dib.paste(im, bbox)
# Assert
self.assertEqual(dib.size, (128, 128))
def test_dib_frombytes_tobytes_roundtrip(self):
# 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
self.assertNotEqual(dib1.tobytes(), dib2.tobytes())
# Act
# Make one the same as the using tobytes()/frombytes()
test_buffer = dib1.tobytes()
dib2.frombytes(test_buffer)
# Assert
# Confirm they're the same
self.assertEqual(dib1.tobytes(), dib2.tobytes())
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化