Skip to content

Commit eca2f5c

Browse files
authored
Merge pull request #6677 from radarhere/binary
Consistently write in binary format in PPM tests
2 parents be8a28d + 64e5baa commit eca2f5c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Tests/test_file_ppm.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def test_header_token_too_long(tmp_path):
240240
def test_truncated_file(tmp_path):
241241
# Test EOF in header
242242
path = str(tmp_path / "temp.pgm")
243-
with open(path, "w", encoding="utf-8") as f:
244-
f.write("P6")
243+
with open(path, "wb") as f:
244+
f.write(b"P6")
245245

246246
with pytest.raises(ValueError) as e:
247247
with Image.open(path):
@@ -256,11 +256,11 @@ def test_truncated_file(tmp_path):
256256
im.load()
257257

258258

259-
@pytest.mark.parametrize("maxval", (0, 65536))
259+
@pytest.mark.parametrize("maxval", (b"0", b"65536"))
260260
def test_invalid_maxval(maxval, tmp_path):
261261
path = str(tmp_path / "temp.ppm")
262-
with open(path, "w", encoding="utf-8") as f:
263-
f.write("P6\n3 1 " + str(maxval))
262+
with open(path, "wb") as f:
263+
f.write(b"P6\n3 1 " + maxval)
264264

265265
with pytest.raises(ValueError) as e:
266266
with Image.open(path):
@@ -283,13 +283,13 @@ def test_neg_ppm():
283283
def test_mimetypes(tmp_path):
284284
path = str(tmp_path / "temp.pgm")
285285

286-
with open(path, "w", encoding="utf-8") as f:
287-
f.write("P4\n128 128\n255")
286+
with open(path, "wb") as f:
287+
f.write(b"P4\n128 128\n255")
288288
with Image.open(path) as im:
289289
assert im.get_format_mimetype() == "image/x-portable-bitmap"
290290

291-
with open(path, "w", encoding="utf-8") as f:
292-
f.write("PyCMYK\n128 128\n255")
291+
with open(path, "wb") as f:
292+
f.write(b"PyCMYK\n128 128\n255")
293293
with Image.open(path) as im:
294294
assert im.get_format_mimetype() == "image/x-portable-anymap"
295295

0 commit comments

Comments
 (0)