From 7c0d1385b836e963aaf5e69610070f390fa1ec11 Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 15 Jul 2013 21:12:44 -0400 Subject: [PATCH] Added test for expected read error when both libraries missing. --- glymur/jp2k.py | 6 +++++- glymur/test/test_config.py | 20 ++++++++++++++++++-- release.txt | 6 +++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 88a8336..88325d4 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -612,8 +612,12 @@ class Jp2k(Jp2kBox): """ if _opj2.OPENJP2 is not None: img = self._read_openjp2(**kwargs) - else: + elif _opj.OPENJPEG is not None: img = self._read_openjpeg(**kwargs) + else: + raise IOError("You must have either a recent version of OpenJPEG " + "or the development version of OpenJP2 installed " + "before using this functionality.") return img def _read_openjpeg(self, rlevel=0, verbose=False): diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index 9615a7f..913be9b 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -25,8 +25,25 @@ import glymur from glymur import Jp2k from glymur.lib import openjp2 as opj2 +class TestConfig(unittest.TestCase): + + def setUp(self): + self.jp2file = glymur.data.nemo() + + def tearDown(self): + pass + + def test_read_without_library_backing_us_up(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((IOError, OSError)): + d = glymur.Jp2k(self.jp2file).read() + + @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") + "TemporaryDirectory introduced in 3.2.") @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Needs openjp2 library first before these tests make sense.") class TestSuite(unittest.TestCase): @@ -51,7 +68,6 @@ class TestSuite(unittest.TestCase): imp.reload(glymur) imp.reload(glymur.lib.openjp2) - @unittest.skip("blah") def test_config_file_via_environ(self): """Verify that we can read a configuration file set via environ var.""" with tempfile.TemporaryDirectory() as tdir: diff --git a/release.txt b/release.txt index 03466fa..445cb66 100644 --- a/release.txt +++ b/release.txt @@ -9,15 +9,15 @@ | | | | | tests should pass. | +---------+--------+--------+--------+---------------------------------------+ | Mac | X | | | MacPorts with both OpenJPEG 1.5.1 | -| | | | | and OpenJPEG svn. 341 of 450 tests | +| | | | | and OpenJPEG svn. 342 of 451 tests | | | | | | should pass. | +---------+--------+--------+--------+---------------------------------------+ | Mac | | X | | MacPorts with both OpenJPEG 1.5.1 | -| | | | | and OpenJPEG svn. 372 of 450 tests | +| | | | | and OpenJPEG svn. 373 of 451 tests | | | | | | should pass. | +---------+--------+--------+--------+---------------------------------------+ | Mac | | | X | MacPorts with both OpenJPEG 1.5.1 | -| | | | | and OpenJPEG svn. 397 of 450 | +| | | | | and OpenJPEG svn. 398 of 451 | | | | | | tests should pass. | +---------+--------+--------+------------------------------------------------+ | Fedora | | | X | Ships with 1.5.1. 390 of 450 tests |