mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
Added tests
This commit is contained in:
parent
d92b1678fe
commit
257bc8bd4f
|
@ -165,7 +165,7 @@ class _PyAccess8(PyAccess):
|
|||
try:
|
||||
# integer
|
||||
self.pixels[y][x] = min(color, 255)
|
||||
except:
|
||||
except TypeError:
|
||||
# tuple
|
||||
self.pixels[y][x] = min(color[0], 255)
|
||||
|
||||
|
@ -182,7 +182,7 @@ class _PyAccessI16_N(PyAccess):
|
|||
try:
|
||||
# integer
|
||||
self.pixels[y][x] = min(color, 65535)
|
||||
except:
|
||||
except TypeError:
|
||||
# tuple
|
||||
self.pixels[y][x] = min(color[0], 65535)
|
||||
|
||||
|
@ -270,7 +270,7 @@ class _PyAccessF(PyAccess):
|
|||
try:
|
||||
# not a tuple
|
||||
self.pixels[y][x] = color
|
||||
except:
|
||||
except TypeError:
|
||||
# tuple
|
||||
self.pixels[y][x] = color[0]
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, hopper
|
||||
|
||||
from PIL import BufrStubImagePlugin
|
||||
|
||||
|
@ -12,6 +12,12 @@ class TestFileBufrStub(PillowTestCase):
|
|||
lambda:
|
||||
BufrStubImagePlugin.BufrStubImageFile(invalid_file))
|
||||
|
||||
def test_save(self):
|
||||
im = hopper()
|
||||
|
||||
tmpfile = self.tempfile("temp.bufr")
|
||||
self.assertRaises(IOError, lambda: im.save(tmpfile))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
21
Tests/test_file_container.py
Normal file
21
Tests/test_file_container.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ContainerIO
|
||||
|
||||
|
||||
class TestFileContainer(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
dir(Image)
|
||||
dir(ContainerIO)
|
||||
|
||||
def test_isatty(self):
|
||||
im = hopper()
|
||||
container = ContainerIO.ContainerIO(im, 0, 0)
|
||||
|
||||
self.assertEqual(container.isatty(), 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, hopper
|
||||
|
||||
from PIL import Image, EpsImagePlugin
|
||||
import io
|
||||
|
@ -94,6 +94,11 @@ class TestFileEps(PillowTestCase):
|
|||
image1_scale1_compare.load()
|
||||
self.assert_image_similar(img, image1_scale1_compare, 5)
|
||||
|
||||
def test_image_mode_not_supported(self):
|
||||
im = hopper("RGBA")
|
||||
tmpfile = self.tempfile('temp.eps')
|
||||
self.assertRaises(ValueError, lambda: im.save(tmpfile))
|
||||
|
||||
def test_render_scale1(self):
|
||||
# We need png support for these render test
|
||||
codecs = dir(Image.core)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, hopper
|
||||
|
||||
from PIL import GribStubImagePlugin
|
||||
|
||||
|
@ -12,6 +12,12 @@ class TestFileGribStub(PillowTestCase):
|
|||
lambda:
|
||||
GribStubImagePlugin.GribStubImageFile(invalid_file))
|
||||
|
||||
def test_save(self):
|
||||
im = hopper()
|
||||
|
||||
tmpfile = self.tempfile("temp.grib")
|
||||
self.assertRaises(IOError, lambda: im.save(tmpfile))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -29,6 +29,16 @@ class TestFileIptc(PillowTestCase):
|
|||
self.assertEqual(iptc[(2, 90)], b"Budapest")
|
||||
self.assertEqual(iptc[(2, 101)], b"Hungary")
|
||||
|
||||
def test_getiptcinfo_tiff_none(self):
|
||||
# Arrange
|
||||
im = Image.open("Tests/images/hopper.tif")
|
||||
|
||||
# Act
|
||||
iptc = IptcImagePlugin.getiptcinfo(im)
|
||||
|
||||
# Assert
|
||||
self.assertIsNone(iptc)
|
||||
|
||||
def test_i(self):
|
||||
# Arrange
|
||||
c = b"a"
|
||||
|
|
|
@ -19,6 +19,10 @@ class TestFilePcx(PillowTestCase):
|
|||
for mode in ('1', 'L', 'P', 'RGB'):
|
||||
self._roundtrip(hopper(mode))
|
||||
|
||||
# Test an unsupported mode
|
||||
f = self.tempfile("temp.pcx")
|
||||
self.assertRaises(ValueError, lambda: hopper("RGBA").save(f))
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, hopper
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
|
@ -26,6 +26,13 @@ class TestFileWmf(PillowTestCase):
|
|||
imref.load()
|
||||
self.assert_image_similar(im, imref, 2.0)
|
||||
|
||||
def test_save(self):
|
||||
im = hopper()
|
||||
|
||||
for ext in [".wmf", ".emf"]:
|
||||
tmpfile = self.tempfile("temp"+ext)
|
||||
self.assertRaises(IOError, lambda: im.save(tmpfile))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
17
Tests/test_file_xvthumb.py
Normal file
17
Tests/test_file_xvthumb.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import XVThumbImagePlugin
|
||||
|
||||
|
||||
class TestFileXVThumb(PillowTestCase):
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
XVThumbImagePlugin.XVThumbImageFile(invalid_file))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -234,6 +234,9 @@ class TestCffi(AccessTest):
|
|||
# im = Image.new('I;32B', (10, 10), 2**10)
|
||||
# self._test_set_access(im, 2**13-1)
|
||||
|
||||
def test_not_implemented(self):
|
||||
self.assertIsNone(PyAccess.new(hopper("BGR;15")))
|
||||
|
||||
# ref https://github.com/python-pillow/Pillow/pull/2009
|
||||
def test_reference_counting(self):
|
||||
size = 10
|
||||
|
|
|
@ -292,14 +292,24 @@ class TestImageDraw(PillowTestCase):
|
|||
draw = ImageDraw.Draw(im)
|
||||
draw.rectangle(BBOX2, outline="yellow", fill="green")
|
||||
centre_point = (int(W/2), int(H/2))
|
||||
red = ImageColor.getrgb("red")
|
||||
im_floodfill = Image.open("Tests/images/imagedraw_floodfill.png")
|
||||
|
||||
# Act
|
||||
ImageDraw.floodfill(im, centre_point, ImageColor.getrgb("red"))
|
||||
del draw
|
||||
ImageDraw.floodfill(im, centre_point, red)
|
||||
|
||||
# Assert
|
||||
self.assert_image_equal(
|
||||
im, Image.open("Tests/images/imagedraw_floodfill.png"))
|
||||
self.assert_image_equal(im, im_floodfill)
|
||||
|
||||
# Test that using the same colour does not change the image
|
||||
ImageDraw.floodfill(im, centre_point, red)
|
||||
self.assert_image_equal(im, im_floodfill)
|
||||
|
||||
# Test that filling outside the image does not change the image
|
||||
ImageDraw.floodfill(im, (W, H), red)
|
||||
self.assert_image_equal(im, im_floodfill)
|
||||
del draw
|
||||
|
||||
|
||||
@unittest.skipIf(hasattr(sys, 'pypy_version_info'),
|
||||
"Causes fatal RPython error on PyPy")
|
||||
|
|
|
@ -73,10 +73,18 @@ class MorphTests(PillowTestCase):
|
|||
'corner', 'dilation4', 'dilation8',
|
||||
'erosion4', 'erosion8', 'edge'):
|
||||
lb = ImageMorph.LutBuilder(op_name=op)
|
||||
self.assertIsNone(lb.get_lut())
|
||||
|
||||
lut = lb.build_lut()
|
||||
with open('Tests/images/%s.lut' % op, 'rb') as f:
|
||||
self.assertEqual(lut, bytearray(f.read()))
|
||||
|
||||
def test_no_operator_loaded(self):
|
||||
mop = ImageMorph.MorphOp()
|
||||
self.assertRaises(Exception, lambda: mop.apply(None))
|
||||
self.assertRaises(Exception, lambda: mop.match(None))
|
||||
self.assertRaises(Exception, lambda: mop.save_lut(None))
|
||||
|
||||
# Test the named patterns
|
||||
def test_erosion8(self):
|
||||
# erosion8
|
||||
|
|
|
@ -10,6 +10,13 @@ class TestImageShow(PillowTestCase):
|
|||
dir(Image)
|
||||
dir(ImageShow)
|
||||
|
||||
def test_viewer(self):
|
||||
viewer = ImageShow.Viewer()
|
||||
|
||||
self.assertIsNone(viewer.get_format(None))
|
||||
|
||||
self.assertRaises(NotImplementedError, lambda: viewer.get_command(None))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user