@@ -50,7 +50,7 @@ def test_pnm(tmp_path):
5050 assert_image_equal_tofile (im , f )
5151
5252
53- def test_not_ppm (tmp_path ):
53+ def test_magic (tmp_path ):
5454 path = str (tmp_path / "temp.ppm" )
5555 with open (path , "wb" ) as f :
5656 f .write (b"PyInvalid" )
@@ -69,10 +69,10 @@ def test_header_with_comments(tmp_path):
6969 assert im .size == (128 , 128 )
7070
7171
72- def test_nondecimal_header (tmp_path ):
72+ def test_non_integer_token (tmp_path ):
7373 path = str (tmp_path / "temp.ppm" )
7474 with open (path , "wb" ) as f :
75- f .write (b"P6\n 128 \x00 " )
75+ f .write (b"P6\n TEST " )
7676
7777 with pytest .raises (ValueError ):
7878 with Image .open (path ):
@@ -82,32 +82,38 @@ def test_nondecimal_header(tmp_path):
8282def test_token_too_long (tmp_path ):
8383 path = str (tmp_path / "temp.ppm" )
8484 with open (path , "wb" ) as f :
85- f .write (b"P6\n 0123456789 " )
85+ f .write (b"P6\n 01234567890 " )
8686
87- with pytest .raises (ValueError ):
87+ with pytest .raises (ValueError ) as e :
8888 with Image .open (path ):
8989 pass
9090
91+ assert str (e .value ) == "Token too long in file header: b'01234567890'"
92+
9193
9294def test_too_many_colors (tmp_path ):
9395 path = str (tmp_path / "temp.ppm" )
9496 with open (path , "wb" ) as f :
9597 f .write (b"P6\n 1 1\n 1000\n " )
9698
97- with pytest .raises (ValueError ):
99+ with pytest .raises (ValueError ) as e :
98100 with Image .open (path ):
99101 pass
100102
103+ assert str (e .value ) == "Too many colors for band: 1000"
104+
101105
102106def test_truncated_file (tmp_path ):
103107 path = str (tmp_path / "temp.pgm" )
104108 with open (path , "w" ) as f :
105109 f .write ("P6" )
106110
107- with pytest .raises (ValueError ):
111+ with pytest .raises (ValueError ) as e :
108112 with Image .open (path ):
109113 pass
110114
115+ assert str (e .value ) == "Reached EOF while reading header"
116+
111117
112118def test_neg_ppm ():
113119 # Storage.c accepted negative values for xsize, ysize. the
0 commit comments