Pillow
1from __future__ import annotations
2
3import pytest
4
5from PIL.GimpPaletteFile import GimpPaletteFile
6
7
8def test_sanity() -> None:
9with open("Tests/images/test.gpl", "rb") as fp:
10GimpPaletteFile(fp)
11
12with open("Tests/images/hopper.jpg", "rb") as fp:
13with pytest.raises(SyntaxError):
14GimpPaletteFile(fp)
15
16with open("Tests/images/bad_palette_file.gpl", "rb") as fp:
17with pytest.raises(SyntaxError):
18GimpPaletteFile(fp)
19
20with open("Tests/images/bad_palette_entry.gpl", "rb") as fp:
21with pytest.raises(ValueError):
22GimpPaletteFile(fp)
23
24
25def test_get_palette() -> None:
26# Arrange
27with open("Tests/images/custom_gimp_palette.gpl", "rb") as fp:
28palette_file = GimpPaletteFile(fp)
29
30# Act
31palette, mode = palette_file.getpalette()
32
33# Assert
34assert mode == "RGB"
35