Skip to content

Commit 10c6745

Browse files
authored
Test mode when saving PPM images (#9195)
2 parents 8e3784f + 7d37984 commit 10c6745

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Tests/test_file_ppm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ def test_16bit_pgm() -> None:
9292
assert_image_equal_tofile(im, "Tests/images/16_bit_binary_pgm.tiff")
9393

9494

95+
def test_p4_save(tmp_path: Path) -> None:
96+
with Image.open("Tests/images/hopper_1bit.pbm") as im:
97+
filename = tmp_path / "temp.pbm"
98+
im.save(filename)
99+
assert_image_equal_tofile(im, filename)
100+
101+
95102
def test_16bit_pgm_write(tmp_path: Path) -> None:
96103
with Image.open("Tests/images/16_bit_binary.pgm") as im:
97104
filename = tmp_path / "temp.pgm"
@@ -134,6 +141,12 @@ def test_pfm_big_endian(tmp_path: Path) -> None:
134141
assert_image_equal_tofile(im, filename)
135142

136143

144+
def test_save_unsupported_mode(tmp_path: Path) -> None:
145+
im = hopper("P")
146+
with pytest.raises(OSError, match="cannot write mode P as PPM"):
147+
im.save(tmp_path / "out.ppm")
148+
149+
137150
@pytest.mark.parametrize(
138151
"data",
139152
[

0 commit comments

Comments
 (0)