raise RuntimeError if writing with library version is too early, closes #273
We still raise a LibraryNotFoundError if there's no library at all
This commit is contained in:
parent
55acd9260c
commit
f36c169f52
2 changed files with 30 additions and 12 deletions
|
|
@ -415,10 +415,12 @@ class Jp2k(Jp2kBox):
|
||||||
glymur.jp2k.LibraryNotFoundError
|
glymur.jp2k.LibraryNotFoundError
|
||||||
if glymur is unable to load an openjpeg library suitable for writing
|
if glymur is unable to load an openjpeg library suitable for writing
|
||||||
"""
|
"""
|
||||||
|
if re.match("1.[0-4]", version.openjpeg_version) is not None:
|
||||||
|
raise RuntimeError("You must have at least version 1.5 of OpenJPEG "
|
||||||
|
"in order to write images.")
|
||||||
|
|
||||||
if opj2.OPENJP2 is None and opj.OPENJPEG is None:
|
if opj2.OPENJP2 is None and opj.OPENJPEG is None:
|
||||||
raise LibraryNotFoundError("You must have at least version 1.5 of "
|
raise LibraryNotFoundError("Cannot load the OpenJPEG library.")
|
||||||
"OpenJPEG before using this "
|
|
||||||
"functionality.")
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,11 @@ import uuid
|
||||||
import warnings
|
import warnings
|
||||||
from xml.etree import cElementTree as ET
|
from xml.etree import cElementTree as ET
|
||||||
|
|
||||||
|
if sys.hexversion <= 0x03030000:
|
||||||
|
from mock import patch
|
||||||
|
else:
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
|
|
@ -833,6 +838,17 @@ class TestJp2k_write(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_write_with_version_too_early(self):
|
||||||
|
"""Should raise a runtime error if trying to write with version 1.3"""
|
||||||
|
data = np.zeros((128, 128), dtype=np.uint8)
|
||||||
|
versions = ["1.0.0", "1.1.0", "1.2.0", "1.3.0"]
|
||||||
|
for version in versions:
|
||||||
|
with patch('glymur.version.openjpeg_version', new=version):
|
||||||
|
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
j = Jp2k(tfile.name, 'wb')
|
||||||
|
j.write(data)
|
||||||
|
|
||||||
def test_cblkh_different_than_width(self):
|
def test_cblkh_different_than_width(self):
|
||||||
"""Verify that we can set a code block size where height does not equal
|
"""Verify that we can set a code block size where height does not equal
|
||||||
width.
|
width.
|
||||||
|
|
@ -1158,15 +1174,15 @@ class TestJp2k_2_1(unittest.TestCase):
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter('ignore')
|
warnings.simplefilter('ignore')
|
||||||
j = Jp2k(tfile.name)
|
j = Jp2k(tfile.name)
|
||||||
regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
|
regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
|
||||||
Invalid\svalues\sfor\scomp\s=\s0\s+
|
Invalid\svalues\sfor\scomp\s=\s0\s+
|
||||||
:\sdx=1\sdy=0''', re.VERBOSE)
|
:\sdx=1\sdy=0''', re.VERBOSE)
|
||||||
if sys.hexversion < 0x03020000:
|
if sys.hexversion < 0x03020000:
|
||||||
with self.assertRaisesRegexp((IOError, OSError), regexp):
|
with self.assertRaisesRegexp((IOError, OSError), regexp):
|
||||||
j.read(rlevel=1)
|
j.read(rlevel=1)
|
||||||
else:
|
else:
|
||||||
with self.assertRaisesRegex((IOError, OSError), regexp):
|
with self.assertRaisesRegex((IOError, OSError), regexp):
|
||||||
j.read(rlevel=1)
|
j.read(rlevel=1)
|
||||||
|
|
||||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||||
"OPJ_DATA_ROOT environment variable not set")
|
"OPJ_DATA_ROOT environment variable not set")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue