From 13ff187fc00b91754df6337fc7569dd5eaf22c68 Mon Sep 17 00:00:00 2001 From: John Evans Date: Tue, 16 Jul 2013 07:04:30 -0400 Subject: [PATCH] Tests to error out with read_bands, write without libraries present. --- glymur/jp2k.py | 7 ++++-- glymur/test/test_config.py | 17 -------------- glymur/test/test_jp2k.py | 45 ++++++++++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 88325d4..dbdafd7 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -226,6 +226,9 @@ class Jp2k(Jp2kBox): >>> j = Jp2k(tfile.name, mode='wb') >>> j.write(data.astype(np.uint8)) """ + if _opj2.OPENJP2 is None: + raise IOError("You must have the development version of OpenJP2 " + "installed before using this functionality.") cparams = _opj2.set_default_encoder_parameters() @@ -965,8 +968,8 @@ class Jp2k(Jp2kBox): If the openjp2 library is not available. """ if _opj2.OPENJP2 is None: - msg = "Requires openjp2 library." - raise NotImplementedError(msg) + raise IOError("You must have the development version of OpenJP2 " + "installed before using this functionality.") lst = self._read_common(rlevel=rlevel, layer=layer, diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index 913be9b..5fd70bb 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -25,23 +25,6 @@ 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, "TemporaryDirectory introduced in 3.2.") @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 7b940b0..4467b5c 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -47,6 +47,44 @@ def load_tests(loader, tests, ignore): return tests +class TestConfig(unittest.TestCase): + + def setUp(self): + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + 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() + + def test_read_bands_without_library_backing_us_up(self): + """Don't have openjp2 library? 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_bands() + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_write_without_library_backing_us_up(self): + """Don't have openjp2 library? Must error out. + """ + data = glymur.Jp2k(self.j2kfile).read() + with patch('glymur.lib.openjp2.OPENJP2', new=None): + with patch('glymur.lib.openjpeg.OPENJPEG', new=None): + with self.assertRaises((IOError, OSError)): + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + ofile = Jp2k(tfile.name, 'wb') + ofile.write(data) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") @@ -713,13 +751,6 @@ class TestJp2k15(unittest.TestCase): def tearDown(self): pass - def test_bands(self): - """Reading individual bands is an advanced maneuver. - """ - jp2k = Jp2k(self.j2kfile) - with self.assertRaises(NotImplementedError): - jp2k.read_bands() - def test_area(self): """Area option not allowed for 1.5.1. """