Added test cases to exhibit issues with custom qtables

This commit is contained in:
Stephen Arthur 2016-05-22 17:53:26 -07:00
parent 55c20731d1
commit 7872501c5b

View File

@ -303,6 +303,15 @@ class TestFileJpeg(PillowTestCase):
filename = "Tests/images/junk_jpeg_header.jpg"
Image.open(filename)
def _n_qtables_helper(self, n, test_file):
im = Image.open(test_file)
f = self.tempfile('temp.jpg')
im.save(f, qtables=[[n]*64]*n)
im = Image.open(f)
self.assertEqual(len(im.quantization), n)
reloaded = self.roundtrip(im, qtables="keep")
self.assertEqual(im.quantization, reloaded.quantization)
def test_qtables(self):
im = Image.open("Tests/images/hopper.jpg")
qtables = im.quantization
@ -359,6 +368,15 @@ class TestFileJpeg(PillowTestCase):
1: standard_chrominance_qtable
}), 30)
self._n_qtables_helper(1, "Tests/images/hopper_gray.jpg")
self._n_qtables_helper(1, "Tests/images/pil_sample_rgb.jpg")
self._n_qtables_helper(2, "Tests/images/pil_sample_rgb.jpg")
self._n_qtables_helper(3, "Tests/images/pil_sample_rgb.jpg")
self._n_qtables_helper(1, "Tests/images/pil_sample_cmyk.jpg")
self._n_qtables_helper(2, "Tests/images/pil_sample_cmyk.jpg")
self._n_qtables_helper(3, "Tests/images/pil_sample_cmyk.jpg")
self._n_qtables_helper(4, "Tests/images/pil_sample_cmyk.jpg")
# not a sequence
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables='a'))
# sequence wrong length