1
from __future__ import annotations
4
from pathlib import Path
8
from PIL import Image, MspImagePlugin
10
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
12
TEST_FILE = "Tests/images/hopper.msp"
13
EXTRA_DIR = "Tests/images/picins"
14
YA_EXTRA_DIR = "Tests/images/msp"
17
def test_sanity(tmp_path: Path) -> None:
18
test_file = str(tmp_path / "temp.msp")
20
hopper("1").save(test_file)
22
with Image.open(test_file) as im:
25
assert im.size == (128, 128)
26
assert im.format == "MSP"
29
def test_invalid_file() -> None:
30
invalid_file = "Tests/images/flower.jpg"
32
with pytest.raises(SyntaxError):
33
MspImagePlugin.MspImageFile(invalid_file)
36
def test_bad_checksum() -> None:
38
# This was created by forcing Pillow to save with checksum=0
39
bad_checksum = "Tests/images/hopper_bad_checksum.msp"
42
with pytest.raises(SyntaxError):
43
MspImagePlugin.MspImageFile(bad_checksum)
46
def test_open_windows_v1() -> None:
49
with Image.open(TEST_FILE) as im:
51
assert_image_equal(im, hopper("1"))
52
assert isinstance(im, MspImagePlugin.MspImageFile)
55
def _assert_file_image_equal(source_path: str, target_path: str) -> None:
56
with Image.open(source_path) as im:
57
assert_image_equal_tofile(im, target_path)
61
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
63
def test_open_windows_v2() -> None:
65
os.path.join(EXTRA_DIR, f)
66
for f in os.listdir(EXTRA_DIR)
67
if os.path.splitext(f)[1] == ".msp"
70
_assert_file_image_equal(path, path.replace(".msp", ".png"))
74
not os.path.exists(YA_EXTRA_DIR), reason="Even More Extra image files not installed"
76
def test_msp_v2() -> None:
77
for f in os.listdir(YA_EXTRA_DIR):
80
path = os.path.join(YA_EXTRA_DIR, f)
81
_assert_file_image_equal(path, path.replace(".MSP", ".png"))
84
def test_cannot_save_wrong_mode(tmp_path: Path) -> None:
87
filename = str(tmp_path / "temp.msp")
90
with pytest.raises(OSError):