From 7872501c5b3a5c64e84efad6d8128a9a5c11f3b7 Mon Sep 17 00:00:00 2001 From: Stephen Arthur Date: Sun, 22 May 2016 17:53:26 -0700 Subject: [PATCH] Added test cases to exhibit issues with custom qtables --- Tests/test_file_jpeg.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 3b2e6cb20..dba16d346 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -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