2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase, lena, imagemagick_available
|
2014-07-01 23:18:40 +04:00
|
|
|
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
class TestFilePalm(PillowTestCase):
|
2014-07-05 21:25:16 +04:00
|
|
|
_roundtrip = imagemagick_available()
|
|
|
|
|
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-07-01 23:53:30 +04:00
|
|
|
im = lena(mode)
|
|
|
|
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)
|
|
|
|
|
2014-07-05 21:25:16 +04:00
|
|
|
def roundtrip(self, mode):
|
|
|
|
if not self._roundtrip:
|
|
|
|
return
|
|
|
|
|
|
|
|
im = lena(mode)
|
|
|
|
outfile = self.tempfile("temp.palm")
|
|
|
|
|
|
|
|
im.save(outfile)
|
2014-08-23 07:49:29 +04:00
|
|
|
try:
|
|
|
|
converted = self.open_withImagemagick(outfile)
|
|
|
|
self.assert_image_equal(converted, im)
|
|
|
|
except IOError:
|
|
|
|
pass
|
2014-07-05 21:25:16 +04:00
|
|
|
|
|
|
|
|
2014-07-01 23:53:30 +04:00
|
|
|
def test_monochrome(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "1"
|
|
|
|
|
|
|
|
# Act / Assert
|
|
|
|
self.helper_save_as_palm(mode)
|
2014-07-05 21:25:16 +04:00
|
|
|
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")
|
2014-07-05 21:25:16 +04:00
|
|
|
self.roundtrip(mode)
|
|
|
|
|
2014-07-01 23:53:30 +04:00
|
|
|
def test_rgb_ioerror(self):
|
|
|
|
# Arrange
|
|
|
|
mode = "RGB"
|
|
|
|
|
|
|
|
# Act / Assert
|
|
|
|
self.assertRaises(IOError, lambda: self.helper_save_as_palm(mode))
|
|
|
|
|
2014-07-01 23:18:40 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|