updated tests to run on fully loaded platform, closes #287
This commit is contained in:
parent
c1bb57f086
commit
da25953de3
4 changed files with 48 additions and 73 deletions
|
|
@ -967,10 +967,10 @@ class Jp2k(Jp2kBox):
|
|||
>>> thumbnail.shape
|
||||
(728, 1296, 3)
|
||||
"""
|
||||
if opj2.OPENJP2 is not None:
|
||||
img = self._read_openjp2(**kwargs)
|
||||
else:
|
||||
if version.openjpeg_version_tuple[0] < 2:
|
||||
img = self._read_openjpeg(**kwargs)
|
||||
else:
|
||||
img = self._read_openjp2(**kwargs)
|
||||
return img
|
||||
|
||||
def _subsampling_sanity_check(self):
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ import glymur
|
|||
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
class TestCallbacks(unittest.TestCase):
|
||||
"""Test suite for callbacks."""
|
||||
|
||||
|
|
@ -37,6 +35,8 @@ class TestCallbacks(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(glymur.version.openjpeg_version[0] != '2',
|
||||
"Missing openjp2 library.")
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_info_callback_on_write(self):
|
||||
|
|
@ -59,46 +59,20 @@ class TestCallbacks(unittest.TestCase):
|
|||
# callback handler is enabled.
|
||||
j = glymur.Jp2k(self.j2kfile)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150))
|
||||
j.read(rlevel=1, verbose=True)
|
||||
actual = fake_out.getvalue().strip()
|
||||
|
||||
lines = ['[INFO] Start to read j2k main header (0).',
|
||||
'[INFO] Main header has been correctly decoded.',
|
||||
'[INFO] Setting decoding area to 0,0,150,200',
|
||||
'[INFO] Header of tile 0 / 0 has been read.',
|
||||
'[INFO] Tile 1/1 has been decoded.',
|
||||
'[INFO] Image data has been updated with tile 1.']
|
||||
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None,
|
||||
"Missing openjpeg library.")
|
||||
class TestCallbacks15(unittest.TestCase):
|
||||
"""This test suite is for OpenJPEG 1.5.1 properties.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
self.j2kfile = glymur.data.goodstuff()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_info_callbacks_on_read(self):
|
||||
"""Verify stdout when reading.
|
||||
|
||||
Verify that we get the expected stdio output when our internal info
|
||||
callback handler is enabled.
|
||||
"""
|
||||
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
||||
# Force to use OPENJPEG instead of OPENJP2.
|
||||
j = glymur.Jp2k(self.j2kfile)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
j.read(rlevel=1, verbose=True)
|
||||
actual = fake_out.getvalue().strip()
|
||||
if glymur.version.openjpeg_version[0] == '2':
|
||||
lines = ['[INFO] Start to read j2k main header (0).',
|
||||
'[INFO] Main header has been correctly decoded.',
|
||||
'[INFO] No decoded area parameters, set the decoded area to the whole image',
|
||||
'[INFO] Header of tile 0 / 0 has been read.',
|
||||
'[INFO] Tile 1/1 has been decoded.',
|
||||
'[INFO] Image data has been updated with tile 1.']
|
||||
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
else:
|
||||
regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+
|
||||
\[INFO\]\s-\stiers-1\stook\s
|
||||
[0-9]+\.[0-9]+\ss\s+
|
||||
|
|
@ -114,7 +88,3 @@ class TestCallbacks15(unittest.TestCase):
|
|||
self.assertRegexpMatches(actual, regex)
|
||||
else:
|
||||
self.assertRegex(actual, regex)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -987,8 +987,6 @@ class TestJp2k_write(unittest.TestCase):
|
|||
self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL)
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] >= 2,
|
||||
"Negative tests only for version 1.x")
|
||||
class TestJp2k_1_x(unittest.TestCase):
|
||||
"""Test suite for openjpeg 1.x, not appropriate for 2.x"""
|
||||
|
||||
|
|
@ -1002,32 +1000,32 @@ class TestJp2k_1_x(unittest.TestCase):
|
|||
def test_tile(self):
|
||||
"""tile option not allowed for 1.x.
|
||||
"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(tile=0)
|
||||
with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(tile=0)
|
||||
|
||||
def test_layer(self):
|
||||
"""layer option not allowed for 1.x.
|
||||
"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(layer=1)
|
||||
with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(layer=1)
|
||||
|
||||
|
||||
@unittest.skipIf(re.match(r'''2.0.0''',
|
||||
glymur.version.openjpeg_version) is None,
|
||||
"Tests only to be run on 2.0 official.")
|
||||
class TestJp2k_2_0_official(unittest.TestCase):
|
||||
"""Test suite to only be run on v2.0 official."""
|
||||
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
|
||||
class Test_2p0_official(unittest.TestCase):
|
||||
"""Tests specific to v2.0.0"""
|
||||
|
||||
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
|
||||
def test_extra_components_on_v2(self):
|
||||
"""Can only write 4 components on 2.0+, should error out otherwise."""
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
data = np.zeros((128, 128, 4), dtype=np.uint8)
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data)
|
||||
with patch('glymur.version.openjpeg_version', new="2.0.0"):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
data = np.zeros((128, 128, 4), dtype=np.uint8)
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data)
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ import sys
|
|||
import tempfile
|
||||
import unittest
|
||||
|
||||
if sys.hexversion <= 0x03030000:
|
||||
from mock import patch
|
||||
else:
|
||||
from unittest.mock import patch
|
||||
|
||||
import numpy as np
|
||||
try:
|
||||
import skimage.io
|
||||
|
|
@ -195,12 +200,10 @@ class WriteCinemaWarns(CinemaBase):
|
|||
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
|
||||
"Cannot read input image without scikit-image/freeimage")
|
||||
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
|
||||
@unittest.skipIf(not re.match("(1.5|2.0.0)", glymur.version.openjpeg_version),
|
||||
"Functionality implemented for 2.0.1")
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_OPJ_DATA_ROOT environment variable not set")
|
||||
class TestSuiteNegative2pointzero(unittest.TestCase):
|
||||
"""Feature set not supported for versions less than 2.0"""
|
||||
class TestNegative2pointzero(unittest.TestCase):
|
||||
"""Feature set not supported for versions less than 2.0.1"""
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
|
|
@ -210,13 +213,17 @@ class TestSuiteNegative2pointzero(unittest.TestCase):
|
|||
pass
|
||||
|
||||
def test_cinema_mode(self):
|
||||
"""Cinema mode not allowed for anything less than 2.0.1"""
|
||||
relfile = 'input/nonregression/X_4_2K_24_185_CBR_WB_000.tif'
|
||||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cinema2k=48)
|
||||
versions = ["1.5.0", "2.0.0"]
|
||||
for version in versions:
|
||||
with patch('glymur.version.openjpeg_version', new=version):
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with self.assertRaises(IOError):
|
||||
j.write(data, cinema2k=48)
|
||||
|
||||
|
||||
@unittest.skipIf(re.match(r'''1.[0-4]''', openjpeg_version) is not None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue