Pillow/Tests/test_image_putpixel.py

51 lines
1.1 KiB
Python
Raw Normal View History

2014-07-07 21:03:50 +04:00
from helper import unittest, PillowTestCase, lena
from PIL import Image
2014-06-10 13:10:47 +04:00
Image.USE_CFFI_ACCESS = False
2014-01-06 09:36:13 +04:00
2014-06-10 13:10:47 +04:00
class TestImagePutPixel(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_sanity(self):
2014-06-10 13:10:47 +04:00
im1 = lena()
im2 = Image.new(im1.mode, im1.size, 0)
2014-06-10 13:10:47 +04:00
for y in range(im1.size[1]):
for x in range(im1.size[0]):
pos = x, y
im2.putpixel(pos, im1.getpixel(pos))
2014-06-10 13:10:47 +04:00
self.assert_image_equal(im1, im2)
2014-06-10 13:10:47 +04:00
im2 = Image.new(im1.mode, im1.size, 0)
im2.readonly = 1
2014-06-10 13:10:47 +04:00
for y in range(im1.size[1]):
for x in range(im1.size[0]):
pos = x, y
im2.putpixel(pos, im1.getpixel(pos))
2014-06-10 13:10:47 +04:00
self.assertFalse(im2.readonly)
self.assert_image_equal(im1, im2)
2014-06-10 13:10:47 +04:00
im2 = Image.new(im1.mode, im1.size, 0)
2014-06-10 13:10:47 +04:00
pix1 = im1.load()
pix2 = im2.load()
2014-06-10 13:10:47 +04:00
for y in range(im1.size[1]):
for x in range(im1.size[0]):
pix2[x, y] = pix1[x, y]
2014-06-10 13:10:47 +04:00
self.assert_image_equal(im1, im2)
2014-06-10 13:10:47 +04:00
# see test_image_getpixel for more tests
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()
# End of file