mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Convert more tests, including a method to skip on ImportError
This commit is contained in:
parent
f14b928ce6
commit
184c380e10
|
@ -1,12 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
def test_copy():
|
||||
def copy(mode):
|
||||
im = lena(mode)
|
||||
out = im.copy()
|
||||
assert_equal(out.mode, mode)
|
||||
assert_equal(out.size, im.size)
|
||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||
yield_test(copy, mode)
|
|
@ -1,13 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
try:
|
||||
from PIL import ImageGrab
|
||||
except ImportError as v:
|
||||
skip(v)
|
||||
|
||||
def test_grab():
|
||||
im = ImageGrab.grab()
|
||||
assert_image(im, im.mode, im.size)
|
||||
|
||||
|
|
@ -12,6 +12,17 @@ else:
|
|||
|
||||
class PillowTestCase(unittest.TestCase):
|
||||
|
||||
def assert_image(self, im, mode, size, msg=None):
|
||||
if mode is not None:
|
||||
self.assertEqual(
|
||||
im.mode, mode,
|
||||
msg or "got mode %r, expected %r" % (im.mode, mode))
|
||||
|
||||
if size is not None:
|
||||
self.assertEqual(
|
||||
im.size, size,
|
||||
msg or "got size %r, expected %r" % (im.size, size))
|
||||
|
||||
def assert_image_equal(self, a, b, msg=None):
|
||||
self.assertEqual(
|
||||
a.mode, b.mode,
|
||||
|
@ -152,15 +163,6 @@ def lena(mode="RGB", cache={}):
|
|||
return im
|
||||
|
||||
|
||||
# def assert_image(im, mode, size, msg=None):
|
||||
# if mode is not None and im.mode != mode:
|
||||
# failure(msg or "got mode %r, expected %r" % (im.mode, mode))
|
||||
# elif size is not None and im.size != size:
|
||||
# failure(msg or "got size %r, expected %r" % (im.size, size))
|
||||
# else:
|
||||
# success()
|
||||
#
|
||||
#
|
||||
# def assert_image_completely_equal(a, b, msg=None):
|
||||
# if a != b:
|
||||
# failure(msg or "images different")
|
||||
|
|
20
test/test_image_copy.py
Normal file
20
test/test_image_copy.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from helper import unittest, PillowTestCase, lena
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class TestImageCopy(PillowTestCase):
|
||||
|
||||
def test_copy(self):
|
||||
def copy(mode):
|
||||
im = lena(mode)
|
||||
out = im.copy()
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size)
|
||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||
copy(mode)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
25
test/test_imagegrab.py
Normal file
25
test/test_imagegrab.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
try:
|
||||
from PIL import ImageGrab
|
||||
|
||||
class TestImageCopy(PillowTestCase):
|
||||
|
||||
def test_grab(self):
|
||||
im = ImageGrab.grab()
|
||||
self.assert_image(im, im.mode, im.size)
|
||||
|
||||
def test_grab2(self):
|
||||
im = ImageGrab.grab()
|
||||
self.assert_image(im, im.mode, im.size)
|
||||
|
||||
except ImportError as v:
|
||||
class TestImageCopy(PillowTestCase):
|
||||
def test_skip(self):
|
||||
self.skipTest(v)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
Loading…
Reference in New Issue
Block a user