Pillow/Tests/test_file_palm.py

72 lines
1.5 KiB
Python
Raw Normal View History

2014-07-01 23:18:40 +04:00
import os.path
import pytest
from .helper import (
PillowTestCase,
assert_image_equal,
hopper,
imagemagick_available,
skip_known_bad_test,
)
2014-07-01 23:18:40 +04:00
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
assert os.path.isfile(outfile)
assert os.path.getsize(outfile) > 0
2014-07-01 23:18:40 +04:00
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)
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)
skip_known_bad_test("Palm P image is wrong")
self.roundtrip(mode)
2014-08-28 15:44:19 +04:00
2019-04-15 11:07:15 +03:00
def test_l_ioerror(self):
# Arrange
mode = "L"
# Act / Assert
with pytest.raises(IOError):
self.helper_save_as_palm(mode)
2019-04-15 11:07:15 +03:00
2014-07-01 23:53:30 +04:00
def test_rgb_ioerror(self):
# Arrange
mode = "RGB"
# Act / Assert
with pytest.raises(IOError):
self.helper_save_as_palm(mode)