From 18818495d24643806fbd3bd3db3471cc5a1b3ae9 Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 23 Oct 2013 06:41:31 -0400 Subject: [PATCH] Added jp2h __repr__ method. #133 --- glymur/jp2box.py | 8 ++++++-- glymur/test/test_jp2box.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/glymur/jp2box.py b/glymur/jp2box.py index b7f385f..7f75f60 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -1102,11 +1102,15 @@ class JP2HeaderBox(Jp2kBox): box : list List of boxes contained in this superbox. """ - def __init__(self, length=0, offset=-1): + def __init__(self, box=[], length=0, offset=-1): Jp2kBox.__init__(self, box_id='jp2h', longname='JP2 Header') self.length = length self.offset = offset - self.box = [] + self.box = box + + def __repr__(self): + msg = "glymur.jp2box.JP2HeaderBox(box={0})".format(self.box) + return msg def __str__(self): msg = Jp2kBox.__str__(self) diff --git a/glymur/test/test_jp2box.py b/glymur/test/test_jp2box.py index c6de126..fb748f7 100644 --- a/glymur/test/test_jp2box.py +++ b/glymur/test/test_jp2box.py @@ -755,9 +755,20 @@ class TestRepr(unittest.TestCase): self.assertEqual(newbox.channel_type, (COLOR, COLOR, COLOR)) self.assertEqual(newbox.association, (RED, GREEN, BLUE)) - def test_imageheader_box(self): + def test_jp2header_box(self): """Verify __repr__ method on ihdr box.""" ihdr = ImageHeaderBox(100, 200, num_components=3) + colr = ColourSpecificationBox(colorspace=glymur.core.SRGB) + jp2h = JP2HeaderBox(box=[ihdr, colr]) + newbox = eval(repr(jp2h)) + self.assertEqual(newbox.box_id, 'jp2h') + self.assertEqual(newbox.box[0].box_id, 'ihdr') + self.assertEqual(newbox.box[1].box_id, 'colr') + + def test_imageheader_box(self): + """Verify __repr__ method on jhdr box.""" + ihdr = ImageHeaderBox(100, 200, num_components=3) + newbox = eval(repr(ihdr)) self.assertEqual(newbox.height, 100) self.assertEqual(newbox.width, 200)