Tests to error out with read_bands, write without libraries present.
This commit is contained in:
parent
7c0d1385b8
commit
13ff187fc0
3 changed files with 43 additions and 26 deletions
|
|
@ -226,6 +226,9 @@ class Jp2k(Jp2kBox):
|
||||||
>>> j = Jp2k(tfile.name, mode='wb')
|
>>> j = Jp2k(tfile.name, mode='wb')
|
||||||
>>> j.write(data.astype(np.uint8))
|
>>> 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()
|
cparams = _opj2.set_default_encoder_parameters()
|
||||||
|
|
||||||
|
|
@ -965,8 +968,8 @@ class Jp2k(Jp2kBox):
|
||||||
If the openjp2 library is not available.
|
If the openjp2 library is not available.
|
||||||
"""
|
"""
|
||||||
if _opj2.OPENJP2 is None:
|
if _opj2.OPENJP2 is None:
|
||||||
msg = "Requires openjp2 library."
|
raise IOError("You must have the development version of OpenJP2 "
|
||||||
raise NotImplementedError(msg)
|
"installed before using this functionality.")
|
||||||
|
|
||||||
lst = self._read_common(rlevel=rlevel,
|
lst = self._read_common(rlevel=rlevel,
|
||||||
layer=layer,
|
layer=layer,
|
||||||
|
|
|
||||||
|
|
@ -25,23 +25,6 @@ import glymur
|
||||||
from glymur import Jp2k
|
from glymur import Jp2k
|
||||||
from glymur.lib import openjp2 as opj2
|
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,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
"TemporaryDirectory introduced in 3.2.")
|
"TemporaryDirectory introduced in 3.2.")
|
||||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,44 @@ def load_tests(loader, tests, ignore):
|
||||||
return tests
|
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(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
|
|
@ -713,13 +751,6 @@ class TestJp2k15(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
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):
|
def test_area(self):
|
||||||
"""Area option not allowed for 1.5.1.
|
"""Area option not allowed for 1.5.1.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue