@@ -16,11 +16,11 @@ def test_sanity() -> None:
1616 GimpPaletteFile (fp )
1717
1818 with open ("Tests/images/bad_palette_file.gpl" , "rb" ) as fp :
19- with pytest .raises (SyntaxError ):
19+ with pytest .raises (SyntaxError , match = "bad palette file" ):
2020 GimpPaletteFile (fp )
2121
2222 with open ("Tests/images/bad_palette_entry.gpl" , "rb" ) as fp :
23- with pytest .raises (ValueError ):
23+ with pytest .raises (ValueError , match = "bad palette entry" ):
2424 GimpPaletteFile (fp )
2525
2626
@@ -40,12 +40,26 @@ def test_get_palette(filename: str, size: int) -> None:
4040 assert len (palette ) / 3 == size
4141
4242
43- def test_palette_limit () -> None :
43+ def test_frombytes () -> None :
4444 with open ("Tests/images/full_gimp_palette.gpl" , "rb" ) as fp :
45- data = fp .read ()
45+ full_data = fp .read ()
4646
4747 # Test that __init__ only reads 256 entries
48- data = data .replace (b"#\n " , b"" ) + b" 0 0 0 Index 256"
48+ data = full_data .replace (b"#\n " , b"" ) + b" 0 0 0 Index 256"
4949 b = BytesIO (data )
5050 palette = GimpPaletteFile (b )
5151 assert len (palette .palette ) / 3 == 256
52+
53+ # Test that frombytes() can read beyond that
54+ palette = GimpPaletteFile .frombytes (data )
55+ assert len (palette .palette ) / 3 == 257
56+
57+ # Test that __init__ raises an error if a comment is too long
58+ data = full_data [:- 1 ] + b"a" * 100
59+ b = BytesIO (data )
60+ with pytest .raises (SyntaxError , match = "bad palette file" ):
61+ palette = GimpPaletteFile (b )
62+
63+ # Test that frombytes() can read the data regardless
64+ palette = GimpPaletteFile .frombytes (data )
65+ assert len (palette .palette ) / 3 == 256
0 commit comments