merge branch 'issue312' into devel

This commit is contained in:
John Evans 2015-01-04 20:22:49 -05:00
commit c23fe48815
4 changed files with 33 additions and 7 deletions

View file

@ -35,11 +35,12 @@ from .core import (_COLORSPACE_MAP_DISPLAY, _COLOR_TYPE_MAP_DISPLAY,
from . import _uuid_io
_METHOD_DISPLAY = {
ENUMERATED_COLORSPACE: 'enumerated colorspace',
RESTRICTED_ICC_PROFILE: 'restricted ICC profile',
ANY_ICC_PROFILE: 'any ICC profile',
VENDOR_COLOR_METHOD: 'vendor color method'}
_factory = lambda x: '{0} (invalid)'.format(x)
_keysvalues = {ENUMERATED_COLORSPACE: 'enumerated colorspace',
RESTRICTED_ICC_PROFILE: 'restricted ICC profile',
ANY_ICC_PROFILE: 'any ICC profile',
VENDOR_COLOR_METHOD: 'vendor color method'}
_METHOD_DISPLAY = _Keydefaultdict(_factory, _keysvalues)
_factory = lambda x: '{0} (invalid)'.format(x)
_keysvalues = {1: 'accurately represents correct colorspace definition',
@ -1317,7 +1318,13 @@ class FileTypeBox(Jp2kBox):
for j in range(int(num_entries)):
entry, = struct.unpack_from('>4s', read_buffer, 8 + j * 4)
if sys.hexversion >= 0x03000000:
entry = entry.decode('utf-8')
try:
entry = entry.decode('utf-8')
except UnicodeDecodeError as err:
# The entry is invalid, but we've got code to catch this
# later on.
pass
compatibility_list.append(entry)
return cls(brand=brand, minor_version=minor_version,

View file

@ -272,6 +272,15 @@ class TestJp2k(unittest.TestCase):
jp2 = Jp2k(jfile)
self.assertEqual(jp2.shape, (128, 128))
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_invalid_compatibility_list_entry(self):
"""should not error out with invalid compatibility list entry"""
filename = opj_data_file('input/nonregression/issue397.jp2')
with self.assertWarns(UserWarning):
Jp2k(filename)
self.assertTrue(True)
def test_shape_j2k(self):
"""verify shape attribute for J2K file
"""

View file

@ -3,7 +3,6 @@ The tests defined here roughly correspond to what is in the OpenJPEG test
suite.
"""
import re
import sys
import unittest
import numpy as np

View file

@ -831,6 +831,17 @@ class TestPrintingOpjDataRootWarns(unittest.TestCase):
def tearDown(self):
pass
def test_invalid_colour_specification_method(self):
"""should not error out with invalid colour specification method"""
# Don't care so much about what the output looks like, just that we
# do not error out.
filename = opj_data_file('input/nonregression/issue397.jp2')
with self.assertWarns(UserWarning):
jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()):
print(jp2)
self.assertTrue(True)
def test_invalid_colorspace(self):
"""An invalid colorspace shouldn't cause an error."""
filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2')