diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index a33d1d6..164f93d 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -11,6 +11,18 @@ import numpy as np import glymur +# The Python XMP Toolkit may be used for XMP UUIDs, but only if available and +# if the version is at least 2.0.0. +try: + import libxmp + if hasattr(libxmp, 'version') and re.match('[2-9].\d*.\d*', libxmp.version.VERSION): + from libxmp import XMPMeta + HAS_PYTHON_XMP_TOOLKIT = True + else: + HAS_PYTHON_XMP_TOOLKIT = False +except ImportError: + HAS_PYTHON_XMP_TOOLKIT = False + # Need to know of the libopenjp2 version is the official 2.0.0 release and NOT # the 2.0+ development version. OPENJP2_IS_V2_OFFICIAL = False diff --git a/glymur/test/test_jp2box_uuid.py b/glymur/test/test_jp2box_uuid.py index 3e7f196..1415777 100644 --- a/glymur/test/test_jp2box_uuid.py +++ b/glymur/test/test_jp2box_uuid.py @@ -35,7 +35,9 @@ if sys.hexversion <= 0x03030000: else: from unittest.mock import patch -from libxmp import XMPMeta +from .fixtures import HAS_PYTHON_XMP_TOOLKIT, OPJ_DATA_ROOT +if HAS_PYTHON_XMP_TOOLKIT: + from libxmp import XMPMeta import glymur from glymur import Jp2k @@ -66,9 +68,13 @@ class TestUUIDXMP(unittest.TestCase): actual_ids = [b.box_id for b in jp2.box] self.assertEqual(actual_ids, expected_ids) - # The data should be an XMP packet, which gets interpreted as - # an ElementTree. - self.assertTrue(isinstance(jp2.box[-1].data, XMPMeta)) + # The data should be an XMP packet + if HAS_PYTHON_XMP_TOOLKIT: + # when python xmp toolkit is available. + self.assertTrue(isinstance(jp2.box[-1].data, XMPMeta)) + else: + # when python xmp toolkit is not available. + self.assertTrue(isinstance(jp2.box[-1].data, str)) class TestUUIDExif(unittest.TestCase): """Tests for UUIDs of Exif type.""" diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index c055aba..cf5596e 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -30,12 +30,13 @@ import warnings import numpy as np import pkg_resources -import libxmp - import glymur from glymur import Jp2k -from .fixtures import OPENJP2_IS_V2_OFFICIAL +from .fixtures import HAS_PYTHON_XMP_TOOLKIT, OPENJP2_IS_V2_OFFICIAL +if HAS_PYTHON_XMP_TOOLKIT: + import libxmp + from .fixtures import OPJ_DATA_ROOT, opj_data_file @@ -361,6 +362,8 @@ class TestJp2k(unittest.TestCase): self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()), b'this is a test') + @unittest.skipIf(not HAS_PYTHON_XMP_TOOLKIT, + "Requires Python XMP Toolkit >= 2.0") def test_xmp_attribute(self): """Verify the XMP packet in the shipping example file can be read.""" j = Jp2k(self.jp2file)