diff --git a/Tests/images/bad_palette_entry.gpl b/Tests/images/bad_palette_entry.gpl new file mode 100644 index 000000000..162037184 --- /dev/null +++ b/Tests/images/bad_palette_entry.gpl @@ -0,0 +1,12 @@ +GIMP Palette +Name: badpaletteentry +Columns: 4 +# + 0 0 0 Index 3 + 65 38 +103 62 49 Index 6 + 79 73 72 Index 7 +114 101 97 Index 8 +208 127 100 Index 9 +151 144 142 Index 10 +221 207 199 Index 11 diff --git a/Tests/images/bad_palette_file.gpl b/Tests/images/bad_palette_file.gpl new file mode 100644 index 000000000..c366cc8db --- /dev/null +++ b/Tests/images/bad_palette_file.gpl @@ -0,0 +1,12 @@ +GIMP Palette +Name: badpalettefile +Columns: 4 +# + 0 0 0 Index 3 +01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 +103 62 49 Index 6 + 79 73 72 Index 7 +114 101 97 Index 8 +208 127 100 Index 9 +151 144 142 Index 10 +221 207 199 Index 11 diff --git a/Tests/images/custom_gimp_palette.gpl b/Tests/images/custom_gimp_palette.gpl new file mode 100644 index 000000000..08ea70028 --- /dev/null +++ b/Tests/images/custom_gimp_palette.gpl @@ -0,0 +1,12 @@ +GIMP Palette +Name: custompalette +Columns: 4 +# + 0 0 0 Index 3 + 65 38 30 Index 4 +103 62 49 Index 6 + 79 73 72 Index 7 +114 101 97 Index 8 +208 127 100 Index 9 +151 144 142 Index 10 +221 207 199 Index 11 diff --git a/Tests/test_file_gimppalette.py b/Tests/test_file_gimppalette.py index bb18e8026..dfa2845ac 100644 --- a/Tests/test_file_gimppalette.py +++ b/Tests/test_file_gimppalette.py @@ -12,6 +12,23 @@ class TestImage(PillowTestCase): with open('Tests/images/hopper.jpg', 'rb') as fp: self.assertRaises(SyntaxError, lambda: GimpPaletteFile(fp)) + with open('Tests/images/bad_palette_file.gpl', 'rb') as fp: + self.assertRaises(SyntaxError, lambda: GimpPaletteFile(fp)) + + with open('Tests/images/bad_palette_entry.gpl', 'rb') as fp: + self.assertRaises(ValueError, lambda: GimpPaletteFile(fp)) + + def test_get_palette(self): + # Arrange + with open('Tests/images/custom_gimp_palette.gpl', 'rb') as fp: + palette_file = GimpPaletteFile(fp) + + # Act + palette, mode = palette_file.getpalette() + + # Assert + self.assertEqual(mode, "RGB") + if __name__ == '__main__': unittest.main()