1
from __future__ import annotations
8
from .helper import assert_image_similar
10
base = os.path.join("Tests", "images", "bmp")
13
def get_files(d: str, ext: str = ".bmp") -> list[str]:
15
os.path.join(base, d, f) for f in os.listdir(os.path.join(base, d)) if ext in f
19
def test_bad() -> None:
20
"""These shouldn't crash/dos, but they shouldn't return anything
22
for f in get_files("b"):
23
# Assert that there is no unclosed file warning
24
with warnings.catch_warnings():
26
with Image.open(f) as im:
28
except Exception: # as msg:
32
def test_questionable() -> None:
33
"""These shouldn't crash/dos, but it's not well defined that these
51
for f in get_files("q"):
53
with Image.open(f) as im:
55
if os.path.basename(f) not in supported:
56
print(f"Please add {f} to the partially supported bmp specs.")
57
except Exception: # as msg:
58
if os.path.basename(f) in supported:
62
def test_good() -> None:
63
"""These should all work. There's a set of target files in the
64
html directory that we can compare against."""
66
# Target files, if they're not just replacing the extension
68
"pal1wb.bmp": "pal1.png",
69
"pal4rle.bmp": "pal4.png",
70
"pal8-0.bmp": "pal8.png",
71
"pal8rle.bmp": "pal8.png",
72
"pal8topdown.bmp": "pal8.png",
73
"pal8nonsquare.bmp": "pal8nonsquare-v.png",
74
"pal8os2.bmp": "pal8.png",
75
"pal8os2sp.bmp": "pal8.png",
76
"pal8os2v2.bmp": "pal8.png",
77
"pal8os2v2-16.bmp": "pal8.png",
78
"pal8v4.bmp": "pal8.png",
79
"pal8v5.bmp": "pal8.png",
80
"rgb16-565pal.bmp": "rgb16-565.png",
81
"rgb24pal.bmp": "rgb24.png",
82
"rgb32.bmp": "rgb24.png",
83
"rgb32bf.bmp": "rgb24.png",
86
def get_compare(f: str) -> str:
87
name = os.path.split(f)[1]
89
return os.path.join(base, "html", file_map[name])
90
name = os.path.splitext(name)[0]
91
return os.path.join(base, "html", f"{name}.png")
93
for f in get_files("g"):
95
with Image.open(f) as im:
97
with Image.open(get_compare(f)) as compare:
100
# assert image similar doesn't really work
101
# with paletized image, since the palette might
102
# be differently ordered for an equivalent image.
103
im = im.convert("RGBA")
104
compare = im.convert("RGBA")
105
assert_image_similar(im, compare, 5)
107
except Exception as msg:
108
# there are three here that are unsupported:
110
os.path.join(base, "g", "rgb32bf.bmp"),
111
os.path.join(base, "g", "pal8rle.bmp"),
112
os.path.join(base, "g", "pal4rle.bmp"),
114
assert f in unsupported, f"Unsupported Image {f}: {msg}"