From 9799762fb5ae56a63659ce5a62ed6524cb72c385 Mon Sep 17 00:00:00 2001 From: John Evans Date: Thu, 24 Oct 2013 08:48:14 -0400 Subject: [PATCH] Added repr support for Jp2k class. #133 --- glymur/jp2k.py | 4 ++++ glymur/test/test_jp2k.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 1bd36a4..a9927da 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -72,6 +72,10 @@ class Jp2k(Jp2kBox): if mode == 'rb': self.parse() + def __repr__(self): + msg = "glymur.Jp2k('{0}')".format(self.filename) + return msg + def __str__(self): metadata = ['File: ' + os.path.basename(self.filename)] if len(self.box) > 0: diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 636ea9a..15da73d 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -67,6 +67,15 @@ class TestJp2k(unittest.TestCase): def tearDown(self): pass + def test_repr(self): + """Verify that results of __repr__ are eval-able.""" + j = Jp2k(self.j2kfile) + newjp2 = eval(repr(j)) + + self.assertEqual(newjp2.filename, self.j2kfile) + self.assertEqual(newjp2.mode, 'rb') + self.assertEqual(len(newjp2.box), 0) + def test_rlevel_max(self): """Verify that rlevel=-1 gets us the lowest resolution image""" j = Jp2k(self.j2kfile)