mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Write in binary format
This commit is contained in:
parent
be8a28d03d
commit
64e5baaaf1
|
@ -240,8 +240,8 @@ def test_header_token_too_long(tmp_path):
|
||||||
def test_truncated_file(tmp_path):
|
def test_truncated_file(tmp_path):
|
||||||
# Test EOF in header
|
# Test EOF in header
|
||||||
path = str(tmp_path / "temp.pgm")
|
path = str(tmp_path / "temp.pgm")
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
with open(path, "wb") as f:
|
||||||
f.write("P6")
|
f.write(b"P6")
|
||||||
|
|
||||||
with pytest.raises(ValueError) as e:
|
with pytest.raises(ValueError) as e:
|
||||||
with Image.open(path):
|
with Image.open(path):
|
||||||
|
@ -256,11 +256,11 @@ def test_truncated_file(tmp_path):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("maxval", (0, 65536))
|
@pytest.mark.parametrize("maxval", (b"0", b"65536"))
|
||||||
def test_invalid_maxval(maxval, tmp_path):
|
def test_invalid_maxval(maxval, tmp_path):
|
||||||
path = str(tmp_path / "temp.ppm")
|
path = str(tmp_path / "temp.ppm")
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
with open(path, "wb") as f:
|
||||||
f.write("P6\n3 1 " + str(maxval))
|
f.write(b"P6\n3 1 " + maxval)
|
||||||
|
|
||||||
with pytest.raises(ValueError) as e:
|
with pytest.raises(ValueError) as e:
|
||||||
with Image.open(path):
|
with Image.open(path):
|
||||||
|
@ -283,13 +283,13 @@ def test_neg_ppm():
|
||||||
def test_mimetypes(tmp_path):
|
def test_mimetypes(tmp_path):
|
||||||
path = str(tmp_path / "temp.pgm")
|
path = str(tmp_path / "temp.pgm")
|
||||||
|
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
with open(path, "wb") as f:
|
||||||
f.write("P4\n128 128\n255")
|
f.write(b"P4\n128 128\n255")
|
||||||
with Image.open(path) as im:
|
with Image.open(path) as im:
|
||||||
assert im.get_format_mimetype() == "image/x-portable-bitmap"
|
assert im.get_format_mimetype() == "image/x-portable-bitmap"
|
||||||
|
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
with open(path, "wb") as f:
|
||||||
f.write("PyCMYK\n128 128\n255")
|
f.write(b"PyCMYK\n128 128\n255")
|
||||||
with Image.open(path) as im:
|
with Image.open(path) as im:
|
||||||
assert im.get_format_mimetype() == "image/x-portable-anymap"
|
assert im.get_format_mimetype() == "image/x-portable-anymap"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user