mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-13 17:25:49 +03:00
Move more tests; remove some redundant helpers
This commit is contained in:
parent
d082c58043
commit
2e52f3ab46
|
@ -1,24 +0,0 @@
|
|||
from __future__ import print_function
|
||||
from tester import *
|
||||
|
||||
import PIL
|
||||
import PIL.Image
|
||||
|
||||
# Make sure we have the binary extension
|
||||
im = PIL.Image.core.new("L", (100, 100))
|
||||
|
||||
assert PIL.Image.VERSION[:3] == '1.1'
|
||||
|
||||
# Create an image and do stuff with it.
|
||||
im = PIL.Image.new("1", (100, 100))
|
||||
assert (im.mode, im.size) == ('1', (100, 100))
|
||||
assert len(im.tobytes()) == 1300
|
||||
|
||||
# Create images in all remaining major modes.
|
||||
im = PIL.Image.new("L", (100, 100))
|
||||
im = PIL.Image.new("P", (100, 100))
|
||||
im = PIL.Image.new("RGB", (100, 100))
|
||||
im = PIL.Image.new("I", (100, 100))
|
||||
im = PIL.Image.new("F", (100, 100))
|
||||
|
||||
print("ok")
|
|
@ -1,19 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
def test_histogram():
|
||||
|
||||
def histogram(mode):
|
||||
h = lena(mode).histogram()
|
||||
return len(h), min(h), max(h)
|
||||
|
||||
assert_equal(histogram("1"), (256, 0, 8872))
|
||||
assert_equal(histogram("L"), (256, 0, 199))
|
||||
assert_equal(histogram("I"), (256, 0, 199))
|
||||
assert_equal(histogram("F"), (256, 0, 199))
|
||||
assert_equal(histogram("P"), (256, 0, 2912))
|
||||
assert_equal(histogram("RGB"), (768, 0, 285))
|
||||
assert_equal(histogram("RGBA"), (1024, 0, 16384))
|
||||
assert_equal(histogram("CMYK"), (1024, 0, 16384))
|
||||
assert_equal(histogram("YCbCr"), (768, 0, 741))
|
|
@ -1,19 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageEnhance
|
||||
|
||||
def test_sanity():
|
||||
|
||||
# FIXME: assert_image
|
||||
assert_no_exception(lambda: ImageEnhance.Color(lena()).enhance(0.5))
|
||||
assert_no_exception(lambda: ImageEnhance.Contrast(lena()).enhance(0.5))
|
||||
assert_no_exception(lambda: ImageEnhance.Brightness(lena()).enhance(0.5))
|
||||
assert_no_exception(lambda: ImageEnhance.Sharpness(lena()).enhance(0.5))
|
||||
|
||||
def test_crash():
|
||||
|
||||
# crashes on small images
|
||||
im = Image.new("RGB", (1, 1))
|
||||
assert_no_exception(lambda: ImageEnhance.Sharpness(im).enhance(0.5))
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
def test_setmode():
|
||||
|
||||
im = Image.new("L", (1, 1), 255)
|
||||
im.im.setmode("1")
|
||||
assert_equal(im.im.getpixel((0, 0)), 255)
|
||||
im.im.setmode("L")
|
||||
assert_equal(im.im.getpixel((0, 0)), 255)
|
||||
|
||||
im = Image.new("1", (1, 1), 1)
|
||||
im.im.setmode("L")
|
||||
assert_equal(im.im.getpixel((0, 0)), 255)
|
||||
im.im.setmode("1")
|
||||
assert_equal(im.im.getpixel((0, 0)), 255)
|
||||
|
||||
im = Image.new("RGB", (1, 1), (1, 2, 3))
|
||||
im.im.setmode("RGB")
|
||||
assert_equal(im.im.getpixel((0, 0)), (1, 2, 3))
|
||||
im.im.setmode("RGBA")
|
||||
assert_equal(im.im.getpixel((0, 0)), (1, 2, 3, 255))
|
||||
im.im.setmode("RGBX")
|
||||
assert_equal(im.im.getpixel((0, 0)), (1, 2, 3, 255))
|
||||
im.im.setmode("RGB")
|
||||
assert_equal(im.im.getpixel((0, 0)), (1, 2, 3))
|
||||
|
||||
assert_exception(ValueError, lambda: im.im.setmode("L"))
|
||||
assert_exception(ValueError, lambda: im.im.setmode("RGBABCDE"))
|
32
test/test_000_sanity.py
Normal file
32
test/test_000_sanity.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from tester import unittest, PillowTestCase
|
||||
|
||||
import PIL
|
||||
import PIL.Image
|
||||
|
||||
|
||||
class TestSanity(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
|
||||
# Make sure we have the binary extension
|
||||
im = PIL.Image.core.new("L", (100, 100))
|
||||
|
||||
self.assertEqual(PIL.Image.VERSION[:3], '1.1')
|
||||
|
||||
# Create an image and do stuff with it.
|
||||
im = PIL.Image.new("1", (100, 100))
|
||||
self.assertEqual((im.mode, im.size), ('1', (100, 100)))
|
||||
self.assertEqual(len(im.tobytes()), 1300)
|
||||
|
||||
# Create images in all remaining major modes.
|
||||
im = PIL.Image.new("L", (100, 100))
|
||||
im = PIL.Image.new("P", (100, 100))
|
||||
im = PIL.Image.new("RGB", (100, 100))
|
||||
im = PIL.Image.new("I", (100, 100))
|
||||
im = PIL.Image.new("F", (100, 100))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
26
test/test_image_histogram.py
Normal file
26
test/test_image_histogram.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from tester import unittest, PillowTestCase, lena
|
||||
|
||||
|
||||
class TestImageHistogram(PillowTestCase):
|
||||
|
||||
def test_histogram(self):
|
||||
|
||||
def histogram(mode):
|
||||
h = lena(mode).histogram()
|
||||
return len(h), min(h), max(h)
|
||||
|
||||
self.assertEqual(histogram("1"), (256, 0, 8872))
|
||||
self.assertEqual(histogram("L"), (256, 0, 199))
|
||||
self.assertEqual(histogram("I"), (256, 0, 199))
|
||||
self.assertEqual(histogram("F"), (256, 0, 199))
|
||||
self.assertEqual(histogram("P"), (256, 0, 2912))
|
||||
self.assertEqual(histogram("RGB"), (768, 0, 285))
|
||||
self.assertEqual(histogram("RGBA"), (1024, 0, 16384))
|
||||
self.assertEqual(histogram("CMYK"), (1024, 0, 16384))
|
||||
self.assertEqual(histogram("YCbCr"), (768, 0, 741))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
28
test/test_imageenhance.py
Normal file
28
test/test_imageenhance.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from tester import unittest, PillowTestCase, lena
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageEnhance
|
||||
|
||||
|
||||
class TestImageEnhance(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
|
||||
# FIXME: assert_image
|
||||
# Implicit asserts no exception:
|
||||
ImageEnhance.Color(lena()).enhance(0.5)
|
||||
ImageEnhance.Contrast(lena()).enhance(0.5)
|
||||
ImageEnhance.Brightness(lena()).enhance(0.5)
|
||||
ImageEnhance.Sharpness(lena()).enhance(0.5)
|
||||
|
||||
def test_crash(self):
|
||||
|
||||
# crashes on small images
|
||||
im = Image.new("RGB", (1, 1))
|
||||
ImageEnhance.Sharpness(im).enhance(0.5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
39
test/test_lib_image.py
Normal file
39
test/test_lib_image.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from tester import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class TestSanity(PillowTestCase):
|
||||
|
||||
def test_setmode(self):
|
||||
|
||||
im = Image.new("L", (1, 1), 255)
|
||||
im.im.setmode("1")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
||||
im.im.setmode("L")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
||||
|
||||
im = Image.new("1", (1, 1), 1)
|
||||
im.im.setmode("L")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
||||
im.im.setmode("1")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
||||
|
||||
im = Image.new("RGB", (1, 1), (1, 2, 3))
|
||||
im.im.setmode("RGB")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3))
|
||||
im.im.setmode("RGBA")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3, 255))
|
||||
im.im.setmode("RGBX")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3, 255))
|
||||
im.im.setmode("RGB")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3))
|
||||
|
||||
self.assertRaises(ValueError, lambda: im.im.setmode("L"))
|
||||
self.assertRaises(ValueError, lambda: im.im.setmode("RGBABCDE"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
|
@ -112,51 +112,6 @@ py3 = (sys.version_info >= (3, 0))
|
|||
# assert_equal(a, b, msg)
|
||||
#
|
||||
#
|
||||
# def assert_greater(a, b, msg=None):
|
||||
# if a > b:
|
||||
# success()
|
||||
# else:
|
||||
# failure(msg or "%r unexpectedly not greater than %r" % (a, b))
|
||||
#
|
||||
#
|
||||
# def assert_greater_equal(a, b, msg=None):
|
||||
# if a >= b:
|
||||
# success()
|
||||
# else:
|
||||
# failure(
|
||||
# msg or "%r unexpectedly not greater than or equal to %r"
|
||||
# % (a, b))
|
||||
#
|
||||
#
|
||||
# def assert_less(a, b, msg=None):
|
||||
# if a < b:
|
||||
# success()
|
||||
# else:
|
||||
# failure(msg or "%r unexpectedly not less than %r" % (a, b))
|
||||
#
|
||||
#
|
||||
# def assert_less_equal(a, b, msg=None):
|
||||
# if a <= b:
|
||||
# success()
|
||||
# else:
|
||||
# failure(
|
||||
# msg or "%r unexpectedly not less than or equal to %r" % (a, b))
|
||||
#
|
||||
#
|
||||
# def assert_is_instance(a, b, msg=None):
|
||||
# if isinstance(a, b):
|
||||
# success()
|
||||
# else:
|
||||
# failure(msg or "got %r, expected %r" % (type(a), b))
|
||||
#
|
||||
#
|
||||
# def assert_in(a, b, msg=None):
|
||||
# if a in b:
|
||||
# success()
|
||||
# else:
|
||||
# failure(msg or "%r unexpectedly not in %r" % (a, b))
|
||||
#
|
||||
#
|
||||
# def assert_match(v, pattern, msg=None):
|
||||
# import re
|
||||
# if re.match(pattern, v):
|
||||
|
@ -165,55 +120,6 @@ py3 = (sys.version_info >= (3, 0))
|
|||
# failure(msg or "got %r, doesn't match pattern %r" % (v, pattern))
|
||||
#
|
||||
#
|
||||
# def assert_exception(exc_class, func):
|
||||
# import sys
|
||||
# import traceback
|
||||
# try:
|
||||
# func()
|
||||
# except exc_class:
|
||||
# success()
|
||||
# except:
|
||||
# failure("expected %r exception, got %r" % (
|
||||
# exc_class.__name__, sys.exc_info()[0].__name__))
|
||||
# traceback.print_exc()
|
||||
# else:
|
||||
# failure(
|
||||
# "expected %r exception, got no exception" % exc_class.__name__)
|
||||
#
|
||||
#
|
||||
# def assert_no_exception(func):
|
||||
# import sys
|
||||
# import traceback
|
||||
# try:
|
||||
# func()
|
||||
# except:
|
||||
# failure("expected no exception, got %r" % sys.exc_info()[0].__name__)
|
||||
# traceback.print_exc()
|
||||
# else:
|
||||
# success()
|
||||
#
|
||||
#
|
||||
# def assert_warning(warn_class, func):
|
||||
# # note: this assert calls func three times!
|
||||
# import warnings
|
||||
#
|
||||
# def warn_error(message, category=UserWarning, **options):
|
||||
# raise category(message)
|
||||
#
|
||||
# def warn_ignore(message, category=UserWarning, **options):
|
||||
# pass
|
||||
# warn = warnings.warn
|
||||
# result = None
|
||||
# try:
|
||||
# warnings.warn = warn_ignore
|
||||
# assert_no_exception(func)
|
||||
# result = func()
|
||||
# warnings.warn = warn_error
|
||||
# assert_exception(warn_class, func)
|
||||
# finally:
|
||||
# warnings.warn = warn # restore
|
||||
# return result
|
||||
#
|
||||
# # helpers
|
||||
#
|
||||
# from io import BytesIO
|
||||
|
|
Loading…
Reference in New Issue
Block a user