Compare commits
11 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db5d8722b3 | ||
|
|
6c41799412 | ||
|
|
3d664b70ff | ||
|
|
0d7547a240 | ||
|
|
95448daa2e | ||
|
|
60d24aa2e6 | ||
|
|
8ae5558fb1 | ||
|
|
6ae0b14ba8 | ||
|
|
bfbc99d2da | ||
|
|
fc2a6c3075 | ||
|
|
7d88ac3c45 |
17 changed files with 1007 additions and 1002 deletions
|
|
@ -8,9 +8,21 @@ import textwrap
|
|||
import warnings
|
||||
|
||||
import numpy as np
|
||||
import six
|
||||
|
||||
import glymur
|
||||
|
||||
# Some versions of "six" on python3 cause problems when verifying warnings.
|
||||
# Only use when the version is 1.7 or higher.
|
||||
# And moreover, we only test using the 3.x infrastructure, never on 2.x.
|
||||
WARNING_INFRASTRUCTURE_ISSUE = False
|
||||
WARNING_INFRASTRUCTURE_MSG = ""
|
||||
if sys.hexversion < 0x03000000:
|
||||
WARNING_INFRASTRUCTURE_ISSUE = True
|
||||
WARNING_INFRASTRUCTURE_MSG = "3.x warning infrastructure only"
|
||||
elif re.match('1.[0-6]', six.__version__) is not None:
|
||||
WARNING_INFRASTRUCTURE_ISSUE = True
|
||||
WARNING_INFRASTRUCTURE_MSG = "Cannot use with this version of six"
|
||||
|
||||
# The Python XMP Toolkit may be used for XMP UUIDs, but only if available and
|
||||
# if the version is at least 2.0.0.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import os
|
|||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import warnings
|
||||
|
||||
import unittest
|
||||
|
||||
|
|
@ -24,6 +23,7 @@ else:
|
|||
|
||||
import glymur
|
||||
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
|
|
@ -37,12 +37,12 @@ class TestCallbacks(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@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):
|
||||
"""Verify messages printed when writing an image in verbose mode."""
|
||||
j = glymur.Jp2k(self.jp2file)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
tiledata = j.read(tile=0)
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = glymur.Jp2k(tfile.name, 'wb')
|
||||
|
|
|
|||
|
|
@ -5,15 +5,11 @@ Test suite for codestream parsing.
|
|||
# unittest doesn't work well with R0904.
|
||||
# pylint: disable=R0904
|
||||
|
||||
# tempfile.TemporaryDirectory, unittest.assertWarns introduced in 3.2
|
||||
# pylint: disable=E1101
|
||||
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from glymur import Jp2k
|
||||
import glymur
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import os
|
|||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
if sys.hexversion <= 0x03030000:
|
||||
from mock import patch
|
||||
|
|
@ -26,6 +25,7 @@ else:
|
|||
import glymur
|
||||
from glymur import Jp2k
|
||||
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||
"TemporaryDirectory introduced in 3.2.")
|
||||
|
|
@ -70,6 +70,7 @@ class TestSuite(unittest.TestCase):
|
|||
imp.reload(glymur.lib.openjp2)
|
||||
Jp2k(self.jp2file)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_xdg_env_config_file_is_bad(self):
|
||||
"""A non-existant library location should be rejected."""
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
|
|
@ -84,11 +85,9 @@ class TestSuite(unittest.TestCase):
|
|||
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
||||
# Misconfigured new configuration file should
|
||||
# be rejected.
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
regex = 'could not be loaded'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
imp.reload(glymur.lib.openjp2)
|
||||
self.assertTrue(issubclass(w[0].category,UserWarning))
|
||||
self.assertTrue('could not be loaded' in str(w[0].message))
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ Test suite for warnings issued by glymur.
|
|||
# unittest doesn't work well with R0904.
|
||||
# pylint: disable=R0904
|
||||
|
||||
import platform
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import six
|
||||
|
||||
|
|
@ -19,13 +19,13 @@ from glymur import Jp2k
|
|||
import glymur
|
||||
|
||||
from .fixtures import opj_data_file, OPJ_DATA_ROOT
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
@unittest.skipIf(sys.hexversion < 0x03030000,
|
||||
"assertWarn methods introduced in 3.x")
|
||||
@unittest.skipIf(re.match('1.[0-6]', six.__version__) is not None,
|
||||
"Problem with earlier versions of six on python3")
|
||||
@unittest.skipIf(sys.hexversion < 0x03040000 and platform.system() == 'Linux',
|
||||
"inexplicable failures on 3.3 and linux")
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
class TestWarnings(unittest.TestCase):
|
||||
"""Test suite for warnings issued by glymur."""
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,15 @@ import datetime
|
|||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
|
||||
from glymur import Jp2k
|
||||
from .fixtures import OPJ_DATA_ROOT, opj_data_file
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class TestICC(unittest.TestCase):
|
||||
|
|
@ -31,9 +32,8 @@ class TestICC(unittest.TestCase):
|
|||
def test_file5(self):
|
||||
"""basic ICC profile"""
|
||||
filename = opj_data_file('input/conformance/file5.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# The file has a bad compatibility list entry. Not important here.
|
||||
warnings.simplefilter("ignore")
|
||||
j = Jp2k(filename)
|
||||
profile = j.box[3].box[1].icc_profile
|
||||
self.assertEqual(profile['Size'], 546)
|
||||
|
|
@ -62,18 +62,15 @@ class TestICC(unittest.TestCase):
|
|||
|
||||
self.assertEqual(profile['Creator'], 'JPEG')
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('linux'), 'Failing on linux')
|
||||
def test_invalid_profile_header(self):
|
||||
"""invalid ICC header data should cause UserWarning"""
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
|
||||
|
||||
# assertWarns in Python 3.3 (python2.7/pylint issue)
|
||||
# pylint: disable=E1101
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
regex = 'ICC profile header is corrupt'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
Jp2k(jfile)
|
||||
self.assertTrue(issubclass(w[0].category,UserWarning))
|
||||
self.assertTrue('ICC profile header is corrupt' in str(w[0].message))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import tempfile
|
|||
import uuid
|
||||
from uuid import UUID
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import lxml.etree as ET
|
||||
import numpy as np
|
||||
|
|
@ -37,6 +36,7 @@ from glymur.core import COLOR, OPACITY
|
|||
from glymur.core import RED, GREEN, BLUE, GREY, WHOLE_IMAGE
|
||||
|
||||
from .fixtures import opj_data_file
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
try:
|
||||
FORMAT_CORPUS_DATA_ROOT = os.environ['FORMAT_CORPUS_DATA_ROOT']
|
||||
|
|
@ -357,6 +357,7 @@ class TestChannelDefinition(unittest.TestCase):
|
|||
with self.assertRaises((IOError, OSError)):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_bad_type(self):
|
||||
"""Channel types are limited to 0, 1, 2, 65535
|
||||
Should reject if not all of index, channel_type, association the
|
||||
|
|
@ -365,25 +366,20 @@ class TestChannelDefinition(unittest.TestCase):
|
|||
channel_type = (COLOR, COLOR, 3)
|
||||
association = (RED, GREEN, BLUE)
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_wrong_lengths(self):
|
||||
"""Should reject if not all of index, channel_type, association the
|
||||
same length.
|
||||
"""
|
||||
channel_type = (COLOR, COLOR)
|
||||
association = (RED, GREEN, BLUE)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
|
||||
association=association)
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
|
||||
class TestFileTypeBox(unittest.TestCase):
|
||||
|
|
@ -395,20 +391,20 @@ class TestFileTypeBox(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_brand_unknown(self):
|
||||
"""A ftyp box brand must be 'jp2 ' or 'jpx '."""
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
ftyp = glymur.jp2box.FileTypeBox(brand='jp3')
|
||||
with self.assertRaises(IOError):
|
||||
with tempfile.TemporaryFile() as tfile:
|
||||
ftyp.write(tfile)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_cl_entry_unknown(self):
|
||||
"""A ftyp box cl list can only contain 'jp2 ', 'jpx ', or 'jpxb'."""
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Bad compatibility list item.
|
||||
warnings.simplefilter("ignore")
|
||||
ftyp = glymur.jp2box.FileTypeBox(compatibility_list=['jp3'])
|
||||
with self.assertRaises(IOError):
|
||||
with tempfile.TemporaryFile() as tfile:
|
||||
|
|
@ -479,41 +475,34 @@ class TestColourSpecificationBox(unittest.TestCase):
|
|||
self.assertEqual(colr.colorspace, glymur.core.SRGB)
|
||||
self.assertIsNone(colr.icc_profile)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_colr_with_cspace_and_icc(self):
|
||||
"""Colour specification boxes can't have both."""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
regex = 'Colorspace and icc_profile cannot both be set'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
colorspace = glymur.core.SRGB
|
||||
rawb = b'\x01\x02\x03\x04'
|
||||
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
|
||||
icc_profile=rawb)
|
||||
self.assertTrue(issubclass(w[0].category,UserWarning))
|
||||
msg = 'Colorspace and icc_profile cannot both be set'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_colr_with_bad_method(self):
|
||||
"""colr must have a valid method field"""
|
||||
colorspace = glymur.core.SRGB
|
||||
method = -1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
regex = 'Invalid method'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
|
||||
method=method)
|
||||
self.assertTrue(issubclass(w[0].category,UserWarning))
|
||||
msg = 'Invalid method'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_colr_with_bad_approx(self):
|
||||
"""colr should have a valid approximation field"""
|
||||
colorspace = glymur.core.SRGB
|
||||
approx = -1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarnsRegex(UserWarning, 'Invalid approximation'):
|
||||
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
|
||||
approximation=approx)
|
||||
self.assertTrue(issubclass(w[0].category,UserWarning))
|
||||
msg = 'Invalid approximation'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
def test_colr_with_bad_color(self):
|
||||
"""colr must have a valid color, strange as though that may sound."""
|
||||
|
|
@ -537,29 +526,25 @@ class TestPaletteBox(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_mismatched_bitdepth_signed(self):
|
||||
"""bitdepth and signed arguments must have equal length"""
|
||||
palette = np.array([[255, 0, 255], [0, 255, 0]], dtype=np.uint8)
|
||||
bps = (8, 8, 8)
|
||||
signed = (False, False)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
pclr = glymur.jp2box.PaletteBox(palette, bits_per_component=bps,
|
||||
signed=signed)
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_mismatched_signed_palette(self):
|
||||
"""bitdepth and signed arguments must have equal length"""
|
||||
palette = np.array([[255, 0, 255], [0, 255, 0]], dtype=np.uint8)
|
||||
bps = (8, 8, 8, 8)
|
||||
signed = (False, False, False, False)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
pclr = glymur.jp2box.PaletteBox(palette, bits_per_component=bps,
|
||||
signed=signed)
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
def test_writing_with_different_bitdepths(self):
|
||||
"""Bitdepths must be the same when writing."""
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import struct
|
|||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import lxml.etree as ET
|
||||
|
||||
|
|
@ -19,6 +18,8 @@ from glymur.jp2box import DataEntryURLBox, FileTypeBox, JPEG2000SignatureBox
|
|||
from glymur.jp2box import DataReferenceBox, FragmentListBox, FragmentTableBox
|
||||
from glymur.jp2box import ColourSpecificationBox
|
||||
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
class TestJPXWrap(unittest.TestCase):
|
||||
"""Test suite for wrapping JPX files."""
|
||||
|
|
@ -305,17 +306,15 @@ class TestJPXWrap(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
jp2.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_deurl_child_of_dtbl(self):
|
||||
"""Data reference boxes can only contain data entry url boxes."""
|
||||
jp2 = Jp2k(self.jp2file)
|
||||
boxes = [jp2.box[idx] for idx in [0, 1, 2, 4]]
|
||||
|
||||
ftyp = glymur.jp2box.FileTypeBox()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
dref = glymur.jp2box.DataReferenceBox([ftyp])
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
# Try to get around it by appending the ftyp box after creation.
|
||||
dref = glymur.jp2box.DataReferenceBox()
|
||||
|
|
@ -433,37 +432,37 @@ class TestJPX(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_flst_lens_not_the_same(self):
|
||||
"""A fragment list box items must be the same length."""
|
||||
offset = [89]
|
||||
length = [1132288]
|
||||
reference = [0, 0]
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
flst = glymur.jp2box.FragmentListBox(offset, length, reference)
|
||||
with self.assertRaises(IOError):
|
||||
with tempfile.TemporaryFile() as tfile:
|
||||
flst.write(tfile)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_flst_offsets_not_positive(self):
|
||||
"""A fragment list box offsets must be positive."""
|
||||
offset = [0]
|
||||
length = [1132288]
|
||||
reference = [0]
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
flst = glymur.jp2box.FragmentListBox(offset, length, reference)
|
||||
with self.assertRaises((IOError, OSError)):
|
||||
with tempfile.TemporaryFile() as tfile:
|
||||
flst.write(tfile)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_flst_lengths_not_positive(self):
|
||||
"""A fragment list box lengths must be positive."""
|
||||
offset = [89]
|
||||
length = [0]
|
||||
reference = [0]
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
flst = glymur.jp2box.FragmentListBox(offset, length, reference)
|
||||
with self.assertRaises(IOError):
|
||||
with tempfile.TemporaryFile() as tfile:
|
||||
|
|
@ -471,9 +470,7 @@ class TestJPX(unittest.TestCase):
|
|||
|
||||
def test_ftbl_boxes_empty(self):
|
||||
"""A fragment table box must have at least one child box."""
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
ftbl = glymur.jp2box.FragmentTableBox()
|
||||
ftbl = glymur.jp2box.FragmentTableBox()
|
||||
with self.assertRaises(IOError):
|
||||
with tempfile.TemporaryFile() as tfile:
|
||||
ftbl.write(tfile)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import struct
|
|||
import sys
|
||||
import tempfile
|
||||
import uuid
|
||||
import warnings
|
||||
|
||||
if sys.hexversion < 0x02070000:
|
||||
import unittest2 as unittest
|
||||
|
|
@ -37,6 +36,8 @@ else:
|
|||
import lxml.etree
|
||||
|
||||
from .fixtures import HAS_PYTHON_XMP_TOOLKIT, OPJ_DATA_ROOT
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
if HAS_PYTHON_XMP_TOOLKIT:
|
||||
from libxmp import XMPMeta
|
||||
|
||||
|
|
@ -46,8 +47,8 @@ from .fixtures import OPJ_DATA_ROOT, opj_data_file, SimpleRDF
|
|||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Unexplained failure on windows")
|
||||
class TestUUIDXMP(unittest.TestCase):
|
||||
"""Tests for UUIDs of XMP type."""
|
||||
class TestSuite(unittest.TestCase):
|
||||
"""Tests for XMP, Exif UUIDs."""
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
|
|
@ -55,7 +56,7 @@ class TestUUIDXMP(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_append(self):
|
||||
def test_append_xmp_uuid(self):
|
||||
"""Should be able to append an XMP UUID box."""
|
||||
the_uuid = uuid.UUID('be7acfcb-97a9-42e8-9c71-999491e3afac')
|
||||
raw_data = SimpleRDF.encode('utf-8')
|
||||
|
|
@ -75,16 +76,42 @@ class TestUUIDXMP(unittest.TestCase):
|
|||
self.assertTrue(isinstance(jp2.box[-1].data,
|
||||
lxml.etree._ElementTree))
|
||||
|
||||
def test_big_endian_exif(self):
|
||||
"""Verify read of Exif big-endian IFD."""
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile:
|
||||
|
||||
with open(self.jp2file, 'rb') as ifptr:
|
||||
tfile.write(ifptr.read())
|
||||
|
||||
# Write L, T, UUID identifier.
|
||||
tfile.write(struct.pack('>I4s', 52, b'uuid'))
|
||||
tfile.write(b'JpgTiffExif->JP2')
|
||||
|
||||
tfile.write(b'Exif\x00\x00')
|
||||
xbuffer = struct.pack('>BBHI', 77, 77, 42, 8)
|
||||
tfile.write(xbuffer)
|
||||
|
||||
# We will write just a single tag.
|
||||
tfile.write(struct.pack('>H', 1))
|
||||
|
||||
# The "Make" tag is tag no. 271.
|
||||
tfile.write(struct.pack('>HHI4s', 271, 2, 3, b'HTC\x00'))
|
||||
tfile.flush()
|
||||
|
||||
jp2 = glymur.Jp2k(tfile.name)
|
||||
self.assertEqual(jp2.box[-1].data['Make'], "HTC")
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@unittest.skipIf(os.name == "nt", "Unexplained failure on windows")
|
||||
class TestUUIDExif(unittest.TestCase):
|
||||
"""Tests for UUIDs of Exif type."""
|
||||
class TestSuiteWarns(unittest.TestCase):
|
||||
"""Tests for XMP, Exif UUIDs, issues warnings."""
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_unrecognized_exif_tag(self):
|
||||
"""Verify warning in case of unrecognized tag."""
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile:
|
||||
|
|
@ -107,12 +134,8 @@ class TestUUIDExif(unittest.TestCase):
|
|||
tfile.write(struct.pack('<HHI4s', 171, 2, 3, b'HTC\x00'))
|
||||
tfile.flush()
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarnsRegex(UserWarning, 'Unrecognized Exif tag'):
|
||||
j = glymur.Jp2k(tfile.name)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
msg = 'Unrecognized Exif tag'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
def test_bad_tag_datatype(self):
|
||||
"""Only certain datatypes are allowable"""
|
||||
|
|
@ -136,12 +159,8 @@ class TestUUIDExif(unittest.TestCase):
|
|||
tfile.write(struct.pack('<HHI4s', 271, 2000, 3, b'HTC\x00'))
|
||||
tfile.flush()
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarnsRegex(UserWarning, 'Invalid TIFF tag'):
|
||||
j = glymur.Jp2k(tfile.name)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
msg = 'Invalid TIFF tag'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
self.assertEqual(j.box[-1].box_id, 'uuid')
|
||||
|
||||
|
|
@ -167,45 +186,11 @@ class TestUUIDExif(unittest.TestCase):
|
|||
tfile.write(struct.pack('<HHI4s', 271, 2, 3, b'HTC\x00'))
|
||||
tfile.flush()
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
j = glymur.Jp2k(tfile.name)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
msg = 'The byte order indication in the TIFF header '
|
||||
if sys.hexversion < 0x03000000:
|
||||
msg += "(JI) is invalid. "
|
||||
msg += "It should be either [73, 73] or [77, 77]."
|
||||
else:
|
||||
msg += "(b'JI') is invalid. "
|
||||
msg += "It should be either b'II' or b'MM'."
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
regex = 'The byte order indication in the TIFF header '
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
jp2 = glymur.Jp2k(tfile.name)
|
||||
|
||||
self.assertEqual(j.box[-1].box_id, 'uuid')
|
||||
|
||||
def test_big_endian(self):
|
||||
"""Verify read of big-endian IFD."""
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile:
|
||||
|
||||
with open(self.jp2file, 'rb') as ifptr:
|
||||
tfile.write(ifptr.read())
|
||||
|
||||
# Write L, T, UUID identifier.
|
||||
tfile.write(struct.pack('>I4s', 52, b'uuid'))
|
||||
tfile.write(b'JpgTiffExif->JP2')
|
||||
|
||||
tfile.write(b'Exif\x00\x00')
|
||||
xbuffer = struct.pack('>BBHI', 77, 77, 42, 8)
|
||||
tfile.write(xbuffer)
|
||||
|
||||
# We will write just a single tag.
|
||||
tfile.write(struct.pack('>H', 1))
|
||||
|
||||
# The "Make" tag is tag no. 271.
|
||||
tfile.write(struct.pack('>HHI4s', 271, 2, 3, b'HTC\x00'))
|
||||
tfile.flush()
|
||||
|
||||
jp2 = glymur.Jp2k(tfile.name)
|
||||
self.assertEqual(jp2.box[-1].data['Make'], "HTC")
|
||||
self.assertEqual(jp2.box[-1].box_id, 'uuid')
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ Test suite specifically targeting JP2 box layout.
|
|||
# pylint: disable=W0613
|
||||
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
if sys.hexversion < 0x03000000:
|
||||
from StringIO import StringIO
|
||||
|
|
@ -40,6 +40,7 @@ from glymur.jp2box import FileTypeBox, ImageHeaderBox, JP2HeaderBox
|
|||
from glymur.jp2box import JPEG2000SignatureBox
|
||||
|
||||
from .fixtures import OPJ_DATA_ROOT, opj_data_file
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
class TestXML(unittest.TestCase):
|
||||
|
|
@ -166,7 +167,6 @@ class TestXML(unittest.TestCase):
|
|||
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
class TestJp2kBadXmlFile(unittest.TestCase):
|
||||
"""Test suite for bad XML box situations"""
|
||||
|
||||
|
|
@ -207,14 +207,11 @@ class TestJp2kBadXmlFile(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_invalid_xml_box(self):
|
||||
"""Should be able to recover info from xml box with bad xml."""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(self._bad_xml_file)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
msg = 'No XML was retrieved'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
self.assertEqual(jp2k.box[3].box_id, 'xml ')
|
||||
self.assertEqual(jp2k.box[3].offset, 77)
|
||||
|
|
@ -263,19 +260,17 @@ class TestBadButRecoverableXmlFile(unittest.TestCase):
|
|||
def tearDownClass(cls):
|
||||
os.unlink(cls._bad_xml_file)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_bad_xml_box_warning(self):
|
||||
"""Should warn in case of bad XML"""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
regex = 'A UnicodeDecodeError was encountered parsing an XML box'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
Jp2k(self._bad_xml_file)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
msg = 'A UnicodeDecodeError was encountered parsing an XML box'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_recover_from_bad_xml(self):
|
||||
"""Should be able to recover info from xml box with bad xml."""
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(self._bad_xml_file)
|
||||
|
||||
self.assertEqual(jp2.box[3].box_id, 'xml ')
|
||||
|
|
@ -285,23 +280,21 @@ class TestBadButRecoverableXmlFile(unittest.TestCase):
|
|||
b'<test>this is a test</test>')
|
||||
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class TestXML_OpjDataRoot(unittest.TestCase):
|
||||
"""Test suite for XML boxes, requires OPJ_DATA_ROOT."""
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('linux'), 'Failing on linux')
|
||||
def test_bom(self):
|
||||
"""Byte order markers are illegal in UTF-8. Issue 185"""
|
||||
filename = opj_data_file(os.path.join('input',
|
||||
'nonregression',
|
||||
'issue171.jp2'))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
msg = 'An illegal BOM \(byte order marker\) was detected and removed '
|
||||
msg += 'from the XML contents in the box starting at byte offset \d+'
|
||||
with self.assertWarnsRegex(UserWarning, re.compile(msg)):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
msg = 'An illegal BOM (byte order marker) was detected and removed'
|
||||
self.assertTrue(msg in str(w[0].message))
|
||||
|
||||
self.assertIsNotNone(jp2.box[3].xml)
|
||||
|
||||
|
|
@ -311,10 +304,8 @@ class TestXML_OpjDataRoot(unittest.TestCase):
|
|||
filename = opj_data_file(os.path.join('input',
|
||||
'nonregression',
|
||||
'26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2'))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
with self.assertWarns((UserWarning, UserWarning)):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
self.assertIsNone(jp2.box[3].box[1].box[1].xml)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ import unittest
|
|||
import uuid
|
||||
from xml.etree import cElementTree as ET
|
||||
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
import pkg_resources
|
||||
|
||||
|
|
@ -30,6 +28,8 @@ import glymur
|
|||
from glymur import Jp2k
|
||||
|
||||
from .fixtures import HAS_PYTHON_XMP_TOOLKIT
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
if HAS_PYTHON_XMP_TOOLKIT:
|
||||
import libxmp
|
||||
from libxmp import XMPMeta
|
||||
|
|
@ -1020,6 +1020,7 @@ class TestJp2k_2_1(unittest.TestCase):
|
|||
self.assertEqual(j.box[2].box[0].num_components, 4)
|
||||
self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_openjpeg_library_message(self):
|
||||
"""Verify the error message produced by the openjpeg library"""
|
||||
|
|
@ -1044,8 +1045,7 @@ class TestJp2k_2_1(unittest.TestCase):
|
|||
tfile.write(data[offset+59:])
|
||||
#tfile.write(data[3186:])
|
||||
tfile.flush()
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
j = Jp2k(tfile.name)
|
||||
regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
|
||||
Invalid\svalues\sfor\scomp\s=\s0\s+
|
||||
|
|
@ -1069,21 +1069,16 @@ class TestParsing(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('linux'), 'Failing on linux')
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_bad_rsiz(self):
|
||||
"""Should not warn if RSIZ when parsing is turned off."""
|
||||
# Actually there are three warning triggered by this codestream.
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2')
|
||||
glymur.set_parseoptions(codestream=False)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
j = Jp2k(filename)
|
||||
self.assertEqual(len(w), 0)
|
||||
j = Jp2k(filename)
|
||||
|
||||
glymur.set_parseoptions(codestream=True)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with self.assertWarnsRegex(UserWarning, 'Invalid profile'):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
self.assertTrue('Invalid profile' in str(w[0].message))
|
||||
|
||||
def test_main_header(self):
|
||||
"""Verify that the main header is not loaded when parsing turned off."""
|
||||
|
|
@ -1095,6 +1090,7 @@ class TestParsing(unittest.TestCase):
|
|||
main_header = jp2c.main_header
|
||||
self.assertIsNotNone(jp2c._main_header)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class TestJp2kOpjDataRootWarnings(unittest.TestCase):
|
||||
|
|
@ -1103,11 +1099,8 @@ class TestJp2kOpjDataRootWarnings(unittest.TestCase):
|
|||
def test_undecodeable_box_id(self):
|
||||
"""Should warn in case of undecodeable box ID but not error out."""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1013627.jp2')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarnsRegex(UserWarning, 'Unrecognized box'):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
self.assertTrue('Unrecognized box' in str(w[0].message))
|
||||
|
||||
# Now make sure we got all of the boxes. Ignore the last, which was
|
||||
# bad.
|
||||
|
|
@ -1117,37 +1110,30 @@ class TestJp2kOpjDataRootWarnings(unittest.TestCase):
|
|||
def test_bad_ftyp_brand(self):
|
||||
"""Should warn in case of bad ftyp brand."""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1000290.jp2')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
|
||||
def test_invalid_approximation(self):
|
||||
"""Should warn in case of invalid approximation."""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1015644.jp2')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarnsRegex(UserWarning, 'Invalid approximation'):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[0].category, UserWarning))
|
||||
self.assertTrue('Invalid approximation' in str(w[0].message))
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('linux'), 'Failing on linux')
|
||||
def test_invalid_colorspace(self):
|
||||
"""Should warn in case of invalid colorspace."""
|
||||
"""
|
||||
Should warn in case of invalid colorspace.
|
||||
|
||||
There are multiple warnings, so there's no good way to regex them all.
|
||||
"""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[1].category, UserWarning))
|
||||
self.assertTrue('Unrecognized colorspace' in str(w[1].message))
|
||||
|
||||
def test_stupid_windows_eol_at_end(self):
|
||||
"""Garbage characters at the end of the file."""
|
||||
filename = opj_data_file('input/nonregression/issue211.jp2')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
self.assertTrue(issubclass(w[1].category, UserWarning))
|
||||
|
||||
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
|
|
@ -1172,10 +1158,12 @@ class TestJp2kOpjDataRoot(unittest.TestCase):
|
|||
actdata = j.read()
|
||||
self.assertTrue(fixtures.mse(actdata, expdata) < 250)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_no_cxform_pclr_jp2(self):
|
||||
"""Indices for pclr jpxfile if no color transform"""
|
||||
filename = opj_data_file('input/conformance/file9.jp2')
|
||||
j = Jp2k(filename)
|
||||
with self.assertWarns(UserWarning):
|
||||
j = Jp2k(filename)
|
||||
rgb = j.read()
|
||||
idx = j.read(ignore_pclr_cmap_cdef=True)
|
||||
self.assertEqual(rgb.shape, (512, 768, 3))
|
||||
|
|
@ -1200,15 +1188,15 @@ class TestJp2kOpjDataRoot(unittest.TestCase):
|
|||
j = Jp2k(filename)
|
||||
with self.assertRaises(RuntimeError):
|
||||
j.read()
|
||||
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_no_cxform_cmap(self):
|
||||
"""Bands as physically ordered, not as physically intended"""
|
||||
# This file has the components physically reversed. The cmap box
|
||||
# tells the decoder how to order them, but this flag prevents that.
|
||||
filename = opj_data_file('input/conformance/file2.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# The file has a bad compatibility list entry. Not important here.
|
||||
warnings.simplefilter("ignore")
|
||||
j = Jp2k(filename)
|
||||
ycbcr = j.read()
|
||||
crcby = j.read(ignore_pclr_cmap_cdef=True)
|
||||
|
|
|
|||
|
|
@ -31,20 +31,16 @@ import re
|
|||
import sys
|
||||
import unittest
|
||||
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
|
||||
from glymur import Jp2k
|
||||
import glymur
|
||||
|
||||
from .fixtures import OPJ_DATA_ROOT
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and
|
||||
glymur.lib.openjpeg.OPENJPEG is None,
|
||||
"Missing openjpeg libraries.")
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class TestSuite(unittest.TestCase):
|
||||
|
|
@ -204,18 +200,127 @@ class TestSuite(unittest.TestCase):
|
|||
self.assertTrue(peak_tolerance(jpdata, pgxdata) < 624)
|
||||
self.assertTrue(mse(jpdata, pgxdata) < 3080)
|
||||
|
||||
def test_NR_DEC_Bretagne2_j2k_1_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/Bretagne2.j2k')
|
||||
jp2 = Jp2k(jfile)
|
||||
jp2.read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC__00042_j2k_2_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/_00042.j2k')
|
||||
jp2 = Jp2k(jfile)
|
||||
jp2.read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_buxI_j2k_9_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/buxI.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_buxR_j2k_10_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/buxR.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self):
|
||||
relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
|
||||
jfile = opj_data_file(relpath)
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_cthead1_j2k_12_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/cthead1.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self):
|
||||
relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k'
|
||||
jfile = opj_data_file(relpath)
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_j2k32_j2k_15_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/j2k32.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_Marrin_jp2_18_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/Marrin.jp2')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_movie_00000_j2k_20_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/movie_00000.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_movie_00001_j2k_21_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/movie_00001.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_movie_00002_j2k_22_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/movie_00002.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_relax_jp2_27_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/relax.jp2')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_test_lossless_j2k_28_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/test_lossless.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_pacs_ge_j2k_30_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/pacs.ge.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
class TestSuiteWarns(unittest.TestCase):
|
||||
"""
|
||||
Identical setup to above, but these tests issue warnings.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_ETS_JP2_file1(self):
|
||||
jfile = opj_data_file('input/conformance/file1.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Bad compatibility list item.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (512, 768, 3))
|
||||
|
||||
def test_ETS_JP2_file2(self):
|
||||
jfile = opj_data_file('input/conformance/file2.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (640, 480, 3))
|
||||
|
||||
|
|
@ -223,7 +328,8 @@ class TestSuite(unittest.TestCase):
|
|||
"Functionality not implemented for 1.x")
|
||||
def test_ETS_JP2_file3(self):
|
||||
jfile = opj_data_file('input/conformance/file3.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read_bands()
|
||||
self.assertEqual(jpdata[0].shape, (640, 480))
|
||||
self.assertEqual(jpdata[1].shape, (320, 240))
|
||||
|
|
@ -231,50 +337,53 @@ class TestSuite(unittest.TestCase):
|
|||
|
||||
def test_ETS_JP2_file4(self):
|
||||
jfile = opj_data_file('input/conformance/file4.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (512, 768))
|
||||
|
||||
def test_ETS_JP2_file5(self):
|
||||
jfile = opj_data_file('input/conformance/file5.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# There's a warning for an unknown compatibility entry.
|
||||
# Ignore it here.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (512, 768, 3))
|
||||
|
||||
def test_ETS_JP2_file6(self):
|
||||
jfile = opj_data_file('input/conformance/file6.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (512, 768))
|
||||
|
||||
def test_ETS_JP2_file7(self):
|
||||
jfile = opj_data_file('input/conformance/file7.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (640, 480, 3))
|
||||
|
||||
def test_ETS_JP2_file8(self):
|
||||
jfile = opj_data_file('input/conformance/file8.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (400, 700))
|
||||
|
||||
def test_ETS_JP2_file9(self):
|
||||
jfile = opj_data_file('input/conformance/file9.jp2')
|
||||
jp2k = Jp2k(jfile)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2k = Jp2k(jfile)
|
||||
jpdata = jp2k.read()
|
||||
self.assertEqual(jpdata.shape, (512, 768, 3))
|
||||
|
||||
def test_NR_broken_jp2_dump(self):
|
||||
jfile = opj_data_file('input/nonregression/broken.jp2')
|
||||
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# colr box has bad length.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(jfile)
|
||||
|
||||
ids = [box.box_id for box in jp2.box]
|
||||
|
|
@ -395,111 +504,17 @@ class TestSuite(unittest.TestCase):
|
|||
self.assertEqual(c.segment[6].exponent,
|
||||
[8] + [9, 9, 10] * 5)
|
||||
|
||||
def test_NR_DEC_Bretagne2_j2k_1_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/Bretagne2.j2k')
|
||||
jp2 = Jp2k(jfile)
|
||||
jp2.read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC__00042_j2k_2_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/_00042.j2k')
|
||||
jp2 = Jp2k(jfile)
|
||||
jp2.read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_buxI_j2k_9_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/buxI.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_buxR_j2k_10_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/buxR.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self):
|
||||
relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
|
||||
jfile = opj_data_file(relpath)
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_cthead1_j2k_12_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/cthead1.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self):
|
||||
relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k'
|
||||
jfile = opj_data_file(relpath)
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_j2k32_j2k_15_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/j2k32.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_Marrin_jp2_18_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/Marrin.jp2')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_movie_00000_j2k_20_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/movie_00000.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_movie_00001_j2k_21_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/movie_00001.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_movie_00002_j2k_22_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/movie_00002.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_orb_blue_lin_jp2_25_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# This file has an invalid ICC profile
|
||||
warnings.simplefilter("ignore")
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_orb_blue_win_jp2_26_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_relax_jp2_27_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/relax.jp2')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_test_lossless_j2k_28_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/test_lossless.j2k')
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_NR_DEC_pacs_ge_j2k_30_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/pacs.ge.j2k')
|
||||
Jp2k(jfile).read()
|
||||
with self.assertWarns(UserWarning):
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
|
||||
|
|
@ -507,11 +522,9 @@ class TestSuite(unittest.TestCase):
|
|||
"OPJ_DATA_ROOT environment variable not set")
|
||||
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
|
||||
"Feature not supported in glymur until openjpeg 2.0")
|
||||
class TestSuite_bands(unittest.TestCase):
|
||||
"""Runs tests introduced in version 1.x but only pass in glymur with 2.0
|
||||
|
||||
The deal here is that the feature works with 1.x, but glymur only supports
|
||||
it with version 2.0.
|
||||
class TestSuiteBands(unittest.TestCase):
|
||||
"""
|
||||
Test the read_bands method.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -630,34 +643,34 @@ class TestSuite2point0(unittest.TestCase):
|
|||
pgxdata = read_pgx(pgxfile)
|
||||
np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_broken2_jp2_5_decode(self):
|
||||
# Null pointer access
|
||||
jfile = opj_data_file('input/nonregression/broken2.jp2')
|
||||
with self.assertRaises(IOError):
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Invalid marker ID.
|
||||
warnings.simplefilter("ignore")
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_broken4_jp2_7_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/broken4.jp2')
|
||||
with self.assertRaises(IOError):
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# invalid number of subbands, bad marker ID
|
||||
warnings.simplefilter("ignore")
|
||||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self):
|
||||
# This test actually passes in 1.5, but produces unpleasant warning
|
||||
# messages that cannot be turned off?
|
||||
relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k'
|
||||
jfile = opj_data_file(relpath)
|
||||
if glymur.version.openjpeg_version_tuple[0] < 2:
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Incorrect warning issued about tile parts.
|
||||
warnings.simplefilter("ignore")
|
||||
Jp2k(jfile).read()
|
||||
else:
|
||||
Jp2k(jfile).read()
|
||||
|
|
|
|||
|
|
@ -31,14 +31,13 @@ import re
|
|||
import sys
|
||||
import unittest
|
||||
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
|
||||
from glymur import Jp2k
|
||||
import glymur
|
||||
|
||||
from .fixtures import OPJ_DATA_ROOT
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file
|
||||
|
||||
|
||||
|
|
@ -56,11 +55,11 @@ class TestSuite2point1(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_text_GBR_jp2_29_decode(self):
|
||||
jfile = opj_data_file('input/nonregression/text_GBR.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# brand is 'jp2 ', but has any icc profile.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(jfile)
|
||||
jp2.read()
|
||||
self.assertTrue(True)
|
||||
|
|
@ -85,32 +84,32 @@ class TestSuite2point1(unittest.TestCase):
|
|||
Jp2k(jfile).read()
|
||||
self.assertTrue(True)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self):
|
||||
f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2'
|
||||
jfile = opj_data_file(f)
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Invalid number of resolutions.
|
||||
warnings.simplefilter("ignore")
|
||||
j = Jp2k(jfile)
|
||||
with self.assertRaises(IOError):
|
||||
j.read()
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self):
|
||||
relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2'
|
||||
jfile = opj_data_file(relpath)
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Invalid number of tiles.
|
||||
warnings.simplefilter("ignore")
|
||||
j = Jp2k(jfile)
|
||||
with self.assertRaises(IOError):
|
||||
j.read()
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self):
|
||||
relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2'
|
||||
jfile = opj_data_file(relpath)
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Invalid subsampling value
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertRaises(IOError):
|
||||
Jp2k(jfile).read()
|
||||
|
||||
|
|
@ -152,14 +151,14 @@ class TestSuite2point1(unittest.TestCase):
|
|||
odata = jp2k.read(rlevel=1)
|
||||
np.testing.assert_array_equal(tdata, odata[64:128, 256:320])
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_NR_DEC_jp2_36_decode(self):
|
||||
lst = ('input',
|
||||
'nonregression',
|
||||
'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2')
|
||||
jfile = opj_data_file('/'.join(lst))
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Invalid component number.
|
||||
warnings.simplefilter("ignore")
|
||||
j = Jp2k(jfile)
|
||||
with self.assertRaises(IOError):
|
||||
j.read()
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -13,7 +13,6 @@ import re
|
|||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
try:
|
||||
|
|
@ -24,6 +23,7 @@ except ImportError:
|
|||
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 .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
|
||||
from glymur import Jp2k
|
||||
import glymur
|
||||
|
|
@ -76,13 +76,13 @@ class TestSuiteNegative(unittest.TestCase):
|
|||
jp2k.get_codestream(header_only=False)
|
||||
self.assertTrue(True)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_nr_illegalclrtransform(self):
|
||||
"""EOC marker is bad"""
|
||||
relpath = 'input/nonregression/illegalcolortransform.j2k'
|
||||
jfile = opj_data_file(relpath)
|
||||
jp2k = Jp2k(jfile)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore')
|
||||
with self.assertWarns(UserWarning):
|
||||
codestream = jp2k.get_codestream(header_only=False)
|
||||
|
||||
# Verify that the last segment returned in the codestream is SOD,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import re
|
|||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
try:
|
||||
|
|
@ -22,50 +21,13 @@ except ImportError:
|
|||
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
|
||||
from .fixtures import OPJ_DATA_ROOT, NO_SKIMAGE_FREEIMAGE_SUPPORT
|
||||
from .fixtures import opj_data_file
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
from . import fixtures
|
||||
|
||||
from glymur import Jp2k
|
||||
import glymur
|
||||
|
||||
@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)''',
|
||||
glymur.version.openjpeg_version) is not None,
|
||||
"Uses features not supported until 2.0.1")
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class TestSuiteWriteCinema(unittest.TestCase):
|
||||
"""Tests for writing with openjp2 backend.
|
||||
|
||||
These tests either roughly correspond with those tests with similar names
|
||||
in the OpenJPEG test suite or are closely associated.
|
||||
"""
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_cinema2K_with_others(self):
|
||||
"""Can't specify cinema2k with any other options."""
|
||||
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_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, cratios=[200, 100, 50])
|
||||
|
||||
def test_cinema4K_with_others(self):
|
||||
"""Can't specify cinema4k with any other options."""
|
||||
relfile = 'input/nonregression/ElephantDream_4K.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, cinema4k=True, cratios=[200, 100, 50])
|
||||
class CinemaBase(unittest.TestCase):
|
||||
|
||||
def check_cinema4k_codestream(self, codestream, image_size):
|
||||
"""Common out for cinema2k tests."""
|
||||
|
|
@ -151,83 +113,137 @@ class TestSuiteWriteCinema(unittest.TestCase):
|
|||
|
||||
|
||||
|
||||
@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)''',
|
||||
glymur.version.openjpeg_version) is not None,
|
||||
"Uses features not supported until 2.0.1")
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class WriteCinema(CinemaBase):
|
||||
"""Tests for writing with openjp2 backend.
|
||||
|
||||
These tests either roughly correspond with those tests with similar names
|
||||
in the OpenJPEG test suite or are closely associated.
|
||||
"""
|
||||
def test_cinema2K_with_others(self):
|
||||
"""Can't specify cinema2k with any other options."""
|
||||
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_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, cratios=[200, 100, 50])
|
||||
|
||||
def test_cinema4K_with_others(self):
|
||||
"""Can't specify cinema4k with any other options."""
|
||||
relfile = 'input/nonregression/ElephantDream_4K.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, cinema4k=True, cratios=[200, 100, 50])
|
||||
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
@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)''',
|
||||
glymur.version.openjpeg_version) is not None,
|
||||
"Uses features not supported until 2.0.1")
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
class WriteCinemaWarns(CinemaBase):
|
||||
"""Tests for writing with openjp2 backend.
|
||||
|
||||
These tests either roughly correspond with those tests with similar names
|
||||
in the OpenJPEG test suite or are closely associated. These tests issue
|
||||
warnings.
|
||||
"""
|
||||
def test_NR_ENC_ElephantDream_4K_tif_21_encode(self):
|
||||
relfile = 'input/nonregression/ElephantDream_4K.tif'
|
||||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
with warnings.catch_warnings():
|
||||
# Just turn off warnings.
|
||||
warnings.simplefilter("ignore")
|
||||
regex = 'OpenJPEG library warning: JPEG 2000 Profile-3 and 4 '
|
||||
regex += '(2k/4k dc profile) requires'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
j.write(data, cinema4k=True)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.check_cinema4k_codestream(codestream, (4096, 2160))
|
||||
|
||||
|
||||
def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_19_encode(self):
|
||||
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif'
|
||||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cinema2k=48)
|
||||
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
|
||||
j.write(data, cinema2k=48)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.check_cinema2k_codestream(codestream, (2048, 857))
|
||||
|
||||
|
||||
def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_20_encode(self):
|
||||
relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif'
|
||||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cinema2k=48)
|
||||
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
|
||||
j.write(data, cinema2k=48)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.check_cinema2k_codestream(codestream, (2048, 1080))
|
||||
|
||||
|
||||
def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_17_encode(self):
|
||||
relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif'
|
||||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cinema2k=24)
|
||||
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
|
||||
j.write(data, cinema2k=24)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.check_cinema2k_codestream(codestream, (2048, 1080))
|
||||
|
||||
|
||||
def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_16_encode(self):
|
||||
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif'
|
||||
infile = opj_data_file(relfile)
|
||||
data = skimage.io.imread(infile)
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
j.write(data, cinema2k=24)
|
||||
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
|
||||
# OpenJPEG library warning: The desired maximum codestream
|
||||
# size has limited at least one of the desired quality layers
|
||||
j.write(data, cinema2k=24)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.check_cinema2k_codestream(codestream, (2048, 857))
|
||||
|
||||
|
||||
def test_NR_ENC_X_4_2K_24_185_CBR_WB_000_tif_18_encode(self):
|
||||
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 warnings.catch_warnings():
|
||||
# Just turn off warnings.
|
||||
warnings.simplefilter("ignore")
|
||||
regex = 'OpenJPEG library warning'
|
||||
with self.assertWarnsRegex(UserWarning, regex):
|
||||
# OpenJPEG library warning: The desired maximum codestream
|
||||
# size has limited at least one of the desired quality layers
|
||||
j.write(data, cinema2k=48)
|
||||
|
||||
codestream = j.get_codestream()
|
||||
self.check_cinema2k_codestream(codestream, (1998, 1080))
|
||||
|
||||
|
||||
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
|
||||
"Cannot read input image without scikit-image/freeimage")
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import re
|
|||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import warnings
|
||||
import unittest
|
||||
|
||||
if sys.hexversion < 0x03000000:
|
||||
|
|
@ -34,6 +33,7 @@ import glymur
|
|||
from glymur import Jp2k, command_line
|
||||
from . import fixtures
|
||||
from .fixtures import OPJ_DATA_ROOT, opj_data_file
|
||||
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
|
||||
from .fixtures import text_gbr_27, text_gbr_33, text_gbr_34
|
||||
|
||||
|
||||
|
|
@ -71,6 +71,7 @@ class TestPrinting(unittest.TestCase):
|
|||
|
||||
self.assertTrue(True)
|
||||
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
def test_unknown_superbox(self):
|
||||
"""Verify that we can handle an unknown superbox."""
|
||||
with tempfile.NamedTemporaryFile(suffix='.jpx') as tfile:
|
||||
|
|
@ -87,9 +88,7 @@ class TestPrinting(unittest.TestCase):
|
|||
tfile.write(write_buffer)
|
||||
tfile.flush()
|
||||
|
||||
with warnings.catch_warnings():
|
||||
# Suppress the warning about the unrecognized box.
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
jpx = Jp2k(tfile.name)
|
||||
|
||||
glymur.set_printoptions(short=True)
|
||||
|
|
@ -645,48 +644,6 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.cinema2k_profile)
|
||||
|
||||
def test_invalid_colorspace(self):
|
||||
"""An invalid colorspace shouldn't cause an error."""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2')
|
||||
with warnings.catch_warnings():
|
||||
# Bad compatibility list item and bad colorspace warnings. Just
|
||||
# suppress the warnings.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2)
|
||||
|
||||
def test_bad_rsiz(self):
|
||||
"""Should still be able to print if rsiz is bad, issue196"""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
j = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j)
|
||||
|
||||
def test_bad_wavelet_transform(self):
|
||||
"""Should still be able to print if wavelet xform is bad, issue195"""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_10025.jp2')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2)
|
||||
|
||||
def test_invalid_progression_order(self):
|
||||
"""Should still be able to print even if prog order is invalid."""
|
||||
jfile = opj_data_file('input/nonregression/2977.pdf.asan.67.2198.jp2')
|
||||
with warnings.catch_warnings():
|
||||
# Multiple warnings, actually.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(jfile)
|
||||
codestream = jp2.get_codestream()
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(codestream.segment[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.issue_186_progression_order)
|
||||
|
||||
def test_crg(self):
|
||||
"""verify printing of CRG segment"""
|
||||
filename = opj_data_file('input/conformance/p0_03.j2k')
|
||||
|
|
@ -836,46 +793,6 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_xml(self):
|
||||
"""verify printing of XML box"""
|
||||
filename = opj_data_file('input/conformance/file1.jp2')
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.file1_xml)
|
||||
|
||||
def test_channel_definition(self):
|
||||
"""verify printing of cdef box"""
|
||||
filename = opj_data_file('input/conformance/file2.jp2')
|
||||
with warnings.catch_warnings():
|
||||
# Bad compatibility list item.
|
||||
warnings.simplefilter("ignore")
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
lines = ['Channel Definition Box (cdef) @ (81, 28)',
|
||||
' Channel 0 (color) ==> (3)',
|
||||
' Channel 1 (color) ==> (2)',
|
||||
' Channel 2 (color) ==> (1)']
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_component_mapping(self):
|
||||
"""verify printing of cmap box"""
|
||||
filename = opj_data_file('input/conformance/file9.jp2')
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
lines = ['Component Mapping Box (cmap) @ (848, 20)',
|
||||
' Component 0 ==> palette column 0',
|
||||
' Component 0 ==> palette column 1',
|
||||
' Component 0 ==> palette column 2']
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_componentmapping_box_alpha(self):
|
||||
"""Verify __repr__ method on cmap box."""
|
||||
cmap = glymur.jp2box.ComponentMappingBox(component_index=(0, 0, 0),
|
||||
|
|
@ -887,27 +804,6 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
self.assertEqual(newbox.mapping_type, (1, 1, 1))
|
||||
self.assertEqual(newbox.palette_index, (0, 1, 2))
|
||||
|
||||
def test_palette7(self):
|
||||
"""verify printing of pclr box"""
|
||||
filename = opj_data_file('input/conformance/file9.jp2')
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[1])
|
||||
actual = fake_out.getvalue().strip()
|
||||
lines = ['Palette Box (pclr) @ (66, 782)',
|
||||
' Size: (256 x 3)']
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_rreq(self):
|
||||
"""verify printing of reader requirements box"""
|
||||
filename = opj_data_file('input/nonregression/text_GBR.jp2')
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.text_GBR_rreq)
|
||||
|
||||
def test_differing_subsamples(self):
|
||||
"""verify printing of SIZ with different subsampling... Issue 86."""
|
||||
filename = opj_data_file('input/conformance/p0_05.j2k')
|
||||
|
|
@ -929,10 +825,133 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
@unittest.skipIf(OPJ_DATA_ROOT is None,
|
||||
"OPJ_DATA_ROOT environment variable not set")
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
|
||||
class TestPrintingOpjDataRootWarns(unittest.TestCase):
|
||||
"""
|
||||
Tests for verifying printing. restricted to OPJ_DATA_ROOT files.
|
||||
|
||||
These tests issue warnings.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.jpxfile = glymur.data.jpxfile()
|
||||
self.jp2file = glymur.data.nemo()
|
||||
self.j2kfile = glymur.data.goodstuff()
|
||||
|
||||
# Reset printoptions for every test.
|
||||
glymur.set_printoptions(short=False, xml=True, codestream=True)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_invalid_colorspace(self):
|
||||
"""An invalid colorspace shouldn't cause an error."""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2)
|
||||
|
||||
@unittest.skip("unexplained failure")
|
||||
def test_bad_rsiz(self):
|
||||
"""Should still be able to print if rsiz is bad, issue196"""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
j = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j)
|
||||
|
||||
def test_bad_wavelet_transform(self):
|
||||
"""Should still be able to print if wavelet xform is bad, issue195"""
|
||||
filename = opj_data_file('input/nonregression/edf_c2_10025.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2)
|
||||
|
||||
def test_invalid_progression_order(self):
|
||||
"""Should still be able to print even if prog order is invalid."""
|
||||
jfile = opj_data_file('input/nonregression/2977.pdf.asan.67.2198.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
# Multiple warnings, actually.
|
||||
jp2 = Jp2k(jfile)
|
||||
codestream = jp2.get_codestream()
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(codestream.segment[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.issue_186_progression_order)
|
||||
|
||||
def test_xml(self):
|
||||
"""verify printing of XML box"""
|
||||
filename = opj_data_file('input/conformance/file1.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.file1_xml)
|
||||
|
||||
def test_channel_definition(self):
|
||||
"""verify printing of cdef box"""
|
||||
filename = opj_data_file('input/conformance/file2.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
# Bad compatibility list item.
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
lines = ['Channel Definition Box (cdef) @ (81, 28)',
|
||||
' Channel 0 (color) ==> (3)',
|
||||
' Channel 1 (color) ==> (2)',
|
||||
' Channel 2 (color) ==> (1)']
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_component_mapping(self):
|
||||
"""verify printing of cmap box"""
|
||||
filename = opj_data_file('input/conformance/file9.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
lines = ['Component Mapping Box (cmap) @ (848, 20)',
|
||||
' Component 0 ==> palette column 0',
|
||||
' Component 0 ==> palette column 1',
|
||||
' Component 0 ==> palette column 2']
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_palette7(self):
|
||||
"""verify printing of pclr box"""
|
||||
filename = opj_data_file('input/conformance/file9.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[1])
|
||||
actual = fake_out.getvalue().strip()
|
||||
lines = ['Palette Box (pclr) @ (66, 782)',
|
||||
' Size: (256 x 3)']
|
||||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_rreq(self):
|
||||
"""verify printing of reader requirements box"""
|
||||
filename = opj_data_file('input/nonregression/text_GBR.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2])
|
||||
actual = fake_out.getvalue().strip()
|
||||
self.assertEqual(actual, fixtures.text_GBR_rreq)
|
||||
|
||||
def test_palette_box(self):
|
||||
"""Verify that palette (pclr) boxes are printed without error."""
|
||||
filename = opj_data_file('input/conformance/file9.jp2')
|
||||
j = glymur.Jp2k(filename)
|
||||
with self.assertWarns(UserWarning):
|
||||
j = glymur.Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(j.box[2].box[1])
|
||||
actual = fake_out.getvalue().strip()
|
||||
|
|
@ -946,9 +965,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
# ICC profiles may be used in JP2, but the approximation field should
|
||||
# be zero unless we have jpx. This file does both.
|
||||
filename = opj_data_file('input/nonregression/text_GBR.jp2')
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# brand is 'jp2 ', but has any icc profile.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(filename)
|
||||
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
|
|
@ -966,7 +984,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
def test_uuid(self):
|
||||
"""verify printing of UUID box"""
|
||||
filename = opj_data_file('input/nonregression/text_GBR.jp2')
|
||||
jp2 = Jp2k(filename)
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2.box[4])
|
||||
|
|
@ -984,9 +1003,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
# Format strings like %d were showing up in the output.
|
||||
filename = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2')
|
||||
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Ignore warning about bad pclr box.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2.box[3].box[3])
|
||||
|
|
@ -996,9 +1014,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
def test_issue183(self):
|
||||
filename = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
|
||||
|
||||
with warnings.catch_warnings():
|
||||
with self.assertWarns(UserWarning):
|
||||
# Ignore warning about bad pclr box.
|
||||
warnings.simplefilter("ignore")
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
print(jp2.box[2].box[1])
|
||||
|
|
@ -1010,8 +1027,7 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
|
|||
filename = opj_data_file(os.path.join('input',
|
||||
'nonregression',
|
||||
'issue171.jp2'))
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
with self.assertWarns(UserWarning):
|
||||
jp2 = Jp2k(filename)
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
# No need to verify, it's enough that we don't error out.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue