progress towards removing 2.x warning infrastructure

This commit is contained in:
jevans 2014-09-17 07:41:33 -04:00
commit 60d24aa2e6
16 changed files with 107 additions and 205 deletions

View file

@ -11,7 +11,6 @@ import os
import re import re
import sys import sys
import tempfile import tempfile
import warnings
import unittest import unittest
@ -41,8 +40,7 @@ class TestCallbacks(unittest.TestCase):
def test_info_callback_on_write(self): def test_info_callback_on_write(self):
"""Verify messages printed when writing an image in verbose mode.""" """Verify messages printed when writing an image in verbose mode."""
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
tiledata = j.read(tile=0) tiledata = j.read(tile=0)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
j = glymur.Jp2k(tfile.name, 'wb') j = glymur.Jp2k(tfile.name, 'wb')

View file

@ -13,7 +13,6 @@ import struct
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
from glymur import Jp2k from glymur import Jp2k
import glymur import glymur

View file

@ -16,7 +16,6 @@ import os
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
if sys.hexversion <= 0x03030000: if sys.hexversion <= 0x03030000:
from mock import patch from mock import patch
@ -84,11 +83,9 @@ class TestSuite(unittest.TestCase):
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}): with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
# Misconfigured new configuration file should # Misconfigured new configuration file should
# be rejected. # be rejected.
with warnings.catch_warnings(record=True) as w: regex = 'could not be loaded'
warnings.simplefilter('always') with self.assertWarnsRegex(UserWarning, regex):
imp.reload(glymur.lib.openjp2) 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 @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and

View file

@ -12,7 +12,6 @@ import struct
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
import six import six

View file

@ -9,7 +9,6 @@ import datetime
import os import os
import sys import sys
import unittest import unittest
import warnings
import numpy as np import numpy as np
@ -31,9 +30,8 @@ class TestICC(unittest.TestCase):
def test_file5(self): def test_file5(self):
"""basic ICC profile""" """basic ICC profile"""
filename = opj_data_file('input/conformance/file5.jp2') 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. # The file has a bad compatibility list entry. Not important here.
warnings.simplefilter("ignore")
j = Jp2k(filename) j = Jp2k(filename)
profile = j.box[3].box[1].icc_profile profile = j.box[3].box[1].icc_profile
self.assertEqual(profile['Size'], 546) self.assertEqual(profile['Size'], 546)

View file

@ -23,7 +23,6 @@ import tempfile
import uuid import uuid
from uuid import UUID from uuid import UUID
import unittest import unittest
import warnings
import lxml.etree as ET import lxml.etree as ET
import numpy as np import numpy as np
@ -365,12 +364,9 @@ class TestChannelDefinition(unittest.TestCase):
channel_type = (COLOR, COLOR, 3) channel_type = (COLOR, COLOR, 3)
association = (RED, GREEN, BLUE) association = (RED, GREEN, BLUE)
with warnings.catch_warnings(record=True) as w: with self.assertWarns(UserWarning):
warnings.simplefilter('always')
glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type, glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
association=association) association=association)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category, UserWarning))
def test_wrong_lengths(self): def test_wrong_lengths(self):
"""Should reject if not all of index, channel_type, association the """Should reject if not all of index, channel_type, association the
@ -378,12 +374,9 @@ class TestChannelDefinition(unittest.TestCase):
""" """
channel_type = (COLOR, COLOR) channel_type = (COLOR, COLOR)
association = (RED, GREEN, BLUE) association = (RED, GREEN, BLUE)
with warnings.catch_warnings(record=True) as w: with self.assertWarns(UserWarning):
warnings.simplefilter('always')
glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type, glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type,
association=association) association=association)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category, UserWarning))
class TestFileTypeBox(unittest.TestCase): class TestFileTypeBox(unittest.TestCase):
@ -397,8 +390,7 @@ class TestFileTypeBox(unittest.TestCase):
def test_brand_unknown(self): def test_brand_unknown(self):
"""A ftyp box brand must be 'jp2 ' or 'jpx '.""" """A ftyp box brand must be 'jp2 ' or 'jpx '."""
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
ftyp = glymur.jp2box.FileTypeBox(brand='jp3') ftyp = glymur.jp2box.FileTypeBox(brand='jp3')
with self.assertRaises(IOError): with self.assertRaises(IOError):
with tempfile.TemporaryFile() as tfile: with tempfile.TemporaryFile() as tfile:
@ -406,9 +398,8 @@ class TestFileTypeBox(unittest.TestCase):
def test_cl_entry_unknown(self): def test_cl_entry_unknown(self):
"""A ftyp box cl list can only contain 'jp2 ', 'jpx ', or 'jpxb'.""" """A ftyp box cl list can only contain 'jp2 ', 'jpx ', or 'jpxb'."""
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Bad compatibility list item. # Bad compatibility list item.
warnings.simplefilter("ignore")
ftyp = glymur.jp2box.FileTypeBox(compatibility_list=['jp3']) ftyp = glymur.jp2box.FileTypeBox(compatibility_list=['jp3'])
with self.assertRaises(IOError): with self.assertRaises(IOError):
with tempfile.TemporaryFile() as tfile: with tempfile.TemporaryFile() as tfile:
@ -481,39 +472,29 @@ class TestColourSpecificationBox(unittest.TestCase):
def test_colr_with_cspace_and_icc(self): def test_colr_with_cspace_and_icc(self):
"""Colour specification boxes can't have both.""" """Colour specification boxes can't have both."""
with warnings.catch_warnings(record=True) as w: regex = 'Colorspace and icc_profile cannot both be set'
warnings.simplefilter('always') with self.assertWarnsRegex(UserWarning, regex):
colorspace = glymur.core.SRGB colorspace = glymur.core.SRGB
rawb = b'\x01\x02\x03\x04' rawb = b'\x01\x02\x03\x04'
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace, glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
icc_profile=rawb) 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))
def test_colr_with_bad_method(self): def test_colr_with_bad_method(self):
"""colr must have a valid method field""" """colr must have a valid method field"""
colorspace = glymur.core.SRGB colorspace = glymur.core.SRGB
method = -1 method = -1
with warnings.catch_warnings(record=True) as w: regex = 'Invalid method'
warnings.simplefilter('always') with self.assertWarnsRegex(UserWarning, regex):
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace, glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
method=method) method=method)
self.assertTrue(issubclass(w[0].category,UserWarning))
msg = 'Invalid method'
self.assertTrue(msg in str(w[0].message))
def test_colr_with_bad_approx(self): def test_colr_with_bad_approx(self):
"""colr should have a valid approximation field""" """colr should have a valid approximation field"""
colorspace = glymur.core.SRGB colorspace = glymur.core.SRGB
approx = -1 approx = -1
with warnings.catch_warnings(record=True) as w: with self.assertWarnsRegex(UserWarning, 'Invalid approximation'):
warnings.simplefilter('always')
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace, glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
approximation=approx) 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): def test_colr_with_bad_color(self):
"""colr must have a valid color, strange as though that may sound.""" """colr must have a valid color, strange as though that may sound."""
@ -542,24 +523,18 @@ class TestPaletteBox(unittest.TestCase):
palette = np.array([[255, 0, 255], [0, 255, 0]], dtype=np.uint8) palette = np.array([[255, 0, 255], [0, 255, 0]], dtype=np.uint8)
bps = (8, 8, 8) bps = (8, 8, 8)
signed = (False, False) signed = (False, False)
with warnings.catch_warnings(record=True) as w: with self.assertWarns(UserWarning):
warnings.simplefilter('always')
pclr = glymur.jp2box.PaletteBox(palette, bits_per_component=bps, pclr = glymur.jp2box.PaletteBox(palette, bits_per_component=bps,
signed=signed) signed=signed)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category, UserWarning))
def test_mismatched_signed_palette(self): def test_mismatched_signed_palette(self):
"""bitdepth and signed arguments must have equal length""" """bitdepth and signed arguments must have equal length"""
palette = np.array([[255, 0, 255], [0, 255, 0]], dtype=np.uint8) palette = np.array([[255, 0, 255], [0, 255, 0]], dtype=np.uint8)
bps = (8, 8, 8, 8) bps = (8, 8, 8, 8)
signed = (False, False, False, False) signed = (False, False, False, False)
with warnings.catch_warnings(record=True) as w: with self.assertWarns(UserWarning):
warnings.simplefilter('always')
pclr = glymur.jp2box.PaletteBox(palette, bits_per_component=bps, pclr = glymur.jp2box.PaletteBox(palette, bits_per_component=bps,
signed=signed) signed=signed)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category, UserWarning))
def test_writing_with_different_bitdepths(self): def test_writing_with_different_bitdepths(self):
"""Bitdepths must be the same when writing.""" """Bitdepths must be the same when writing."""

View file

@ -9,7 +9,6 @@ import struct
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
import lxml.etree as ET import lxml.etree as ET
@ -311,11 +310,8 @@ class TestJPXWrap(unittest.TestCase):
boxes = [jp2.box[idx] for idx in [0, 1, 2, 4]] boxes = [jp2.box[idx] for idx in [0, 1, 2, 4]]
ftyp = glymur.jp2box.FileTypeBox() ftyp = glymur.jp2box.FileTypeBox()
with warnings.catch_warnings(record=True) as w: with self.assertWarns(UserWarning):
warnings.simplefilter('always')
dref = glymur.jp2box.DataReferenceBox([ftyp]) 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. # Try to get around it by appending the ftyp box after creation.
dref = glymur.jp2box.DataReferenceBox() dref = glymur.jp2box.DataReferenceBox()
@ -438,8 +434,7 @@ class TestJPX(unittest.TestCase):
offset = [89] offset = [89]
length = [1132288] length = [1132288]
reference = [0, 0] reference = [0, 0]
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
flst = glymur.jp2box.FragmentListBox(offset, length, reference) flst = glymur.jp2box.FragmentListBox(offset, length, reference)
with self.assertRaises(IOError): with self.assertRaises(IOError):
with tempfile.TemporaryFile() as tfile: with tempfile.TemporaryFile() as tfile:
@ -450,8 +445,7 @@ class TestJPX(unittest.TestCase):
offset = [0] offset = [0]
length = [1132288] length = [1132288]
reference = [0] reference = [0]
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
flst = glymur.jp2box.FragmentListBox(offset, length, reference) flst = glymur.jp2box.FragmentListBox(offset, length, reference)
with self.assertRaises((IOError, OSError)): with self.assertRaises((IOError, OSError)):
with tempfile.TemporaryFile() as tfile: with tempfile.TemporaryFile() as tfile:
@ -462,8 +456,7 @@ class TestJPX(unittest.TestCase):
offset = [89] offset = [89]
length = [0] length = [0]
reference = [0] reference = [0]
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
flst = glymur.jp2box.FragmentListBox(offset, length, reference) flst = glymur.jp2box.FragmentListBox(offset, length, reference)
with self.assertRaises(IOError): with self.assertRaises(IOError):
with tempfile.TemporaryFile() as tfile: with tempfile.TemporaryFile() as tfile:
@ -471,9 +464,7 @@ class TestJPX(unittest.TestCase):
def test_ftbl_boxes_empty(self): def test_ftbl_boxes_empty(self):
"""A fragment table box must have at least one child box.""" """A fragment table box must have at least one child box."""
with warnings.catch_warnings(): ftbl = glymur.jp2box.FragmentTableBox()
warnings.simplefilter("ignore")
ftbl = glymur.jp2box.FragmentTableBox()
with self.assertRaises(IOError): with self.assertRaises(IOError):
with tempfile.TemporaryFile() as tfile: with tempfile.TemporaryFile() as tfile:
ftbl.write(tfile) ftbl.write(tfile)

View file

@ -17,7 +17,6 @@ import struct
import sys import sys
import tempfile import tempfile
import uuid import uuid
import warnings
if sys.hexversion < 0x02070000: if sys.hexversion < 0x02070000:
import unittest2 as unittest import unittest2 as unittest
@ -107,12 +106,8 @@ class TestUUIDExif(unittest.TestCase):
tfile.write(struct.pack('<HHI4s', 171, 2, 3, b'HTC\x00')) tfile.write(struct.pack('<HHI4s', 171, 2, 3, b'HTC\x00'))
tfile.flush() tfile.flush()
with warnings.catch_warnings(record=True) as w: with self.assertWarnsRegex(UserWarning, 'Unrecognized Exif tag'):
warnings.simplefilter('always')
j = glymur.Jp2k(tfile.name) 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): def test_bad_tag_datatype(self):
"""Only certain datatypes are allowable""" """Only certain datatypes are allowable"""
@ -136,12 +131,8 @@ class TestUUIDExif(unittest.TestCase):
tfile.write(struct.pack('<HHI4s', 271, 2000, 3, b'HTC\x00')) tfile.write(struct.pack('<HHI4s', 271, 2000, 3, b'HTC\x00'))
tfile.flush() tfile.flush()
with warnings.catch_warnings(record=True) as w: with self.assertWarnsRegex(UserWarning, 'Invalid TIFF tag'):
warnings.simplefilter('always')
j = glymur.Jp2k(tfile.name) 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') self.assertEqual(j.box[-1].box_id, 'uuid')
@ -167,20 +158,11 @@ class TestUUIDExif(unittest.TestCase):
tfile.write(struct.pack('<HHI4s', 271, 2, 3, b'HTC\x00')) tfile.write(struct.pack('<HHI4s', 271, 2, 3, b'HTC\x00'))
tfile.flush() tfile.flush()
with warnings.catch_warnings(record=True) as w: regex = 'The byte order indication in the TIFF header '
warnings.simplefilter('always') with self.assertWarnsRegex(UserWarning, regex):
j = glymur.Jp2k(tfile.name) jp2 = 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))
self.assertEqual(j.box[-1].box_id, 'uuid') self.assertEqual(jp2.box[-1].box_id, 'uuid')
def test_big_endian(self): def test_big_endian(self):
"""Verify read of big-endian IFD.""" """Verify read of big-endian IFD."""

View file

@ -20,7 +20,6 @@ import struct
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
if sys.hexversion < 0x03000000: if sys.hexversion < 0x03000000:
from StringIO import StringIO from StringIO import StringIO
@ -269,8 +268,7 @@ class TestBadButRecoverableXmlFile(unittest.TestCase):
def test_recover_from_bad_xml(self): def test_recover_from_bad_xml(self):
"""Should be able to recover info from xml box with bad xml.""" """Should be able to recover info from xml box with bad xml."""
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
jp2 = Jp2k(self._bad_xml_file) jp2 = Jp2k(self._bad_xml_file)
self.assertEqual(jp2.box[3].box_id, 'xml ') self.assertEqual(jp2.box[3].box_id, 'xml ')

View file

@ -21,8 +21,6 @@ import unittest
import uuid import uuid
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
import warnings
import numpy as np import numpy as np
import pkg_resources import pkg_resources
@ -1044,8 +1042,7 @@ class TestJp2k_2_1(unittest.TestCase):
tfile.write(data[offset+59:]) tfile.write(data[offset+59:])
#tfile.write(data[3186:]) #tfile.write(data[3186:])
tfile.flush() tfile.flush()
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
j = Jp2k(tfile.name) j = Jp2k(tfile.name)
regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+ regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
Invalid\svalues\sfor\scomp\s=\s0\s+ Invalid\svalues\sfor\scomp\s=\s0\s+
@ -1074,9 +1071,7 @@ class TestParsing(unittest.TestCase):
"""Should not warn if RSIZ when parsing is turned off.""" """Should not warn if RSIZ when parsing is turned off."""
filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2') filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2')
glymur.set_parseoptions(codestream=False) glymur.set_parseoptions(codestream=False)
with warnings.catch_warnings(record=True) as w: j = Jp2k(filename)
j = Jp2k(filename)
self.assertEqual(len(w), 0)
glymur.set_parseoptions(codestream=True) glymur.set_parseoptions(codestream=True)
with self.assertWarnsRegex(UserWarning, 'Invalid profile'): with self.assertWarnsRegex(UserWarning, 'Invalid profile'):
@ -1194,9 +1189,8 @@ class TestJp2kOpjDataRoot(unittest.TestCase):
# This file has the components physically reversed. The cmap box # This file has the components physically reversed. The cmap box
# tells the decoder how to order them, but this flag prevents that. # tells the decoder how to order them, but this flag prevents that.
filename = opj_data_file('input/conformance/file2.jp2') 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. # The file has a bad compatibility list entry. Not important here.
warnings.simplefilter("ignore")
j = Jp2k(filename) j = Jp2k(filename)
ycbcr = j.read() ycbcr = j.read()
crcby = j.read(ignore_pclr_cmap_cdef=True) crcby = j.read(ignore_pclr_cmap_cdef=True)

View file

@ -31,8 +31,6 @@ import re
import sys import sys
import unittest import unittest
import warnings
import numpy as np import numpy as np
from glymur import Jp2k from glymur import Jp2k
@ -206,16 +204,16 @@ class TestSuite(unittest.TestCase):
def test_ETS_JP2_file1(self): def test_ETS_JP2_file1(self):
jfile = opj_data_file('input/conformance/file1.jp2') jfile = opj_data_file('input/conformance/file1.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Bad compatibility list item. # Bad compatibility list item.
warnings.simplefilter("ignore")
jp2k = Jp2k(jfile) jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (512, 768, 3)) self.assertEqual(jpdata.shape, (512, 768, 3))
def test_ETS_JP2_file2(self): def test_ETS_JP2_file2(self):
jfile = opj_data_file('input/conformance/file2.jp2') jfile = opj_data_file('input/conformance/file2.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (640, 480, 3)) self.assertEqual(jpdata.shape, (640, 480, 3))
@ -223,7 +221,8 @@ class TestSuite(unittest.TestCase):
"Functionality not implemented for 1.x") "Functionality not implemented for 1.x")
def test_ETS_JP2_file3(self): def test_ETS_JP2_file3(self):
jfile = opj_data_file('input/conformance/file3.jp2') jfile = opj_data_file('input/conformance/file3.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read_bands() jpdata = jp2k.read_bands()
self.assertEqual(jpdata[0].shape, (640, 480)) self.assertEqual(jpdata[0].shape, (640, 480))
self.assertEqual(jpdata[1].shape, (320, 240)) self.assertEqual(jpdata[1].shape, (320, 240))
@ -231,50 +230,53 @@ class TestSuite(unittest.TestCase):
def test_ETS_JP2_file4(self): def test_ETS_JP2_file4(self):
jfile = opj_data_file('input/conformance/file4.jp2') jfile = opj_data_file('input/conformance/file4.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (512, 768)) self.assertEqual(jpdata.shape, (512, 768))
def test_ETS_JP2_file5(self): def test_ETS_JP2_file5(self):
jfile = opj_data_file('input/conformance/file5.jp2') 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. # There's a warning for an unknown compatibility entry.
# Ignore it here. # Ignore it here.
warnings.simplefilter("ignore")
jp2k = Jp2k(jfile) jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (512, 768, 3)) self.assertEqual(jpdata.shape, (512, 768, 3))
def test_ETS_JP2_file6(self): def test_ETS_JP2_file6(self):
jfile = opj_data_file('input/conformance/file6.jp2') jfile = opj_data_file('input/conformance/file6.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (512, 768)) self.assertEqual(jpdata.shape, (512, 768))
def test_ETS_JP2_file7(self): def test_ETS_JP2_file7(self):
jfile = opj_data_file('input/conformance/file7.jp2') jfile = opj_data_file('input/conformance/file7.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (640, 480, 3)) self.assertEqual(jpdata.shape, (640, 480, 3))
def test_ETS_JP2_file8(self): def test_ETS_JP2_file8(self):
jfile = opj_data_file('input/conformance/file8.jp2') jfile = opj_data_file('input/conformance/file8.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (400, 700)) self.assertEqual(jpdata.shape, (400, 700))
def test_ETS_JP2_file9(self): def test_ETS_JP2_file9(self):
jfile = opj_data_file('input/conformance/file9.jp2') jfile = opj_data_file('input/conformance/file9.jp2')
jp2k = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read() jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (512, 768, 3)) self.assertEqual(jpdata.shape, (512, 768, 3))
def test_NR_broken_jp2_dump(self): def test_NR_broken_jp2_dump(self):
jfile = opj_data_file('input/nonregression/broken.jp2') jfile = opj_data_file('input/nonregression/broken.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# colr box has bad length. # colr box has bad length.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
@ -476,15 +478,15 @@ class TestSuite(unittest.TestCase):
def test_NR_DEC_orb_blue_lin_jp2_25_decode(self): def test_NR_DEC_orb_blue_lin_jp2_25_decode(self):
jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') 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 # This file has an invalid ICC profile
warnings.simplefilter("ignore")
Jp2k(jfile).read() Jp2k(jfile).read()
self.assertTrue(True) self.assertTrue(True)
def test_NR_DEC_orb_blue_win_jp2_26_decode(self): def test_NR_DEC_orb_blue_win_jp2_26_decode(self):
jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2') jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2')
Jp2k(jfile).read() with self.assertWarns(UserWarning):
Jp2k(jfile).read()
self.assertTrue(True) self.assertTrue(True)
def test_NR_DEC_relax_jp2_27_decode(self): def test_NR_DEC_relax_jp2_27_decode(self):
@ -634,18 +636,16 @@ class TestSuite2point0(unittest.TestCase):
# Null pointer access # Null pointer access
jfile = opj_data_file('input/nonregression/broken2.jp2') jfile = opj_data_file('input/nonregression/broken2.jp2')
with self.assertRaises(IOError): with self.assertRaises(IOError):
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Invalid marker ID. # Invalid marker ID.
warnings.simplefilter("ignore")
Jp2k(jfile).read() Jp2k(jfile).read()
self.assertTrue(True) self.assertTrue(True)
def test_NR_DEC_broken4_jp2_7_decode(self): def test_NR_DEC_broken4_jp2_7_decode(self):
jfile = opj_data_file('input/nonregression/broken4.jp2') jfile = opj_data_file('input/nonregression/broken4.jp2')
with self.assertRaises(IOError): with self.assertRaises(IOError):
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# invalid number of subbands, bad marker ID # invalid number of subbands, bad marker ID
warnings.simplefilter("ignore")
Jp2k(jfile).read() Jp2k(jfile).read()
self.assertTrue(True) self.assertTrue(True)
@ -655,9 +655,8 @@ class TestSuite2point0(unittest.TestCase):
relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k'
jfile = opj_data_file(relpath) jfile = opj_data_file(relpath)
if glymur.version.openjpeg_version_tuple[0] < 2: if glymur.version.openjpeg_version_tuple[0] < 2:
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Incorrect warning issued about tile parts. # Incorrect warning issued about tile parts.
warnings.simplefilter("ignore")
Jp2k(jfile).read() Jp2k(jfile).read()
else: else:
Jp2k(jfile).read() Jp2k(jfile).read()

View file

@ -31,8 +31,6 @@ import re
import sys import sys
import unittest import unittest
import warnings
import numpy as np import numpy as np
from glymur import Jp2k from glymur import Jp2k
@ -58,9 +56,8 @@ class TestSuite2point1(unittest.TestCase):
def test_NR_DEC_text_GBR_jp2_29_decode(self): def test_NR_DEC_text_GBR_jp2_29_decode(self):
jfile = opj_data_file('input/nonregression/text_GBR.jp2') 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. # brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
jp2.read() jp2.read()
self.assertTrue(True) self.assertTrue(True)
@ -88,9 +85,8 @@ class TestSuite2point1(unittest.TestCase):
def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self): def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self):
f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2' f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2'
jfile = opj_data_file(f) jfile = opj_data_file(f)
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Invalid number of resolutions. # Invalid number of resolutions.
warnings.simplefilter("ignore")
j = Jp2k(jfile) j = Jp2k(jfile)
with self.assertRaises(IOError): with self.assertRaises(IOError):
j.read() j.read()
@ -98,9 +94,8 @@ class TestSuite2point1(unittest.TestCase):
def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self): def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self):
relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2' relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2'
jfile = opj_data_file(relpath) jfile = opj_data_file(relpath)
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Invalid number of tiles. # Invalid number of tiles.
warnings.simplefilter("ignore")
j = Jp2k(jfile) j = Jp2k(jfile)
with self.assertRaises(IOError): with self.assertRaises(IOError):
j.read() j.read()
@ -108,9 +103,8 @@ class TestSuite2point1(unittest.TestCase):
def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self): def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self):
relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2' relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2'
jfile = opj_data_file(relpath) jfile = opj_data_file(relpath)
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Invalid subsampling value # Invalid subsampling value
warnings.simplefilter("ignore")
with self.assertRaises(IOError): with self.assertRaises(IOError):
Jp2k(jfile).read() Jp2k(jfile).read()
@ -157,9 +151,8 @@ class TestSuite2point1(unittest.TestCase):
'nonregression', 'nonregression',
'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2') 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2')
jfile = opj_data_file('/'.join(lst)) jfile = opj_data_file('/'.join(lst))
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Invalid component number. # Invalid component number.
warnings.simplefilter("ignore")
j = Jp2k(jfile) j = Jp2k(jfile)
with self.assertRaises(IOError): with self.assertRaises(IOError):
j.read() j.read()

View file

@ -31,8 +31,6 @@ import re
import sys import sys
import unittest import unittest
import warnings
import numpy as np import numpy as np
from glymur import Jp2k from glymur import Jp2k
@ -44,7 +42,7 @@ from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file
@unittest.skipIf(OPJ_DATA_ROOT is None, @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set") "OPJ_DATA_ROOT environment variable not set")
class TestSuiteDump(unittest.TestCase): class TestSuite(unittest.TestCase):
def setUp(self): def setUp(self):
pass pass
@ -112,8 +110,7 @@ class TestSuiteDump(unittest.TestCase):
""" """
relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2' relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2'
jfile = opj_data_file(relpath) jfile = opj_data_file(relpath)
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
j = Jp2k(jfile) j = Jp2k(jfile)
d = j.read() d = j.read()
self.assertTrue(True) self.assertTrue(True)
@ -121,8 +118,7 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_broken4_jp2_dump(self): def test_NR_broken4_jp2_dump(self):
jfile = opj_data_file('input/nonregression/broken4.jp2') jfile = opj_data_file('input/nonregression/broken4.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC')
@ -136,9 +132,8 @@ class TestSuiteDump(unittest.TestCase):
length of over 1GB. Don't run it on 32-bit platforms. length of over 1GB. Don't run it on 32-bit platforms.
""" """
jfile = opj_data_file('input/nonregression/broken3.jp2') jfile = opj_data_file('input/nonregression/broken3.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Bad box length. # Bad box length.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
@ -232,9 +227,8 @@ class TestSuiteDump(unittest.TestCase):
Invalid marker ID in the codestream. Invalid marker ID in the codestream.
""" """
jfile = opj_data_file('input/nonregression/broken2.jp2') jfile = opj_data_file('input/nonregression/broken2.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Invalid marker ID on codestream. # Invalid marker ID on codestream.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC')
@ -2467,9 +2461,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file1_dump(self): def test_NR_file1_dump(self):
jfile = opj_data_file('input/conformance/file1.jp2') jfile = opj_data_file('input/conformance/file1.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Bad compatibility list item. # Bad compatibility list item.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
@ -2503,7 +2496,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file2_dump(self): def test_NR_file2_dump(self):
jfile = opj_data_file('input/conformance/file2.jp2') jfile = opj_data_file('input/conformance/file2.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
@ -2533,7 +2527,8 @@ class TestSuiteDump(unittest.TestCase):
# vertical directions. The components are stored in the standard # vertical directions. The components are stored in the standard
# order. # order.
jfile = opj_data_file('input/conformance/file3.jp2') jfile = opj_data_file('input/conformance/file3.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
@ -2564,7 +2559,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file4_dump(self): def test_NR_file4_dump(self):
# One 8-bit component in the sRGB-grey colourspace. # One 8-bit component in the sRGB-grey colourspace.
jfile = opj_data_file('input/conformance/file4.jp2') jfile = opj_data_file('input/conformance/file4.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
@ -2589,10 +2585,9 @@ class TestSuiteDump(unittest.TestCase):
# profile and using the JPX-defined enumerated code for the ROMM-RGB # profile and using the JPX-defined enumerated code for the ROMM-RGB
# colourspace. # colourspace.
jfile = opj_data_file('input/conformance/file5.jp2') 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. # There's a warning for an unknown compatibility entry.
# Ignore it here. # Ignore it here.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
@ -2615,7 +2610,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file6_dump(self): def test_NR_file6_dump(self):
jfile = opj_data_file('input/conformance/file6.jp2') jfile = opj_data_file('input/conformance/file6.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
@ -2642,7 +2638,8 @@ class TestSuiteDump(unittest.TestCase):
# profile and using the JPX-defined enumerated code for the e-sRGB # profile and using the JPX-defined enumerated code for the e-sRGB
# colourspace. # colourspace.
jfile = opj_data_file('input/conformance/file7.jp2') jfile = opj_data_file('input/conformance/file7.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c'])
@ -2670,7 +2667,8 @@ class TestSuiteDump(unittest.TestCase):
# One 8-bit component in a gamma 1.8 space. The colourspace is # One 8-bit component in a gamma 1.8 space. The colourspace is
# specified using a Restricted ICC profile. # specified using a Restricted ICC profile.
jfile = opj_data_file('input/conformance/file8.jp2') jfile = opj_data_file('input/conformance/file8.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'xml ', 'jp2c', self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'xml ', 'jp2c',
@ -2712,7 +2710,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file9_dump(self): def test_NR_file9_dump(self):
# Colormap # Colormap
jfile = opj_data_file('input/conformance/file9.jp2') jfile = opj_data_file('input/conformance/file9.jp2')
jp2 = Jp2k(jfile) with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
@ -3955,9 +3954,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_issue188_beach_64bitsbox(self): def test_NR_issue188_beach_64bitsbox(self):
lst = ['input', 'nonregression', 'issue188_beach_64bitsbox.jp2'] lst = ['input', 'nonregression', 'issue188_beach_64bitsbox.jp2']
jfile = opj_data_file('/'.join(lst)) jfile = opj_data_file('/'.join(lst))
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# There's a warning for an unknown box. # There's a warning for an unknown box.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
@ -4350,9 +4348,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_orb_blue10_lin_jp2_dump(self): def test_NR_orb_blue10_lin_jp2_dump(self):
jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') 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 # This file has an invalid ICC profile
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]
@ -4426,9 +4423,8 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_orb_blue10_win_jp2_dump(self): def test_NR_orb_blue10_win_jp2_dump(self):
jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2') jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# This file has an invalid ICC profile # This file has an invalid ICC profile
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box] ids = [box.box_id for box in jp2.box]

View file

@ -13,7 +13,6 @@ import re
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
import numpy as np import numpy as np
try: try:
@ -81,8 +80,7 @@ class TestSuiteNegative(unittest.TestCase):
relpath = 'input/nonregression/illegalcolortransform.j2k' relpath = 'input/nonregression/illegalcolortransform.j2k'
jfile = opj_data_file(relpath) jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile) jp2k = Jp2k(jfile)
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter('ignore')
codestream = jp2k.get_codestream(header_only=False) codestream = jp2k.get_codestream(header_only=False)
# Verify that the last segment returned in the codestream is SOD, # Verify that the last segment returned in the codestream is SOD,

View file

@ -11,7 +11,6 @@ import re
import sys import sys
import tempfile import tempfile
import unittest import unittest
import warnings
import numpy as np import numpy as np
try: try:
@ -157,10 +156,7 @@ class TestSuiteWriteCinema(unittest.TestCase):
data = skimage.io.imread(infile) data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
with warnings.catch_warnings(): j.write(data, cinema4k=True)
# Just turn off warnings.
warnings.simplefilter("ignore")
j.write(data, cinema4k=True)
codestream = j.get_codestream() codestream = j.get_codestream()
self.check_cinema4k_codestream(codestream, (4096, 2160)) self.check_cinema4k_codestream(codestream, (4096, 2160))
@ -220,10 +216,7 @@ class TestSuiteWriteCinema(unittest.TestCase):
data = skimage.io.imread(infile) data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
with warnings.catch_warnings(): j.write(data, cinema2k=48)
# Just turn off warnings.
warnings.simplefilter("ignore")
j.write(data, cinema2k=48)
codestream = j.get_codestream() codestream = j.get_codestream()
self.check_cinema2k_codestream(codestream, (1998, 1080)) self.check_cinema2k_codestream(codestream, (1998, 1080))

View file

@ -15,7 +15,6 @@ import re
import struct import struct
import sys import sys
import tempfile import tempfile
import warnings
import unittest import unittest
if sys.hexversion < 0x03000000: if sys.hexversion < 0x03000000:
@ -87,9 +86,7 @@ class TestPrinting(unittest.TestCase):
tfile.write(write_buffer) tfile.write(write_buffer)
tfile.flush() tfile.flush()
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Suppress the warning about the unrecognized box.
warnings.simplefilter("ignore")
jpx = Jp2k(tfile.name) jpx = Jp2k(tfile.name)
glymur.set_printoptions(short=True) glymur.set_printoptions(short=True)
@ -648,10 +645,7 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_invalid_colorspace(self): def test_invalid_colorspace(self):
"""An invalid colorspace shouldn't cause an error.""" """An invalid colorspace shouldn't cause an error."""
filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2') filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Bad compatibility list item and bad colorspace warnings. Just
# suppress the warnings.
warnings.simplefilter("ignore")
jp2 = Jp2k(filename) jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(jp2) print(jp2)
@ -659,8 +653,7 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_bad_rsiz(self): def test_bad_rsiz(self):
"""Should still be able to print if rsiz is bad, issue196""" """Should still be able to print if rsiz is bad, issue196"""
filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2') filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
j = Jp2k(filename) j = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j) print(j)
@ -668,8 +661,7 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_bad_wavelet_transform(self): def test_bad_wavelet_transform(self):
"""Should still be able to print if wavelet xform is bad, issue195""" """Should still be able to print if wavelet xform is bad, issue195"""
filename = opj_data_file('input/nonregression/edf_c2_10025.jp2') filename = opj_data_file('input/nonregression/edf_c2_10025.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
jp2 = Jp2k(filename) jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(jp2) print(jp2)
@ -677,9 +669,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_invalid_progression_order(self): def test_invalid_progression_order(self):
"""Should still be able to print even if prog order is invalid.""" """Should still be able to print even if prog order is invalid."""
jfile = opj_data_file('input/nonregression/2977.pdf.asan.67.2198.jp2') jfile = opj_data_file('input/nonregression/2977.pdf.asan.67.2198.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Multiple warnings, actually. # Multiple warnings, actually.
warnings.simplefilter("ignore")
jp2 = Jp2k(jfile) jp2 = Jp2k(jfile)
codestream = jp2.get_codestream() codestream = jp2.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -839,7 +830,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_xml(self): def test_xml(self):
"""verify printing of XML box""" """verify printing of XML box"""
filename = opj_data_file('input/conformance/file1.jp2') filename = opj_data_file('input/conformance/file1.jp2')
j = glymur.Jp2k(filename) with self.assertWarns(UserWarning):
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2]) print(j.box[2])
actual = fake_out.getvalue().strip() actual = fake_out.getvalue().strip()
@ -848,9 +840,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_channel_definition(self): def test_channel_definition(self):
"""verify printing of cdef box""" """verify printing of cdef box"""
filename = opj_data_file('input/conformance/file2.jp2') filename = opj_data_file('input/conformance/file2.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Bad compatibility list item. # Bad compatibility list item.
warnings.simplefilter("ignore")
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2]) print(j.box[2].box[2])
@ -865,7 +856,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_component_mapping(self): def test_component_mapping(self):
"""verify printing of cmap box""" """verify printing of cmap box"""
filename = opj_data_file('input/conformance/file9.jp2') 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: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2]) print(j.box[2].box[2])
actual = fake_out.getvalue().strip() actual = fake_out.getvalue().strip()
@ -890,7 +882,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_palette7(self): def test_palette7(self):
"""verify printing of pclr box""" """verify printing of pclr box"""
filename = opj_data_file('input/conformance/file9.jp2') 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: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1]) print(j.box[2].box[1])
actual = fake_out.getvalue().strip() actual = fake_out.getvalue().strip()
@ -902,7 +895,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_rreq(self): def test_rreq(self):
"""verify printing of reader requirements box""" """verify printing of reader requirements box"""
filename = opj_data_file('input/nonregression/text_GBR.jp2') filename = opj_data_file('input/nonregression/text_GBR.jp2')
j = glymur.Jp2k(filename) with self.assertWarns(UserWarning):
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2]) print(j.box[2])
actual = fake_out.getvalue().strip() actual = fake_out.getvalue().strip()
@ -932,7 +926,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_palette_box(self): def test_palette_box(self):
"""Verify that palette (pclr) boxes are printed without error.""" """Verify that palette (pclr) boxes are printed without error."""
filename = opj_data_file('input/conformance/file9.jp2') 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: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1]) print(j.box[2].box[1])
actual = fake_out.getvalue().strip() actual = fake_out.getvalue().strip()
@ -946,9 +941,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
# ICC profiles may be used in JP2, but the approximation field should # ICC profiles may be used in JP2, but the approximation field should
# be zero unless we have jpx. This file does both. # be zero unless we have jpx. This file does both.
filename = opj_data_file('input/nonregression/text_GBR.jp2') 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. # brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
jp2 = Jp2k(filename) jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -966,7 +960,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_uuid(self): def test_uuid(self):
"""verify printing of UUID box""" """verify printing of UUID box"""
filename = opj_data_file('input/nonregression/text_GBR.jp2') 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: with patch('sys.stdout', new=StringIO()) as fake_out:
print(jp2.box[4]) print(jp2.box[4])
@ -984,9 +979,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
# Format strings like %d were showing up in the output. # Format strings like %d were showing up in the output.
filename = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2') filename = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2')
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
# Ignore warning about bad pclr box. # Ignore warning about bad pclr box.
warnings.simplefilter("ignore")
jp2 = Jp2k(filename) jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(jp2.box[3].box[3]) print(jp2.box[3].box[3])
@ -996,9 +990,8 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
def test_issue183(self): def test_issue183(self):
filename = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') 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. # Ignore warning about bad pclr box.
warnings.simplefilter("ignore")
jp2 = Jp2k(filename) jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(jp2.box[2].box[1]) print(jp2.box[2].box[1])
@ -1010,8 +1003,7 @@ class TestPrintingOpjDataRoot(unittest.TestCase):
filename = opj_data_file(os.path.join('input', filename = opj_data_file(os.path.join('input',
'nonregression', 'nonregression',
'issue171.jp2')) 'issue171.jp2'))
with warnings.catch_warnings(): with self.assertWarns(UserWarning):
warnings.simplefilter("ignore")
jp2 = Jp2k(filename) jp2 = Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
# No need to verify, it's enough that we don't error out. # No need to verify, it's enough that we don't error out.