2014-07-01 23:18:40 +04:00
|
|
|
import os.path
|
|
|
|
|
2020-02-22 16:06:21 +03:00
|
|
|
import pytest
|
|
|
|
|
2020-01-30 17:56:07 +03:00
|
|
|
from .helper import (
|
|
|
|
PillowTestCase,
|
|
|
|
assert_image_equal,
|
|
|
|
hopper,
|
|
|
|
imagemagick_available,
|
|
|
|
skip_known_bad_test,
|
|
|
|
)
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2014-07-01 23:18:40 +04:00
|
|
|
|
|
|
|
class TestFilePalm(PillowTestCase):
|
2014-07-05 21:25:16 +04:00
|
|
|
_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
|
2020-02-22 16:06:21 +03:00
|
|
|
assert os.path.isfile(outfile)
|
|
|
|
assert os.path.getsize(outfile) > 0
|
2014-07-01 23:18:40 +04:00
|
|
|
|
2014-07-05 21:25:16 +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)
|
2014-07-05 21:25:16 +04:00
|
|
|
outfile = self.tempfile("temp.palm")
|
|
|
|
|
|
|
|
im.save(outfile)
|
|
|
|
converted = self.open_withImagemagick(outfile)
|
2020-01-30 17:56:07 +03:00
|
|
|
assert_image_equal(converted, im)
|
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)
|
2020-01-30 17:56:07 +03:00
|
|
|
skip_known_bad_test("Palm P image is wrong")
|
2014-07-05 21:25:16 +04:00
|
|
|
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
|
2020-02-22 16:06:21 +03:00
|
|
|
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
|
2020-02-22 16:06:21 +03:00
|
|
|
with pytest.raises(IOError):
|
|
|
|
self.helper_save_as_palm(mode)
|