Fixed repr on palette box. Closes #151

Had thought that numpy arrays could not be reconstituted through repr,
but that is not the case.
This commit is contained in:
John Evans 2014-02-05 11:35:05 -05:00
commit 4487bb1f42
2 changed files with 11 additions and 6 deletions

View file

@ -1543,9 +1543,10 @@ class PaletteBox(Jp2kBox):
self.offset = offset
def __repr__(self):
msg = "glymur.jp2box.PaletteBox(ndarray, bits_per_component={0}, "
msg += "signed={1})"
msg = msg.format(self.bits_per_component, self.signed)
msg = "glymur.jp2box.PaletteBox({0}, bits_per_component={1}, "
msg += "signed={2})"
msg = msg.format(repr(self.palette), self.bits_per_component,
self.signed)
return msg
def __str__(self):

View file

@ -909,9 +909,13 @@ class TestRepr(unittest.TestCase):
signed = (True, False, True)
box = glymur.jp2box.PaletteBox(palette=palette, bits_per_component=bps,
signed=(True, False, True))
# The palette can't be reinstantiated thru eval/repr.
s = repr(box)
self.assertTrue(True)
# Test will fail unless addition imports from numpy are done.
from numpy import array, int32
newbox = eval(repr(box))
np.testing.assert_array_equal(newbox.palette, palette)
self.assertEqual(newbox.bits_per_component, (8, 8, 16))
self.assertEqual(newbox.signed, (True, False, True))
@unittest.skipIf(sys.hexversion < 0x02070000, "Requires 2.7+")
def test_xml_box(self):