From c56b919c36b0a7312dc9ea2c10617984549c0457 Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 12 Mar 2014 12:27:52 -0400 Subject: [PATCH] Fixed printing of cmap boxes when not pclr. #182 --- glymur/jp2box.py | 2 +- glymur/test/fixtures.py | 5 +++++ glymur/test/test_printing.py | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/glymur/jp2box.py b/glymur/jp2box.py index 6db6c87..a106ee4 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -829,7 +829,7 @@ class ComponentMappingBox(Jp2kBox): msg = msg.format(self.component_index[k], self.palette_index[k]) else: - msg += '\n Component %d ==> %d' + msg += '\n Component {0} ==> {1}' msg = msg.format(self.component_index[k], k) return msg diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 2004d2b..63f5837 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -577,3 +577,8 @@ file1_xml = """XML Box (xml ) @ (36, 439) \t\tProfessional 120 Image \t """ + +issue_182_cmap = """Component Mapping Box (cmap) @ (130, 24) + Component 0 ==> palette column 0 + Component 1 ==> palette column 0 + Component 2 ==> 2""" diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 0deaebd..3dd58f5 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -905,6 +905,22 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) + def test_issue182(self): + """Should not show the format string in output.""" + # The cmap box is wildly broken, but printing was still wrong. + # Format strings like %d were showing up in the output. + filename = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2') + + with warnings.catch_warnings(): + # Ignore warning about bad pclr box. + warnings.simplefilter("ignore") + jp2 = Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + print(jp2.box[3].box[3]) + actual = fake_out.getvalue().strip() + self.assertEqual(actual, fixtures.issue_182_cmap) + + @unittest.skipIf(sys.hexversion < 0x03000000, "Ordered dicts not printing well in 2.7") def test_exif_uuid(self):