Pillow/Tests/test_file_ppm.py

43 lines
1013 B
Python
Raw Normal View History

2014-07-07 21:03:50 +04:00
from helper import unittest, PillowTestCase
from PIL import Image
# sample ppm stream
2014-09-05 13:36:24 +04:00
file = "Tests/images/hopper.ppm"
data = open(file, "rb").read()
2014-06-10 13:10:47 +04:00
class TestFilePpm(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_sanity(self):
im = Image.open(file)
im.load()
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "PPM")
2014-06-10 13:10:47 +04:00
def test_16bit_pgm(self):
im = Image.open('Tests/images/16_bit_binary.pgm')
im.load()
self.assertEqual(im.mode, 'I')
self.assertEqual(im.size, (20, 100))
2014-04-08 09:22:42 +04:00
2014-06-10 13:10:47 +04:00
tgt = Image.open('Tests/images/16_bit_binary_pgm.png')
self.assert_image_equal(im, tgt)
2014-04-08 09:22:42 +04:00
2014-06-10 13:10:47 +04:00
def test_16bit_pgm_write(self):
im = Image.open('Tests/images/16_bit_binary.pgm')
im.load()
2014-04-08 09:22:42 +04:00
2014-06-10 13:10:47 +04:00
f = self.tempfile('temp.pgm')
im.save(f, 'PPM')
2014-04-08 09:22:42 +04:00
2014-06-10 13:10:47 +04:00
reloaded = Image.open(f)
self.assert_image_equal(im, reloaded)
2014-04-08 09:22:42 +04:00
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()
# End of file