Skip to content

Commit 51574bf

Browse files
committed
Parametrize test
1 parent 10ccbd7 commit 51574bf

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

Tests/test_file_bmp.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,19 @@
1515
)
1616

1717

18-
def test_sanity(tmp_path: Path) -> None:
19-
def roundtrip(im: Image.Image) -> None:
20-
outfile = tmp_path / "temp.bmp"
21-
22-
im.save(outfile, "BMP")
23-
24-
with Image.open(outfile) as reloaded:
25-
reloaded.load()
26-
assert im.mode == reloaded.mode
27-
assert im.size == reloaded.size
28-
assert reloaded.format == "BMP"
29-
assert reloaded.get_format_mimetype() == "image/bmp"
18+
@pytest.mark.parametrize("mode", ("1", "L", "P", "RGB"))
19+
def test_sanity(mode: str, tmp_path: Path) -> None:
20+
outfile = tmp_path / "temp.bmp"
3021

31-
roundtrip(hopper())
22+
im = hopper(mode)
23+
im.save(outfile, "BMP")
3224

33-
roundtrip(hopper("1"))
34-
roundtrip(hopper("L"))
35-
roundtrip(hopper("P"))
36-
roundtrip(hopper("RGB"))
25+
with Image.open(outfile) as reloaded:
26+
reloaded.load()
27+
assert im.mode == reloaded.mode
28+
assert im.size == reloaded.size
29+
assert reloaded.format == "BMP"
30+
assert reloaded.get_format_mimetype() == "image/bmp"
3731

3832

3933
def test_invalid_file() -> None:

Tests/test_file_sgi.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,26 @@ def test_invalid_file() -> None:
7171
SgiImagePlugin.SgiImageFile(invalid_file)
7272

7373

74-
def test_write(tmp_path: Path) -> None:
75-
def roundtrip(img: Image.Image) -> None:
76-
out = tmp_path / "temp.sgi"
77-
img.save(out, format="sgi")
74+
def roundtrip(img: Image.Image, tmp_path: Path) -> None:
75+
out = tmp_path / "temp.sgi"
76+
img.save(out, format="sgi")
77+
assert_image_equal_tofile(img, out)
78+
79+
out = tmp_path / "fp.sgi"
80+
with open(out, "wb") as fp:
81+
img.save(fp)
7882
assert_image_equal_tofile(img, out)
7983

80-
out = tmp_path / "fp.sgi"
81-
with open(out, "wb") as fp:
82-
img.save(fp)
83-
assert_image_equal_tofile(img, out)
84+
assert not fp.closed
85+
8486

85-
assert not fp.closed
87+
@pytest.mark.parametrize("mode", ("L", "RGB", "RGBA"))
88+
def test_write(mode: str, tmp_path: Path) -> None:
89+
roundtrip(hopper(mode), tmp_path)
8690

87-
for mode in ("L", "RGB", "RGBA"):
88-
roundtrip(hopper(mode))
8991

90-
# Test 1 dimension for an L mode image
91-
roundtrip(Image.new("L", (10, 1)))
92+
def test_write_L_mode_1_dimension(tmp_path: Path) -> None:
93+
roundtrip(Image.new("L", (10, 1)), tmp_path)
9294

9395

9496
def test_write16(tmp_path: Path) -> None:

0 commit comments

Comments
 (0)