Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently write in binary format in PPM tests #6677

Merged
merged 1 commit into from
Oct 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def test_header_token_too_long(tmp_path):
def test_truncated_file(tmp_path):
# Test EOF in header
path = str(tmp_path / "temp.pgm")
with open(path, "w", encoding="utf-8") as f:
f.write("P6")
with open(path, "wb") as f:
f.write(b"P6")

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


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

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

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

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

Expand Down