LibraryNotFoundError isn't needed because we already error out during the import of glymur if neither openjpeg nor openjp2 can be found. When read_bands is used and the library version is not at least 2.0.0, use RuntimeError instead of LibraryNotFoundError.
This commit is contained in:
parent
dba289677d
commit
5de1b8b240
3 changed files with 8 additions and 61 deletions
|
|
@ -406,19 +406,11 @@ class Jp2k(Jp2kBox):
|
||||||
>>> tfile = NamedTemporaryFile(suffix='.jp2', delete=False)
|
>>> tfile = NamedTemporaryFile(suffix='.jp2', delete=False)
|
||||||
>>> j = Jp2k(tfile.name, mode='wb')
|
>>> j = Jp2k(tfile.name, mode='wb')
|
||||||
>>> j.write(data.astype(np.uint8))
|
>>> j.write(data.astype(np.uint8))
|
||||||
|
|
||||||
Raises
|
|
||||||
------
|
|
||||||
glymur.jp2k.LibraryNotFoundError
|
|
||||||
if glymur is unable to load an openjpeg library suitable for writing
|
|
||||||
"""
|
"""
|
||||||
if re.match("1.[0-4]", version.openjpeg_version) is not None:
|
if re.match("1.[0-4]", version.openjpeg_version) is not None:
|
||||||
raise RuntimeError("You must have at least version 1.5 of OpenJPEG "
|
raise RuntimeError("You must have at least version 1.5 of OpenJPEG "
|
||||||
"in order to write images.")
|
"in order to write images.")
|
||||||
|
|
||||||
if opj2.OPENJP2 is None and opj.OPENJPEG is None:
|
|
||||||
raise LibraryNotFoundError("Cannot load the OpenJPEG library.")
|
|
||||||
|
|
||||||
self._determine_colorspace(img_array, **kwargs)
|
self._determine_colorspace(img_array, **kwargs)
|
||||||
cparams = self._populate_cparams(img_array, **kwargs)
|
cparams = self._populate_cparams(img_array, **kwargs)
|
||||||
|
|
||||||
|
|
@ -962,8 +954,6 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
------
|
------
|
||||||
glymur.jp2k.LibraryNotFoundError
|
|
||||||
if glymur is unable to load an openjpeg library suitable for reading
|
|
||||||
IOError
|
IOError
|
||||||
If the image has differing subsample factors.
|
If the image has differing subsample factors.
|
||||||
|
|
||||||
|
|
@ -982,9 +972,6 @@ class Jp2k(Jp2kBox):
|
||||||
>>> thumbnail.shape
|
>>> thumbnail.shape
|
||||||
(728, 1296, 3)
|
(728, 1296, 3)
|
||||||
"""
|
"""
|
||||||
if opj2.OPENJP2 is None and opj.OPENJPEG is None:
|
|
||||||
raise LibraryNotFoundError("Cannot load the OpenJPEG library.")
|
|
||||||
|
|
||||||
if opj2.OPENJP2 is not None:
|
if opj2.OPENJP2 is not None:
|
||||||
img = self._read_openjp2(**kwargs)
|
img = self._read_openjp2(**kwargs)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1275,16 +1262,11 @@ class Jp2k(Jp2kBox):
|
||||||
>>> jfile = glymur.data.nemo()
|
>>> jfile = glymur.data.nemo()
|
||||||
>>> jp = glymur.Jp2k(jfile)
|
>>> jp = glymur.Jp2k(jfile)
|
||||||
>>> components_lst = jp.read_bands(rlevel=1)
|
>>> components_lst = jp.read_bands(rlevel=1)
|
||||||
|
|
||||||
Raises
|
|
||||||
------
|
|
||||||
glymur.jp2k.LibraryNotFoundError
|
|
||||||
if glymur is unable to load an openjpeg library suitable for reading
|
|
||||||
"""
|
"""
|
||||||
if version.openjpeg_version_tuple[0] < 2:
|
if version.openjpeg_version_tuple[0] < 2:
|
||||||
raise LibraryNotFoundError("You must have at least version 2.0.0 "
|
raise RuntimeError("You must have at least version 2.0.0 of "
|
||||||
"of OpenJPEG installed before using "
|
"OpenJPEG installed before using this "
|
||||||
"this functionality.")
|
"functionality.")
|
||||||
|
|
||||||
dparam = self._populate_dparam(rlevel, ignore_pclr_cmap_cdef,
|
dparam = self._populate_dparam(rlevel, ignore_pclr_cmap_cdef,
|
||||||
layer=layer, tile=tile, area=area)
|
layer=layer, tile=tile, area=area)
|
||||||
|
|
@ -1835,10 +1817,3 @@ def _default_warning_handler(library_msg, _):
|
||||||
_ERROR_CALLBACK = _CMPFUNC(_default_error_handler)
|
_ERROR_CALLBACK = _CMPFUNC(_default_error_handler)
|
||||||
_INFO_CALLBACK = _CMPFUNC(_default_info_handler)
|
_INFO_CALLBACK = _CMPFUNC(_default_info_handler)
|
||||||
_WARNING_CALLBACK = _CMPFUNC(_default_warning_handler)
|
_WARNING_CALLBACK = _CMPFUNC(_default_warning_handler)
|
||||||
|
|
||||||
|
|
||||||
class LibraryNotFoundError(IOError):
|
|
||||||
"""Raised if functionality is requested without the necessary library.
|
|
||||||
"""
|
|
||||||
def __init__(self, msg):
|
|
||||||
IOError.__init__(self, msg)
|
|
||||||
|
|
|
||||||
|
|
@ -108,36 +108,3 @@ class TestConfig(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_read_without_library(self):
|
|
||||||
"""Don't have either openjp2 or openjpeg libraries? Must error out.
|
|
||||||
"""
|
|
||||||
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
|
||||||
with patch('glymur.lib.openjpeg.OPENJPEG', new=None):
|
|
||||||
with self.assertRaises(glymur.jp2k.LibraryNotFoundError):
|
|
||||||
glymur.Jp2k(self.jp2file).read()
|
|
||||||
|
|
||||||
def test_read_bands_without_library(self):
|
|
||||||
"""Don't have openjp2 library? Must error out.
|
|
||||||
"""
|
|
||||||
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
|
||||||
with patch('glymur.lib.openjpeg.OPENJPEG', new=None):
|
|
||||||
with patch('glymur.version.openjpeg_version_tuple',
|
|
||||||
new=(0, 0, 0)):
|
|
||||||
with self.assertRaises(glymur.jp2k.LibraryNotFoundError):
|
|
||||||
glymur.Jp2k(self.jp2file).read_bands()
|
|
||||||
|
|
||||||
@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG)
|
|
||||||
def test_write_without_library(self):
|
|
||||||
"""Don't have openjpeg libraries? Must error out.
|
|
||||||
"""
|
|
||||||
data = glymur.Jp2k(self.j2kfile).read()
|
|
||||||
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
|
||||||
with patch('glymur.lib.openjpeg.OPENJPEG', new=None):
|
|
||||||
with self.assertRaises(glymur.jp2k.LibraryNotFoundError):
|
|
||||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
|
||||||
ofile = Jp2k(tfile.name, 'wb')
|
|
||||||
ofile.write(data)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
|
|
|
||||||
|
|
@ -824,6 +824,11 @@ class TestJp2k(unittest.TestCase):
|
||||||
data = jpx.read()
|
data = jpx.read()
|
||||||
self.assertEqual(data.shape, (1024, 1024, 3))
|
self.assertEqual(data.shape, (1024, 1024, 3))
|
||||||
|
|
||||||
|
def test_read_bands_without_openjp2(self):
|
||||||
|
"""Don't have openjp2 library? Must error out."""
|
||||||
|
with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
glymur.Jp2k(self.jp2file).read_bands()
|
||||||
|
|
||||||
@unittest.skipIf(re.match('1.[0-4]', openjpeg_version) is not None,
|
@unittest.skipIf(re.match('1.[0-4]', openjpeg_version) is not None,
|
||||||
"Not supported with OpenJPEG {0}".format(openjpeg_version))
|
"Not supported with OpenJPEG {0}".format(openjpeg_version))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue