From 69d3c1a846ba86190b1ef8cc0932e27202d03f4f Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 3 Sep 2014 20:26:11 -0400 Subject: [PATCH] Need to use extra care on skimage.io.plugin('freeimage'...) --- glymur/test/fixtures.py | 13 +++++++++++++ glymur/test/test_opj_suite_neg.py | 10 ++-------- glymur/test/test_opj_suite_write.py | 14 ++++---------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 0fc5be1..845c342 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -37,6 +37,19 @@ except: raise +# The Cinema2K/4K tests seem to need the freeimage backend to skimage.io +# in order to work. +try: + import skimage.io + if 'freeimage' in skimage.io.find_available_plugins(loaded=True).keys(): + skimage.io.use_plugin('freeimage', 'imread') + NO_SKIMAGE_FREEIMAGE_SUPPORT = False + else: + NO_SKIMAGE_FREEIMAGE_SUPPORT = True +except ((ImportError, RuntimeError)): + NO_SKIMAGE_FREEIMAGE_SUPPORT = True + + def _indent(textstr): """ Indent a string. diff --git a/glymur/test/test_opj_suite_neg.py b/glymur/test/test_opj_suite_neg.py index 0020803..244d244 100644 --- a/glymur/test/test_opj_suite_neg.py +++ b/glymur/test/test_opj_suite_neg.py @@ -17,15 +17,9 @@ import warnings import numpy as np -try: - import skimage.io - skimage.io.use_plugin('freeimage', 'imread') - _HAS_SKIMAGE_FREEIMAGE_SUPPORT = True -except ((ImportError, RuntimeError)): - _HAS_SKIMAGE_FREEIMAGE_SUPPORT = False - from .fixtures import OPJ_DATA_ROOT, opj_data_file, read_image from .fixtures import NO_READ_BACKEND, NO_READ_BACKEND_MSG +from .fixtures import NO_SKIMAGE_FREEIMAGE_SUPPORT from glymur import Jp2k import glymur @@ -44,7 +38,7 @@ class TestSuiteNegative(unittest.TestCase): pass - @unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT, + @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") def test_cinema2K_bad_frame_rate(self): diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 5fdc0ca..e3d80ff 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -15,21 +15,15 @@ import warnings import numpy as np -try: - import skimage.io - skimage.io.use_plugin('freeimage', 'imread') - _HAS_SKIMAGE_FREEIMAGE_SUPPORT = True -except ((ImportError, RuntimeError)): - _HAS_SKIMAGE_FREEIMAGE_SUPPORT = False - from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG -from .fixtures import OPJ_DATA_ROOT, opj_data_file +from .fixtures import OPJ_DATA_ROOT, NO_SKIMAGE_FREEIMAGE_SUPPORT +from .fixtures import opj_data_file from . import fixtures from glymur import Jp2k import glymur -@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT, +@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") @unittest.skipIf(os.name == "nt", "no write support on windows, period") @unittest.skipIf(re.match(r'''(1|2.0.0)''', @@ -230,7 +224,7 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (1998, 1080)) -@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT, +@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @unittest.skipIf(not re.match("(1.5|2.0.0)", glymur.version.openjpeg_version),