Compare commits

...
Sign in to create a new pull request.

6 commits

Author SHA1 Message Date
John Evans
982e70be79 filtered out tests that should not run on linux where no openjpeg 2014-11-18 11:32:55 -05:00
John Evans
d03870cc72 filtered out tests that should not run if openjpeg not installed 2014-11-18 07:26:21 -05:00
John Evans
d45d74ff5d add test fixture for determining if openjpeg is installed 2014-11-18 07:07:14 -05:00
jevans
f1ce5520ff merge branch 'issue300' of https://github.com/quintusdias/glymur into issue300 2014-11-17 22:10:53 -05:00
jevans
3fa3072041 warn instead of raising IOError if openjpeg library cannot be found, issue#300
Improve error message when trying to read without openjpeg library.
2014-11-17 22:09:39 -05:00
jevans
29dfce7927 warn instead of raising IOError if openjpeg library cannot be found
Improve error message when trying to read without openjpeg library.
2014-11-17 21:07:36 -05:00
8 changed files with 47 additions and 11 deletions

View file

@ -937,10 +937,8 @@ class Jp2k(Jp2kBox):
elif opj.OPENJPEG is not None: elif opj.OPENJPEG is not None:
img = self._read_openjpeg(**kwargs) img = self._read_openjpeg(**kwargs)
else: else:
raise LibraryNotFoundError("You must have either a recent version " raise LibraryNotFoundError("You must have OpenJPEG installed "
"of OpenJPEG or the development " "before reading a JPEG2000 image.")
"version of OpenJP2 installed before "
"using this functionality.")
return img return img
def _subsampling_sanity_check(self): def _subsampling_sanity_check(self):
@ -1235,8 +1233,8 @@ class Jp2k(Jp2kBox):
""" """
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 LibraryNotFoundError("You must have at least version 2.0.0 "
"of OpenJP2 installed before using " "of OpenJPEG installed before using "
"this functionality.") "read_bands.")
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)

View file

@ -146,7 +146,7 @@ def glymur_config():
libopenjpeg_handle = load_openjpeg(libs['openjpeg']) libopenjpeg_handle = load_openjpeg(libs['openjpeg'])
if libopenjp2_handle is None and libopenjpeg_handle is None: if libopenjp2_handle is None and libopenjpeg_handle is None:
msg = "Neither the openjp2 nor the openjpeg library could be loaded. " msg = "Neither the openjp2 nor the openjpeg library could be loaded. "
raise IOError(msg) warnings.warn(msg, UserWarning)
return libopenjp2_handle, libopenjpeg_handle return libopenjp2_handle, libopenjpeg_handle

View file

@ -13,6 +13,15 @@ import six
import glymur import glymur
# If openjpeg is not installed, many tests cannot be run.
if glymur.version.openjpeg_version == "0.0.0":
OPENJPEG_NOT_AVAILABLE = True
OPENJPEG_NOT_AVAILABLE_MSG = "OpenJPEG library not installed"
else:
OPENJPEG_NOT_AVAILABLE = False
OPENJPEG_NOT_AVAILABLE_MSG = None
# Some versions of "six" on python3 cause problems when verifying warnings. # Some versions of "six" on python3 cause problems when verifying warnings.
# Only use when the version is 1.7 or higher. # Only use when the version is 1.7 or higher.
# And moreover, we only test using the 3.x infrastructure, never on 2.x. # And moreover, we only test using the 3.x infrastructure, never on 2.x.

View file

@ -34,6 +34,7 @@ from glymur.jp2box import FileTypeBox, ImageHeaderBox, JP2HeaderBox
from glymur.jp2box import JPEG2000SignatureBox from glymur.jp2box import JPEG2000SignatureBox
from glymur.core import COLOR, OPACITY from glymur.core import COLOR, OPACITY
from glymur.core import RED, GREEN, BLUE, GREY, WHOLE_IMAGE from glymur.core import RED, GREEN, BLUE, GREY, WHOLE_IMAGE
from glymur.version import openjpeg_version
from .fixtures import ( from .fixtures import (
WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG, WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG,
@ -54,6 +55,8 @@ def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite('glymur.jp2box')) tests.addTests(doctest.DocTestSuite('glymur.jp2box'))
return tests return tests
@unittest.skipIf(re.match('0|1.[0-2]', openjpeg_version) is not None,
"Not supported with OpenJPEG {0}".format(openjpeg_version))
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
class TestDataEntryURL(unittest.TestCase): class TestDataEntryURL(unittest.TestCase):
"""Test suite for DataEntryURL boxes.""" """Test suite for DataEntryURL boxes."""
@ -119,7 +122,7 @@ class TestDataEntryURL(unittest.TestCase):
self.assertEqual(url + chr(0), read_url) self.assertEqual(url + chr(0), read_url)
@unittest.skipIf(re.match(r'''(1|2.0.0)''', @unittest.skipIf(re.match(r'''0|1|2.0.0''',
glymur.version.openjpeg_version) is not None, glymur.version.openjpeg_version) is not None,
"Not supported until 2.1") "Not supported until 2.1")
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")

View file

@ -54,6 +54,8 @@ def load_tests(loader, tests, ignore):
return tests return tests
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
class SliceProtocolBase(unittest.TestCase): class SliceProtocolBase(unittest.TestCase):
""" """
Test slice protocol, i.e. when using [ ] to read image data. Test slice protocol, i.e. when using [ ] to read image data.
@ -309,6 +311,8 @@ class TestSliceProtocolRead(SliceProtocolBase):
expected = self.j2k.read(area=(5, 27, 533, 423), rlevel=5) expected = self.j2k.read(area=(5, 27, 533, 423), rlevel=5)
np.testing.assert_array_equal(actual, expected) np.testing.assert_array_equal(actual, expected)
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@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")
class TestSliceProtocolOpjData(unittest.TestCase): class TestSliceProtocolOpjData(unittest.TestCase):
@ -460,6 +464,8 @@ class TestSliceProtocolOpjData(unittest.TestCase):
expected = self.j2k_quarter_data[5:13, 38:50] expected = self.j2k_quarter_data[5:13, 38:50]
np.testing.assert_array_equal(actual, expected) np.testing.assert_array_equal(actual, expected)
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
class TestJp2k(unittest.TestCase): class TestJp2k(unittest.TestCase):
"""These tests should be run by just about all configuration.""" """These tests should be run by just about all configuration."""
@ -488,7 +494,7 @@ class TestJp2k(unittest.TestCase):
actdata = j2.read() actdata = j2.read()
self.assertTrue(fixtures.mse(actdata[0], expdata[0]) < 0.38) self.assertTrue(fixtures.mse(actdata[0], expdata[0]) < 0.38)
@unittest.skipIf(re.match('1.[0-4]', openjpeg_version) is not None, @unittest.skipIf(re.match('0|1.[0-4]', openjpeg_version) is not None,
"Not supported with OpenJPEG {0}".format(openjpeg_version)) "Not supported with OpenJPEG {0}".format(openjpeg_version))
@unittest.skipIf(re.match('1.5.(1|2)', openjpeg_version) is not None, @unittest.skipIf(re.match('1.5.(1|2)', openjpeg_version) is not None,
"Mysteriously fails in 1.5.1 and 1.5.2") "Mysteriously fails in 1.5.1 and 1.5.2")
@ -820,7 +826,7 @@ class TestJp2k(unittest.TestCase):
self.assertEqual(data.shape, (1024, 1024, 3)) self.assertEqual(data.shape, (1024, 1024, 3))
@unittest.skipIf(re.match('1.[0-4]', openjpeg_version) is not None, @unittest.skipIf(re.match('0|1.[0-4]', openjpeg_version) is not None,
"Not supported with OpenJPEG {0}".format(openjpeg_version)) "Not supported with OpenJPEG {0}".format(openjpeg_version))
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
class TestJp2k_write(unittest.TestCase): class TestJp2k_write(unittest.TestCase):
@ -966,6 +972,8 @@ class TestJp2k_write(unittest.TestCase):
self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL) self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL)
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] >= 2, @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] >= 2,
"Negative tests only for version 1.x") "Negative tests only for version 1.x")
class TestJp2k_1_x(unittest.TestCase): class TestJp2k_1_x(unittest.TestCase):
@ -1092,7 +1100,7 @@ class TestJp2k_2_0(unittest.TestCase):
self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ') self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ')
@unittest.skipIf(re.match(r'''(1|2.0.0)''', @unittest.skipIf(re.match(r'''0|1|2.0.0''',
glymur.version.openjpeg_version) is not None, glymur.version.openjpeg_version) is not None,
"Not to be run until unless 2.0.1 or higher is present") "Not to be run until unless 2.0.1 or higher is present")
class TestJp2k_2_1(unittest.TestCase): class TestJp2k_2_1(unittest.TestCase):
@ -1290,6 +1298,8 @@ class TestJp2kOpjDataRoot(unittest.TestCase):
rgb_from_idx[r, c] = palette[idx[r, c]] rgb_from_idx[r, c] = palette[idx[r, c]]
np.testing.assert_array_equal(rgb, rgb_from_idx) np.testing.assert_array_equal(rgb, rgb_from_idx)
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
def test_read_differing_subsamples(self): def test_read_differing_subsamples(self):
"""should error out with read used on differently subsampled images""" """should error out with read used on differently subsampled images"""
# Verify that we error out appropriately if we use the read method # Verify that we error out appropriately if we use the read method

View file

@ -37,6 +37,7 @@ import glymur
from glymur import Jp2k from glymur import Jp2k
from glymur.jp2box import FileTypeBox, ImageHeaderBox, ColourSpecificationBox from glymur.jp2box import FileTypeBox, ImageHeaderBox, ColourSpecificationBox
from . import fixtures
from .fixtures import ( from .fixtures import (
OPJ_DATA_ROOT, MetadataBase, OPJ_DATA_ROOT, MetadataBase,
WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG, WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG,
@ -44,6 +45,8 @@ from .fixtures import (
) )
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@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")
class TestSuite(unittest.TestCase): class TestSuite(unittest.TestCase):
@ -479,6 +482,8 @@ class TestSuiteWarns(MetadataBase):
self.assertTrue(True) self.assertTrue(True)
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@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")
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
@ -574,6 +579,8 @@ class TestSuiteBands(unittest.TestCase):
self.assertTrue(True) self.assertTrue(True)
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@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")
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,

View file

@ -36,11 +36,14 @@ import numpy as np
from glymur import Jp2k from glymur import Jp2k
import glymur import glymur
from . import fixtures
from .fixtures import OPJ_DATA_ROOT from .fixtures import OPJ_DATA_ROOT
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@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")
@unittest.skipIf(re.match(r'''(1|2.0.0)''', @unittest.skipIf(re.match(r'''(1|2.0.0)''',
@ -163,6 +166,8 @@ class TestSuite2point1(unittest.TestCase):
with self.assertRaises(IOError): with self.assertRaises(IOError):
j.read() j.read()
@unittest.skipIf(fixtures.OPENJPEG_NOT_AVAILABLE,
fixtures.OPENJPEG_NOT_AVAILABLE_MSG)
@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")
@unittest.skipIf(re.match(r'''(1|2.0.0)''', @unittest.skipIf(re.match(r'''(1|2.0.0)''',

View file

@ -31,6 +31,8 @@ import lxml.etree as ET
import glymur import glymur
from glymur import Jp2k, command_line from glymur import Jp2k, command_line
from glymur.version import openjpeg_version
from . import fixtures from . import fixtures
from .fixtures import OPJ_DATA_ROOT, opj_data_file from .fixtures import OPJ_DATA_ROOT, opj_data_file
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
@ -106,6 +108,8 @@ class TestPrinting(unittest.TestCase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
glymur.set_printoptions(hi='low') glymur.set_printoptions(hi='low')
@unittest.skipIf(re.match('0|1.[0-4]', openjpeg_version) is not None,
"Not supported with OpenJPEG {0}".format(openjpeg_version))
def test_asoc_label_box(self): def test_asoc_label_box(self):
"""verify printing of asoc, label boxes""" """verify printing of asoc, label boxes"""
# Construct a fake file with an asoc and a label box, as # Construct a fake file with an asoc and a label box, as