Pillow/Tests/test_imagewin.py
Jon Dufresne 7da17ad41e Improve pytest configuration to allow specific tests as CLI args
The previous test configuration made it difficult to run a single test
with the pytest CLI. There were two major issues:

- The Tests directory was not a package. It now includes a __init__.py
  file and imports from other tests modules are done with relative
  imports.

- setup.cfg always specified the Tests directory. So even if a specific
  test were specified as a CLI arg, this configuration would also always
  include all tests. This configuration has been removed to allow
  specifying a single test on the command line.

Contributors can now run specific tests with a single command such as:

  $ tox -e py37 -- Tests/test_file_pdf.py::TestFilePdf.test_rgb

This makes it easy and faster to iterate on a single test failure and is
very familiar to those that have previously used tox and pytest.

When running tox or pytest with no arguments, they still discover and
runs all tests in the Tests directory.
2019-01-13 09:00:12 -08:00

113 lines
2.2 KiB
Python

from .helper import unittest, PillowTestCase, hopper
from PIL import ImageWin
import sys
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(sys.platform.startswith('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())
if __name__ == '__main__':
unittest.main()