@@ -240,8 +240,8 @@ def test_header_token_too_long(tmp_path):
240240def 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" ))
260260def 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\n 3 1 " + str ( maxval ) )
262+ with open (path , "wb " ) as f :
263+ f .write (b "P6\n 3 1 " + maxval )
264264
265265 with pytest .raises (ValueError ) as e :
266266 with Image .open (path ):
@@ -283,13 +283,13 @@ def test_neg_ppm():
283283def 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\n 128 128\n 255" )
286+ with open (path , "wb " ) as f :
287+ f .write (b "P4\n 128 128\n 255" )
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\n 128 128\n 255" )
291+ with open (path , "wb " ) as f :
292+ f .write (b "PyCMYK\n 128 128\n 255" )
293293 with Image .open (path ) as im :
294294 assert im .get_format_mimetype () == "image/x-portable-anymap"
295295
0 commit comments