More GIMP palette tests

This commit is contained in:
hugovk 2015-07-01 14:28:34 +03:00
parent 6a85d5184c
commit dba0e7960a
4 changed files with 53 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -12,6 +12,23 @@ class TestImage(PillowTestCase):
with open('Tests/images/hopper.jpg', 'rb') as fp: with open('Tests/images/hopper.jpg', 'rb') as fp:
self.assertRaises(SyntaxError, lambda: GimpPaletteFile(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__': if __name__ == '__main__':
unittest.main() unittest.main()