Pillow/Tests/test_file_palm.py

59 lines
1.3 KiB
Python
Raw Normal View History

from .helper import unittest, PillowTestCase, hopper, imagemagick_available
2014-07-01 23:18:40 +04:00
import os.path
class TestFilePalm(PillowTestCase):
_roundtrip = imagemagick_available()
2014-08-28 15:44:19 +04:00
2014-07-01 23:53:30 +04:00
def helper_save_as_palm(self, mode):
2014-07-01 23:18:40 +04:00
# Arrange
2014-09-05 13:36:24 +04:00
im = hopper(mode)
2014-07-01 23:53:30 +04:00
outfile = self.tempfile("temp_" + mode + ".palm")
2014-07-01 23:18:40 +04:00
# Act
im.save(outfile)
# Assert
self.assertTrue(os.path.isfile(outfile))
self.assertGreater(os.path.getsize(outfile), 0)
def roundtrip(self, mode):
if not self._roundtrip:
return
2014-08-28 15:44:19 +04:00
2014-09-05 13:36:24 +04:00
im = hopper(mode)
outfile = self.tempfile("temp.palm")
im.save(outfile)
converted = self.open_withImagemagick(outfile)
self.assert_image_equal(converted, im)
2014-07-01 23:53:30 +04:00
def test_monochrome(self):
# Arrange
mode = "1"
# Act / Assert
self.helper_save_as_palm(mode)
self.roundtrip(mode)
2014-07-01 23:53:30 +04:00
def test_p_mode(self):
# Arrange
mode = "P"
# Act / Assert
self.helper_save_as_palm(mode)
2014-07-05 21:56:40 +04:00
self.skipKnownBadTest("Palm P image is wrong")
self.roundtrip(mode)
2014-08-28 15:44:19 +04:00
2014-07-01 23:53:30 +04:00
def test_rgb_ioerror(self):
# Arrange
mode = "RGB"
# Act / Assert
2017-09-01 14:05:40 +03:00
self.assertRaises(IOError, self.helper_save_as_palm, mode)
2014-07-01 23:53:30 +04:00
2014-07-01 23:18:40 +04:00
if __name__ == '__main__':
unittest.main()