From 368c355560127afc0edc8797a838a06614f7695f Mon Sep 17 00:00:00 2001 From: John Evans Date: Sun, 20 Oct 2013 07:52:28 -0400 Subject: [PATCH] Added __repr__ for JPEG2000SignatureBox, FileTypeBox. --- glymur/jp2box.py | 10 ++++++++++ glymur/test/test_jp2box.py | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/glymur/jp2box.py b/glymur/jp2box.py index bf88e4d..c3f2b63 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -801,6 +801,13 @@ class FileTypeBox(Jp2kBox): self.length = length self.offset = offset + def __repr__(self): + msg = "glymur.jp2box.FileTypeBox(brand='{0}', minor_version={1}, " + msg += "compatibility_list={2})" + msg = msg.format(self.brand, self.minor_version, + self.compatibility_list) + return msg + def __str__(self): lst = [Jp2kBox.__str__(self), ' Brand: {0}', @@ -1141,6 +1148,9 @@ class JPEG2000SignatureBox(Jp2kBox): self.length = length self.offset = offset + def __repr__(self): + return 'glymur.jp2box.JPEG2000SignatureBox()' + def __str__(self): msg = Jp2kBox.__str__(self) msg += '\n Signature: {0:02x}{1:02x}{2:02x}{3:02x}' diff --git a/glymur/test/test_jp2box.py b/glymur/test/test_jp2box.py index ef62460..617a93a 100644 --- a/glymur/test/test_jp2box.py +++ b/glymur/test/test_jp2box.py @@ -677,6 +677,10 @@ class TestJp2Boxes(unittest.TestCase): jp2k = glymur.jp2box.JPEG2000SignatureBox() self.assertEqual(jp2k.signature, (13, 10, 135, 10)) + # Test the representation instantiation. + newbox = eval(repr(jp2k)) + self.assertTrue(isinstance(newbox, glymur.jp2box.JPEG2000SignatureBox)) + def test_default_ftyp(self): """Should be able to instantiate a FileTypeBox""" ftyp = glymur.jp2box.FileTypeBox() @@ -684,6 +688,13 @@ class TestJp2Boxes(unittest.TestCase): self.assertEqual(ftyp.minor_version, 0) self.assertEqual(ftyp.compatibility_list, ['jp2 ']) + # Test the representation instantiation. + newbox = eval(repr(ftyp)) + self.assertTrue(isinstance(newbox, glymur.jp2box.FileTypeBox)) + self.assertEqual(newbox.brand, 'jp2 ') + self.assertEqual(newbox.minor_version, 0) + self.assertEqual(newbox.compatibility_list, ['jp2 ']) + def test_default_ihdr(self): """Should be able to instantiate an image header box.""" ihdr = glymur.jp2box.ImageHeaderBox(height=512, width=256,