From 165d2765f60d91180708a3de905ba1d012d7c8a0 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 18 Sep 2014 17:50:31 +0300 Subject: [PATCH] Add some Windows-only tests --- Tests/test_imagewin.py | 89 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index 0ff22601e..6fb58a0dc 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -1,6 +1,7 @@ -from helper import unittest, PillowTestCase +from helper import unittest, PillowTestCase, hopper from PIL import ImageWin +import sys class TestImageWin(PillowTestCase): @@ -32,6 +33,92 @@ class TestImageWin(PillowTestCase): 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() + buffer = dib1.tobytes() + dib2.frombytes(buffer) + + # Assert + # Confirm they're the same + self.assertEqual(dib1.tobytes(), dib2.tobytes()) + + def test_dib_fromstring_tostring_deprecated(self): + # Arrange + im = hopper() + dib = ImageWin.Dib(im) + buffer = dib.tobytes() + + # Act/Assert + self.assert_warning(DeprecationWarning, lambda: dib.tostring()) + self.assert_warning(DeprecationWarning, lambda: dib.fromstring(buffer)) + + if __name__ == '__main__': unittest.main()