/
test_file_palm.py
69 lines (48 loc) · 1.42 KB
/
test_file_palm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os.path
import subprocess
import pytest
from PIL import Image
from .helper import assert_image_equal, hopper, magick_command
def helper_save_as_palm(tmp_path, mode):
# Arrange
im = hopper(mode)
outfile = str(tmp_path / ("temp_" + mode + ".palm"))
# Act
im.save(outfile)
# Assert
assert os.path.isfile(outfile)
assert os.path.getsize(outfile) > 0
def open_with_magick(magick, tmp_path, f):
outfile = str(tmp_path / "temp.png")
rc = subprocess.call(
magick + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
)
if rc:
raise OSError
return Image.open(outfile)
def roundtrip(tmp_path, mode):
magick = magick_command()
if not magick:
return
im = hopper(mode)
outfile = str(tmp_path / "temp.palm")
im.save(outfile)
converted = open_with_magick(magick, tmp_path, outfile)
assert_image_equal(converted, im)
def test_monochrome(tmp_path):
# Arrange
mode = "1"
# Act / Assert
helper_save_as_palm(tmp_path, mode)
roundtrip(tmp_path, mode)
@pytest.mark.xfail(reason="Palm P image is wrong")
def test_p_mode(tmp_path):
# Arrange
mode = "P"
# Act / Assert
helper_save_as_palm(tmp_path, mode)
roundtrip(tmp_path, mode)
@pytest.mark.parametrize("mode", ("L", "RGB"))
def test_oserror(tmp_path, mode):
with pytest.raises(OSError):
helper_save_as_palm(tmp_path, mode)