Bad test suite removed. Closes #122
The channel definition test suite looks like it was mistakenly pasted into another part of the file but not correctly skipped when the library version was 1.3.
This commit is contained in:
parent
6ed605b50c
commit
275e0fbd6b
1 changed files with 0 additions and 260 deletions
|
|
@ -56,7 +56,6 @@ def load_tests(loader, tests, ignore):
|
|||
tests.addTests(doctest.DocTestSuite('glymur.jp2box'))
|
||||
return tests
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2 or
|
||||
OPENJP2_IS_V2_OFFICIAL,
|
||||
"Not supported until 2.0+.")
|
||||
|
|
@ -744,264 +743,5 @@ class TestJpxBoxes(unittest.TestCase):
|
|||
self.assertEqual(len(jpx.box[5].box), 0)
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
class TestChannelDefinition(unittest.TestCase):
|
||||
"""Test suite for channel definition boxes."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Need a one_plane plane image for greyscale testing."""
|
||||
j2k = Jp2k(glymur.data.goodstuff())
|
||||
data = j2k.read()
|
||||
# Write the first component back out to file.
|
||||
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
|
||||
grey_j2k = Jp2k(tfile.name, 'wb')
|
||||
grey_j2k.write(data[:, :, 0])
|
||||
cls.one_plane = tfile.name
|
||||
# Write the first two components back out to file.
|
||||
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
|
||||
grey_j2k = Jp2k(tfile.name, 'wb')
|
||||
grey_j2k.write(data[:, :, 0:1])
|
||||
cls.two_planes = tfile.name
|
||||
# Write four components back out to file.
|
||||
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
|
||||
rgba_jp2 = Jp2k(tfile.name, 'wb')
|
||||
shape = (data.shape[0], data.shape[1], 1)
|
||||
alpha = np.zeros((shape), dtype=data.dtype)
|
||||
data4 = np.concatenate((data, alpha), axis=2)
|
||||
rgba_jp2.write(data4)
|
||||
cls.four_planes = tfile.name
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
os.unlink(cls.one_plane)
|
||||
os.unlink(cls.two_planes)
|
||||
os.unlink(cls.four_planes)
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
self.j2kfile = glymur.data.goodstuff()
|
||||
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
codestream = j2k.get_codestream()
|
||||
height = codestream.segment[1].ysiz
|
||||
width = codestream.segment[1].xsiz
|
||||
num_components = len(codestream.segment[1].xrsiz)
|
||||
|
||||
self.jp2b = JPEG2000SignatureBox()
|
||||
self.ftyp = FileTypeBox()
|
||||
self.jp2h = JP2HeaderBox()
|
||||
self.jp2c = ContiguousCodestreamBox()
|
||||
self.ihdr = ImageHeaderBox(height=height, width=width,
|
||||
num_components=num_components)
|
||||
self.colr_rgb = ColourSpecificationBox(colorspace=glymur.core.SRGB)
|
||||
self.colr_gr = ColourSpecificationBox(colorspace=glymur.core.GREYSCALE)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_cdef_no_inputs(self):
|
||||
"""channel_type and association are required inputs."""
|
||||
with self.assertRaises(IOError):
|
||||
glymur.jp2box.ChannelDefinitionBox()
|
||||
|
||||
def test_rgb_with_index(self):
|
||||
"""Just regular RGB."""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
channel_type = [COLOR, COLOR, COLOR]
|
||||
association = [RED, GREEN, BLUE]
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(index=[0, 1, 2],
|
||||
channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_rgb, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
jp2 = Jp2k(tfile.name)
|
||||
jp2h = jp2.box[2]
|
||||
boxes = [box.box_id for box in jp2h.box]
|
||||
self.assertEqual(boxes, ['ihdr', 'colr', 'cdef'])
|
||||
self.assertEqual(jp2h.box[2].index, (0, 1, 2))
|
||||
self.assertEqual(jp2h.box[2].channel_type,
|
||||
(COLOR, COLOR, COLOR))
|
||||
self.assertEqual(jp2h.box[2].association,
|
||||
(RED, GREEN, BLUE))
|
||||
|
||||
def test_rgb(self):
|
||||
"""Just regular RGB, but don't supply the optional index."""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
channel_type = [COLOR, COLOR, COLOR]
|
||||
association = [RED, GREEN, BLUE]
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_rgb, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
jp2 = Jp2k(tfile.name)
|
||||
jp2h = jp2.box[2]
|
||||
boxes = [box.box_id for box in jp2h.box]
|
||||
self.assertEqual(boxes, ['ihdr', 'colr', 'cdef'])
|
||||
self.assertEqual(jp2h.box[2].index, (0, 1, 2))
|
||||
self.assertEqual(jp2h.box[2].channel_type,
|
||||
(COLOR, COLOR, COLOR))
|
||||
self.assertEqual(jp2h.box[2].association,
|
||||
(RED, GREEN, BLUE))
|
||||
|
||||
def test_rgba(self):
|
||||
"""Just regular RGBA."""
|
||||
j2k = Jp2k(self.four_planes)
|
||||
channel_type = (COLOR, COLOR, COLOR, OPACITY)
|
||||
association = (RED, GREEN, BLUE, WHOLE_IMAGE)
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_rgb, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
jp2 = Jp2k(tfile.name)
|
||||
jp2h = jp2.box[2]
|
||||
boxes = [box.box_id for box in jp2h.box]
|
||||
self.assertEqual(boxes, ['ihdr', 'colr', 'cdef'])
|
||||
self.assertEqual(jp2h.box[2].index, (0, 1, 2, 3))
|
||||
self.assertEqual(jp2h.box[2].channel_type, channel_type)
|
||||
self.assertEqual(jp2h.box[2].association, association)
|
||||
|
||||
def test_bad_rgba(self):
|
||||
"""R, G, and B must be specified."""
|
||||
j2k = Jp2k(self.four_planes)
|
||||
channel_type = (COLOR, COLOR, OPACITY, OPACITY)
|
||||
association = (RED, GREEN, BLUE, WHOLE_IMAGE)
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_rgb, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_grey(self):
|
||||
"""Just regular greyscale."""
|
||||
j2k = Jp2k(self.one_plane)
|
||||
channel_type = (COLOR,)
|
||||
association = (GREY,)
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_gr, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
jp2 = Jp2k(tfile.name)
|
||||
jp2h = jp2.box[2]
|
||||
boxes = [box.box_id for box in jp2h.box]
|
||||
self.assertEqual(boxes, ['ihdr', 'colr', 'cdef'])
|
||||
self.assertEqual(jp2h.box[2].index, (0,))
|
||||
self.assertEqual(jp2h.box[2].channel_type, channel_type)
|
||||
self.assertEqual(jp2h.box[2].association, association)
|
||||
|
||||
def test_grey_alpha(self):
|
||||
"""Just regular greyscale plus alpha."""
|
||||
j2k = Jp2k(self.two_planes)
|
||||
channel_type = (COLOR, OPACITY)
|
||||
association = (GREY, WHOLE_IMAGE)
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_gr, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
jp2 = Jp2k(tfile.name)
|
||||
jp2h = jp2.box[2]
|
||||
boxes = [box.box_id for box in jp2h.box]
|
||||
self.assertEqual(boxes, ['ihdr', 'colr', 'cdef'])
|
||||
self.assertEqual(jp2h.box[2].index, (0, 1))
|
||||
self.assertEqual(jp2h.box[2].channel_type, channel_type)
|
||||
self.assertEqual(jp2h.box[2].association, association)
|
||||
|
||||
def test_bad_grey_alpha(self):
|
||||
"""A greyscale image with alpha layer must specify a color channel"""
|
||||
j2k = Jp2k(self.two_planes)
|
||||
|
||||
channel_type = (OPACITY, OPACITY)
|
||||
association = (GREY, WHOLE_IMAGE)
|
||||
|
||||
# This cdef box
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
boxes = [self.ihdr, self.colr_gr, cdef]
|
||||
self.jp2h.box = boxes
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
with self.assertRaises((OSError, IOError)):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_only_one_cdef_in_jp2h(self):
|
||||
"""There can only be one channel definition box in the jp2 header."""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
|
||||
channel_type = (COLOR, COLOR, COLOR)
|
||||
association = (RED, GREEN, BLUE)
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
|
||||
boxes = [self.ihdr, cdef, self.colr_rgb, cdef]
|
||||
self.jp2h.box = boxes
|
||||
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_not_in_jp2h(self):
|
||||
"""need cdef in jp2h"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
boxes = [self.ihdr, self.colr_rgb]
|
||||
self.jp2h.box = boxes
|
||||
|
||||
channel_type = (COLOR, COLOR, COLOR)
|
||||
association = (RED, GREEN, BLUE)
|
||||
cdef = glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, cdef, self.jp2c]
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_bad_type(self):
|
||||
"""Channel types are limited to 0, 1, 2, 65535
|
||||
Should reject if not all of index, channel_type, association the
|
||||
same length.
|
||||
"""
|
||||
channel_type = (COLOR, COLOR, 3)
|
||||
association = (RED, GREEN, BLUE)
|
||||
with self.assertRaises(IOError):
|
||||
glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
|
||||
def test_wrong_lengths(self):
|
||||
"""Should reject if not all of index, channel_type, association the
|
||||
same length.
|
||||
"""
|
||||
channel_type = (COLOR, COLOR)
|
||||
association = (RED, GREEN, BLUE)
|
||||
with self.assertRaises(IOError):
|
||||
glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue