diff --git a/glymur/test/test_codestream.py b/glymur/test/test_codestream.py index 8bac19c..91c1adb 100644 --- a/glymur/test/test_codestream.py +++ b/glymur/test/test_codestream.py @@ -54,46 +54,39 @@ class TestCodestreamOpjData(unittest.TestCase): def test_bad_rsiz(self): """Should warn if RSIZ is bad. Issue196""" filename = opj_data_file('input/nonregression/edf_c2_1002767.jp2') - if sys.hexversion < 0x03000000: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - j = Jp2k(filename) - else: - with self.assertWarns(UserWarning): - j = Jp2k(filename) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + j = Jp2k(filename) + self.assertEqual(len(w), 3) + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Invalid profile' in str(w[0].message)) def test_bad_wavelet_transform(self): """Should warn if wavelet transform is bad. Issue195""" filename = opj_data_file('input/nonregression/edf_c2_10025.jp2') - if sys.hexversion < 0x03000000: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - j = Jp2k(filename) - else: - with self.assertWarns(UserWarning): - j = Jp2k(filename) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + j = Jp2k(filename) + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Invalid wavelet transform' in str(w[0].message)) def test_invalid_progression_order(self): """Should still be able to parse even if prog order is invalid.""" jfile = opj_data_file('input/nonregression/2977.pdf.asan.67.2198.jp2') - if sys.hexversion < 0x03000000: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - Jp2k(jfile) - else: - with self.assertWarns(UserWarning): - Jp2k(jfile) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + Jp2k(jfile) + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Invalid progression order' in str(w[0].message)) def test_tile_height_is_zero(self): """Zero tile height should not cause an exception.""" filename = opj_data_file('input/nonregression/2539.pdf.SIGFPE.706.1712.jp2') - if sys.hexversion < 0x03000000: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - Jp2k(filename) - else: - with self.assertWarns(UserWarning): - Jp2k(filename) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + Jp2k(filename) + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Invalid tile dimensions' in str(w[0].message)) @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @@ -127,8 +120,6 @@ class TestCodestreamOpjData(unittest.TestCase): self.assertEqual(codestream.segment[2].length, 3) self.assertEqual(codestream.segment[2].data, b'\x00') - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") def test_unknown_marker_segment(self): """Should warn for an unknown marker.""" @@ -151,8 +142,11 @@ class TestCodestreamOpjData(unittest.TestCase): tfile.write(read_buffer) tfile.flush() - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') codestream = Jp2k(tfile.name).get_codestream() + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Unrecognized marker' in str(w[0].message)) self.assertEqual(codestream.segment[2].marker_id, '0xff79') self.assertEqual(codestream.segment[2].length, 3) diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index 6884d2c..b8c97ae 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -16,6 +16,7 @@ import os import sys import tempfile import unittest +import warnings if sys.hexversion <= 0x03030000: from mock import patch @@ -83,8 +84,11 @@ class TestSuite(unittest.TestCase): with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}): # Misconfigured new configuration file should # be rejected. - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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 diff --git a/glymur/test/test_icc.py b/glymur/test/test_icc.py index d2dd959..3ddc249 100644 --- a/glymur/test/test_icc.py +++ b/glymur/test/test_icc.py @@ -62,16 +62,17 @@ class TestICC(unittest.TestCase): self.assertEqual(profile['Creator'], 'JPEG') - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") 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 self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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() diff --git a/glymur/test/test_jp2box.py b/glymur/test/test_jp2box.py index d8866cf..cef0d41 100644 --- a/glymur/test/test_jp2box.py +++ b/glymur/test/test_jp2box.py @@ -357,7 +357,6 @@ class TestChannelDefinition(unittest.TestCase): with self.assertRaises((IOError, OSError)): j2k.wrap(tfile.name, boxes=boxes) - @unittest.skipIf(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") 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,20 +364,26 @@ class TestChannelDefinition(unittest.TestCase): """ channel_type = (COLOR, COLOR, 3) association = (RED, GREEN, BLUE) - with self.assertWarns(UserWarning): + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') glymur.jp2box.ChannelDefinitionBox(channel_type=channel_type, association=association) + self.assertEqual(len(w), 1) + self.assertTrue(issubclass(w[0].category, UserWarning)) - @unittest.skipIf(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") 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 self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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): @@ -474,32 +479,41 @@ class TestColourSpecificationBox(unittest.TestCase): self.assertEqual(colr.colorspace, glymur.core.SRGB) self.assertIsNone(colr.icc_profile) - @unittest.skipIf(sys.hexversion < 0x03030000, "Requires 3.3+") def test_colr_with_cspace_and_icc(self): """Colour specification boxes can't have both.""" - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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(sys.hexversion < 0x03030000, "Requires 3.3+") def test_colr_with_bad_method(self): """colr must have a valid method field""" colorspace = glymur.core.SRGB method = -1 - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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(sys.hexversion < 0x03030000, "Requires 3.3+") def test_colr_with_bad_approx(self): """colr should have a valid approximation field""" colorspace = glymur.core.SRGB approx = -1 - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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.""" @@ -523,25 +537,29 @@ class TestPaletteBox(unittest.TestCase): def tearDown(self): pass - @unittest.skipIf(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") 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 self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") 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 self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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.""" diff --git a/glymur/test/test_jp2box_jpx.py b/glymur/test/test_jp2box_jpx.py index 3e09c83..3a5d42e 100644 --- a/glymur/test/test_jp2box_jpx.py +++ b/glymur/test/test_jp2box_jpx.py @@ -305,15 +305,17 @@ class TestJPXWrap(unittest.TestCase): with self.assertRaises(IOError): jp2.wrap(tfile.name, boxes=boxes) - @unittest.skipIf(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") 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 self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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() @@ -484,35 +486,6 @@ class TestJPX(unittest.TestCase): with tempfile.TemporaryFile() as tfile: ftbl.write(tfile) - @unittest.skip("No such jpx file anymore.") - def test_jpx_rreq_mask_length_3(self): - """There are some JPX files with rreq mask length of 3.""" - jpx = Jp2k(self.jpxfile) - self.assertEqual(jpx.box[2].box_id, 'rreq') - self.assertEqual(type(jpx.box[2]), - glymur.jp2box.ReaderRequirementsBox) - self.asserwrite_buffertEqual(jpx.box[2].standard_flag, - (5, 42, 45, 2, 18, 19, 1, 8, 12, 31, 20)) - - @unittest.skip("Requires unnecessarily complicated code") - def test_unknown_superbox(self): - """Verify that we can handle an unknown superbox.""" - with tempfile.NamedTemporaryFile(suffix='.jpx') as tfile: - with open(self.jpxfile, 'rb') as ifile: - tfile.write(ifile.read()) - - # Add the header for an unknwon superbox. - write_buffer = struct.pack('>I4s', 20, 'grp '.encode()) - tfile.write(write_buffer) - write_buffer = struct.pack('>I4sI', 12, 'free'.encode(), 0) - tfile.write(write_buffer) - tfile.flush() - - with self.assertWarns(UserWarning): - jpx = Jp2k(tfile.name) - self.assertEqual(jpx.box[-1].box_id, b'grp ') - self.assertEqual(jpx.box[-1].box[0].box_id, 'free') - def test_data_reference_requires_dtbl(self): """The existance of a data reference box requires a ftbl box as well.""" flag = 0 diff --git a/glymur/test/test_jp2box_uuid.py b/glymur/test/test_jp2box_uuid.py index a904174..b6e9762 100644 --- a/glymur/test/test_jp2box_uuid.py +++ b/glymur/test/test_jp2box_uuid.py @@ -83,7 +83,6 @@ class TestUUIDExif(unittest.TestCase): def tearDown(self): pass - @unittest.skipIf(sys.hexversion < 0x03000000, "Requires assertWarns, 3.2+") def test_unrecognized_exif_tag(self): """Verify warning in case of unrecognized tag.""" with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile: @@ -106,10 +105,13 @@ class TestUUIDExif(unittest.TestCase): tfile.write(struct.pack('= 0x03000000: - with self.assertWarns(UserWarning): - jp2 = Jp2k(filename) + with warnings.catch_warnings(record=True) as w: + jp2 = Jp2k(filename) + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Invalid profile' in str(w[0].message)) - @unittest.skip("blah") def test_main_header(self): """Verify that the main header is not loaded when parsing turned off.""" # The hidden _main_header attribute should show up after accessing it. @@ -792,44 +793,62 @@ class TestParsing(unittest.TestCase): @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") -class TestJp2kOpjDataRoot(unittest.TestCase): +class TestJp2kOpjDataRootWarnings(unittest.TestCase): """These tests should be run by just about all configuration.""" 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') - if sys.hexversion < 0x03000000: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - jp2 = Jp2k(filename) - else: - with self.assertWarns(UserWarning): - jp2 = Jp2k(filename) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + 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. box_ids = [box.box_id for box in jp2.box[:-1]] self.assertEqual(box_ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - def test_invalid_approximation(self): + 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 self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') jp2 = Jp2k(filename) + self.assertTrue(issubclass(w[0].category, UserWarning)) - @unittest.skipIf(sys.hexversion < 0x03000000, "Test requires Python 3.3+") def test_invalid_approximation(self): """Should warn in case of invalid approximation.""" filename = opj_data_file('input/nonregression/edf_c2_1015644.jp2') - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') jp2 = Jp2k(filename) + self.assertTrue(issubclass(w[0].category, UserWarning)) + self.assertTrue('Invalid approximation' in str(w[0].message)) - @unittest.skipIf(sys.hexversion < 0x03000000, "Test requires Python 3.3+") def test_invalid_colorspace(self): """Should warn in case of invalid colorspace.""" filename = opj_data_file('input/nonregression/edf_c2_1103421.jp2') - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') 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') + jp2 = Jp2k(filename) + self.assertTrue(issubclass(w[1].category, UserWarning)) + + +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") +class TestJp2kOpjDataRoot(unittest.TestCase): + """These tests should be run by just about all configuration.""" def test_no_cxform_pclr_jp2(self): """Indices for pclr jpxfile if no color transform""" @@ -849,17 +868,6 @@ class TestJp2kOpjDataRoot(unittest.TestCase): rgb_from_idx[r, c] = palette[idx[r, c]] np.testing.assert_array_equal(rgb, rgb_from_idx) - def test_stupid_windows_eol_at_end(self): - """Garbage characters at the end of the file.""" - filename = opj_data_file('input/nonregression/issue211.jp2') - if sys.hexversion < 0x03000000: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - jp2 = Jp2k(filename) - else: - with self.assertWarns(UserWarning): - jp2 = Jp2k(filename) - def test_read_differing_subsamples(self): """should error out with read used on differently subsampled images""" # Verify that we error out appropriately if we use the read method diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index f4534ef..ca9d532 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -65,19 +65,6 @@ class TestSuite(unittest.TestCase): np.testing.assert_array_equal(jpdata, pgxdata) - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_ETS_C1P0_p0_02_j2k(self): - jfile = opj_data_file('input/conformance/p0_02.j2k') - jp2k = Jp2k(jfile) - with self.assertWarns(UserWarning): - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_02_0.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - def test_ETS_C1P0_p0_03_j2k(self): jfile = opj_data_file('input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) @@ -409,28 +396,6 @@ class TestSuite(unittest.TestCase): jp2.read() self.assertTrue(True) - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_DEC_broken_jp2_4_decode(self): - jfile = opj_data_file('input/nonregression/broken.jp2') - with self.assertWarns(UserWarning): - # colr box has bad length. - jp2 = Jp2k(jfile) - with self.assertRaises(IOError): - jp2.read() - self.assertTrue(True) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_DEC_broken3_jp2_6_decode(self): - jfile = opj_data_file('input/nonregression/broken3.jp2') - with self.assertWarns(UserWarning): - # colr box has bad length. - j = Jp2k(jfile) - - with self.assertRaises(IOError): - j.read() - @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_bug_j2c_8_decode(self): jfile = opj_data_file('input/nonregression/bug.j2c') @@ -622,6 +587,482 @@ class TestSuite(unittest.TestCase): jp2k.read(rlevel=4) +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") +class TestSuiteWarn(unittest.TestCase): + """ + All these tests issue warnings. + """ + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_NR_text_GBR_dump(self): + # brand is 'jp2 ', but has any icc profile. + # Verify the warning on python3, but ignore it otherwise. + jfile = opj_data_file('input/nonregression/text_GBR.jp2') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + jp2 = Jp2k(jfile) + + ids = [box.box_id for box in jp2.box] + lst = ['jP ', 'ftyp', 'rreq', 'jp2h', + 'uuid', 'uuid', 'uuid', 'uuid', 'jp2c'] + self.assertEqual(ids, lst) + + ids = [box.box_id for box in jp2.box[3].box] + self.assertEqual(ids, ['ihdr', 'colr', 'res ']) + + # Signature box. Check for corruption. + self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) + + # File type box. + self.assertEqual(jp2.box[1].brand, 'jp2 ') + self.assertEqual(jp2.box[1].minor_version, 0) + self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') + + # Reader requirements. + # Compositing layer uses any icc profile + self.assertTrue(44 in jp2.box[2].standard_flag) + + # Jp2 Header + # Image header + self.assertEqual(jp2.box[3].box[0].height, 400) + self.assertEqual(jp2.box[3].box[0].width, 400) + self.assertEqual(jp2.box[3].box[0].num_components, 3) + self.assertEqual(jp2.box[3].box[0].bits_per_component, 8) + self.assertEqual(jp2.box[3].box[0].signed, False) + self.assertEqual(jp2.box[3].box[0].compression, 7) # wavelet + self.assertEqual(jp2.box[3].box[0].colorspace_unknown, True) + self.assertEqual(jp2.box[3].box[0].ip_provided, False) + + # Jp2 Header + # Colour specification + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ANY_ICC_PROFILE) + self.assertEqual(jp2.box[3].box[1].precedence, 2) + self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact + self.assertEqual(jp2.box[3].box[1].icc_profile['Size'], 1328) + self.assertIsNone(jp2.box[3].box[1].colorspace) + + # UUID boxes. All mentioned in the RREQ box. + self.assertEqual(jp2.box[2].vendor_feature[0], jp2.box[4].uuid) + self.assertEqual(jp2.box[2].vendor_feature[1], jp2.box[5].uuid) + self.assertEqual(jp2.box[2].vendor_feature[2], jp2.box[6].uuid) + self.assertEqual(jp2.box[2].vendor_feature[3], jp2.box[7].uuid) + + c = jp2.box[8].main_header + + ids = [x.marker_id for x in c.segment] + expected = ['SOC', 'SIZ', 'COD', 'QCD'] + self.assertEqual(ids, expected) + + # SIZ: Image and tile size + # Profile: + self.assertEqual(c.segment[1].rsiz, 0) + # Reference grid size + self.assertEqual(c.segment[1].xsiz, 400) + self.assertEqual(c.segment[1].ysiz, 400) + # Reference grid offset + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) + # Tile size + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) + # Tile offset + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) + # bitdepth + self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) + # signed + self.assertEqual(c.segment[1].signed, (False, False, False)) + # subsampling + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), + [(1, 1)] * 3) + + # COD: Coding style default + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) + self.assertEqual(c.segment[2].layers, 6) # layers = 6 + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level + self.assertEqual(tuple(c.segment[2].code_block_size), + (32, 32)) # cblk + # Selective arithmetic coding bypass + self.assertFalse(c.segment[2].spcod[7] & 0x01) + # Reset context probabilities + self.assertFalse(c.segment[2].spcod[7] & 0x02) + # Termination on each coding pass + self.assertFalse(c.segment[2].spcod[7] & 0x04) + # Vertically causal context + self.assertFalse(c.segment[2].spcod[7] & 0x08) + # Predictable termination + self.assertFalse(c.segment[2].spcod[7] & 0x0010) + # Segmentation symbols + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) + + # QCD: Quantization default + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3].guard_bits, 2) + self.assertEqual(c.segment[3].mantissa, [0] * 16) + self.assertEqual(c.segment[3].exponent, + [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) + + def test_ETS_C1P0_p0_02_j2k(self): + jfile = opj_data_file('input/conformance/p0_02.j2k') + jp2k = Jp2k(jfile) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + jpdata = jp2k.read(rlevel=0) + + pgxfile = opj_data_file('baseline/conformance/c1p0_02_0.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_NR_DEC_broken_jp2_4_decode(self): + jfile = opj_data_file('input/nonregression/broken.jp2') + with warnings.catch_warnings(record=True) as w: + # colr box has bad length. + warnings.simplefilter('ignore') + jp2 = Jp2k(jfile) + with self.assertRaises(IOError): + jp2.read() + self.assertTrue(True) + + def test_NR_DEC_broken3_jp2_6_decode(self): + jfile = opj_data_file('input/nonregression/broken3.jp2') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + # colr box has bad length. + j = Jp2k(jfile) + + with self.assertRaises(IOError): + j.read() + +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") +class TestSuiteDumpWarnings(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_NR_broken_jp2_dump(self): + jfile = opj_data_file('input/nonregression/broken.jp2') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + # colr box has bad length. + jp2 = Jp2k(jfile) + + ids = [box.box_id for box in jp2.box] + self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) + + ids = [box.box_id for box in jp2.box[2].box] + self.assertEqual(ids, ['ihdr', 'colr']) + + # Signature box. Check for corruption. + self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) + + # File type box. + self.assertEqual(jp2.box[1].brand, 'jp2 ') + self.assertEqual(jp2.box[1].minor_version, 0) + self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') + + # Jp2 Header + # Image header + self.assertEqual(jp2.box[2].box[0].height, 152) + self.assertEqual(jp2.box[2].box[0].width, 203) + self.assertEqual(jp2.box[2].box[0].num_components, 3) + self.assertEqual(jp2.box[2].box[0].bits_per_component, 8) + self.assertEqual(jp2.box[2].box[0].signed, False) + self.assertEqual(jp2.box[2].box[0].compression, 7) # wavelet + self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) + self.assertEqual(jp2.box[2].box[0].ip_provided, False) + + # Jp2 Header + # Colour specification + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) + self.assertEqual(jp2.box[2].box[1].precedence, 0) + self.assertEqual(jp2.box[2].box[1].approximation, 0) # not allowed? + self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) + + c = jp2.box[3].main_header + + ids = [x.marker_id for x in c.segment] + expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC'] + self.assertEqual(ids, expected) + + # SIZ: Image and tile size + # Profile: + self.assertEqual(c.segment[1].rsiz, 0) + # Reference grid size + self.assertEqual(c.segment[1].xsiz, 203) + self.assertEqual(c.segment[1].ysiz, 152) + # Reference grid offset + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) + # Tile size + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (203, 152)) + # Tile offset + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) + # bitdepth + self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) + # signed + self.assertEqual(c.segment[1].signed, (False, False, False)) + # subsampling + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), + [(1, 1)] * 3) + + # COM: comment + # Registration + self.assertEqual(c.segment[2].rcme, glymur.core.RCME_ISO_8859_1) + # Comment value + self.assertEqual(c.segment[2].ccme.decode('latin-1'), + "Creator: JasPer Version 1.701.0") + + # COD: Coding style default + self.assertFalse(c.segment[3].scod & 2) # no sop + self.assertFalse(c.segment[3].scod & 4) # no eph + self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP) + self.assertEqual(c.segment[3].layers, 1) # layers = 1 + self.assertEqual(c.segment[3].spcod[3], 1) # mct + self.assertEqual(c.segment[3].spcod[4], 5) # level + self.assertEqual(tuple(c.segment[3].code_block_size), + (64, 64)) # cblk + # Selective arithmetic coding bypass + self.assertFalse(c.segment[3].spcod[7] & 0x01) + # Reset context probabilities + self.assertFalse(c.segment[3].spcod[7] & 0x02) + # Termination on each coding pass + self.assertFalse(c.segment[3].spcod[7] & 0x04) + # Vertically causal context + self.assertFalse(c.segment[3].spcod[7] & 0x08) + # Predictable termination + self.assertFalse(c.segment[3].spcod[7] & 0x0010) + # Segmentation symbols + self.assertFalse(c.segment[3].spcod[7] & 0x0020) + self.assertEqual(c.segment[3].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[3].spcod), 9) + + # QCD: Quantization default + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) + self.assertEqual(c.segment[4].guard_bits, 2) + self.assertEqual(c.segment[4].mantissa, [0] * 16) + self.assertEqual(c.segment[4].exponent, + [8] + [9, 9, 10] * 5) + + # QCC: Quantization component + # associated component + self.assertEqual(c.segment[5].cqcc, 1) + self.assertEqual(c.segment[5].guard_bits, 2) + # quantization type + self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[5].mantissa, [0] * 16) + self.assertEqual(c.segment[5].exponent, + [8] + [9, 9, 10] * 5) + + # QCC: Quantization component + # associated component + self.assertEqual(c.segment[6].cqcc, 2) + self.assertEqual(c.segment[6].guard_bits, 2) + # quantization type + self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[6].mantissa, [0] * 16) + self.assertEqual(c.segment[6].exponent, + [8] + [9, 9, 10] * 5) + + def test_NR_broken2_jp2_dump(self): + # Invalid marker ID on codestream. + jfile = opj_data_file('input/nonregression/broken2.jp2') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + jp2 = Jp2k(jfile) + + self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') + + def test_NR_broken3_jp2_dump(self): + jfile = opj_data_file('input/nonregression/broken3.jp2') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + jp2 = Jp2k(jfile) + + ids = [box.box_id for box in jp2.box] + self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) + + ids = [box.box_id for box in jp2.box[2].box] + self.assertEqual(ids, ['ihdr', 'colr']) + + # Signature box. Check for corruption. + self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) + + # File type box. + self.assertEqual(jp2.box[1].brand, 'jp2 ') + self.assertEqual(jp2.box[1].minor_version, 0) + self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') + + # Jp2 Header + # Image header + self.assertEqual(jp2.box[2].box[0].height, 152) + self.assertEqual(jp2.box[2].box[0].width, 203) + self.assertEqual(jp2.box[2].box[0].num_components, 3) + self.assertEqual(jp2.box[2].box[0].bits_per_component, 8) + self.assertEqual(jp2.box[2].box[0].signed, False) + self.assertEqual(jp2.box[2].box[0].compression, 7) # wavelet + self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) + self.assertEqual(jp2.box[2].box[0].ip_provided, False) + + # Jp2 Header + # Colour specification + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) + self.assertEqual(jp2.box[2].box[1].precedence, 0) + self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 + self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) + + c = jp2.box[3].main_header + + ids = [x.marker_id for x in c.segment] + expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC'] + self.assertEqual(ids, expected) + + # SIZ: Image and tile size + # Profile: + self.assertEqual(c.segment[1].rsiz, 0) + # Reference grid size + self.assertEqual(c.segment[1].xsiz, 203) + self.assertEqual(c.segment[1].ysiz, 152) + # Reference grid offset + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) + # Tile size + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (203, 152)) + # Tile offset + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) + # bitdepth + self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) + # signed + self.assertEqual(c.segment[1].signed, (False, False, False)) + # subsampling + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), + [(1, 1)] * 3) + + # COM: comment + # Registration + self.assertEqual(c.segment[2].rcme, glymur.core.RCME_ISO_8859_1) + # Comment value + self.assertEqual(c.segment[2].ccme.decode('latin-1'), + "Creator: JasPer Vers)on 1.701.0") + + # COD: Coding style default + self.assertFalse(c.segment[3].scod & 2) # no sop + self.assertFalse(c.segment[3].scod & 4) # no eph + self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP) + self.assertEqual(c.segment[3].layers, 1) # layers = 1 + self.assertEqual(c.segment[3].spcod[3], 1) # mct + self.assertEqual(c.segment[3].spcod[4], 5) # level + self.assertEqual(tuple(c.segment[3].code_block_size), + (64, 64)) # cblk + # Selective arithmetic coding bypass + self.assertFalse(c.segment[3].spcod[7] & 0x01) + # Reset context probabilities + self.assertFalse(c.segment[3].spcod[7] & 0x02) + # Termination on each coding pass + self.assertFalse(c.segment[3].spcod[7] & 0x04) + # Vertically causal context + self.assertFalse(c.segment[3].spcod[7] & 0x08) + # Predictable termination + self.assertFalse(c.segment[3].spcod[7] & 0x0010) + # Segmentation symbols + self.assertFalse(c.segment[3].spcod[7] & 0x0020) + self.assertEqual(c.segment[3].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[3].spcod), 9) + + # QCD: Quantization default + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) + self.assertEqual(c.segment[4].guard_bits, 2) + self.assertEqual(c.segment[4].mantissa, [0] * 16) + self.assertEqual(c.segment[4].exponent, + [8] + [9, 9, 10] * 5) + + # QCC: Quantization component + # associated component + self.assertEqual(c.segment[5].cqcc, 1) + self.assertEqual(c.segment[5].guard_bits, 2) + # quantization type + self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[5].mantissa, [0] * 16) + self.assertEqual(c.segment[5].exponent, + [8] + [9, 9, 10] * 5) + + # QCC: Quantization component + # associated component + self.assertEqual(c.segment[6].cqcc, 2) + self.assertEqual(c.segment[6].guard_bits, 2) + # quantization type + self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[6].mantissa, [0] * 16) + self.assertEqual(c.segment[6].exponent, + [8] + [9, 9, 10] * 5) + + def test_NR_broken4_jp2_dump(self): + # Has an invalid marker in the main header + jfile = opj_data_file('input/nonregression/broken4.jp2') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + jp2 = Jp2k(jfile) + + self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') + + def test_NR_gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc_patch_jp2(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(record=True) as w: + warnings.simplefilter('ignore') + Jp2k(jfile) + + def test_NR_gdal_fuzzer_check_comp_dx_dy_jp2_dump(self): + lst = ['input', 'nonregression', 'gdal_fuzzer_check_comp_dx_dy.jp2'] + jfile = opj_data_file('/'.join(lst)) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + Jp2k(jfile) + + def test_NR_gdal_fuzzer_check_number_of_tiles(self): + # Has an impossible tiling setup. + lst = ['input', 'nonregression', + 'gdal_fuzzer_check_number_of_tiles.jp2'] + jfile = opj_data_file('/'.join(lst)) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + Jp2k(jfile) + + def test_NR_gdal_fuzzer_unchecked_numresolutions_dump(self): + # Has an invalid number of resolutions. + lst = ['input', 'nonregression', + 'gdal_fuzzer_unchecked_numresolutions.jp2'] + jfile = opj_data_file('/'.join(lst)) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + Jp2k(jfile) + + def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self): + # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it + # really does deserve a warning. + relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2' + jfile = opj_data_file(relpath) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') + Jp2k(jfile).read() + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestSuiteDump(unittest.TestCase): @@ -632,6 +1073,103 @@ class TestSuiteDump(unittest.TestCase): def tearDown(self): pass + def test_NR_file409752(self): + jfile = opj_data_file('input/nonregression/file409752.jp2') + jp2 = Jp2k(jfile) + + ids = [box.box_id for box in jp2.box] + self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) + + ids = [box.box_id for box in jp2.box[2].box] + self.assertEqual(ids, ['ihdr', 'colr']) + + # Signature box. Check for corruption. + self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) + + # File type box. + self.assertEqual(jp2.box[1].brand, 'jp2 ') + self.assertEqual(jp2.box[1].minor_version, 0) + self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') + + # Jp2 Header + # Image header + self.assertEqual(jp2.box[2].box[0].height, 243) + self.assertEqual(jp2.box[2].box[0].width, 720) + self.assertEqual(jp2.box[2].box[0].num_components, 3) + self.assertEqual(jp2.box[2].box[0].bits_per_component, 8) + self.assertEqual(jp2.box[2].box[0].signed, False) + self.assertEqual(jp2.box[2].box[0].compression, 7) # wavelet + self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) + self.assertEqual(jp2.box[2].box[0].ip_provided, False) + + # Jp2 Header + # Colour specification + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) + self.assertEqual(jp2.box[2].box[1].precedence, 0) + self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 + self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.YCC) + + c = jp2.box[3].main_header + + ids = [x.marker_id for x in c.segment] + expected = ['SOC', 'SIZ', 'COD', 'QCD'] + self.assertEqual(ids, expected) + + # SIZ: Image and tile size + # Profile: + self.assertEqual(c.segment[1].rsiz, 0) + # Reference grid size + self.assertEqual(c.segment[1].xsiz, 720) + self.assertEqual(c.segment[1].ysiz, 243) + # Reference grid offset + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) + # Tile size + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (720, 243)) + # Tile offset + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) + # bitdepth + self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) + # signed + self.assertEqual(c.segment[1].signed, (False, False, False)) + # subsampling + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), + [(1, 1), (2, 1), (2, 1)]) + + # COD: Coding style default + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) + self.assertEqual(c.segment[2].layers, 1) # layers = 1 + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level + self.assertEqual(tuple(c.segment[2].code_block_size), + (32, 128)) # cblk + # Selective arithmetic coding bypass + self.assertFalse(c.segment[2].spcod[7] & 0x01) + # Reset context probabilities + self.assertFalse(c.segment[2].spcod[7] & 0x02) + # Termination on each coding pass + self.assertFalse(c.segment[2].spcod[7] & 0x04) + # Vertically causal context + self.assertFalse(c.segment[2].spcod[7] & 0x08) + # Predictable termination + self.assertFalse(c.segment[2].spcod[7] & 0x0010) + # Segmentation symbols + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) + + # QCD: Quantization default + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3].guard_bits, 1) + self.assertEqual(c.segment[3].mantissa, + [1816, 1792, 1792, 1724, 1770, 1770, 1724, 1868, + 1868, 1892, 3, 3, 69, 2002, 2002, 1889]) + self.assertEqual(c.segment[3].exponent, + [13] * 4 + [12] * 3 + [11] * 3 + [9] * 6) + def test_NR_p0_01_dump(self): jfile = opj_data_file('input/conformance/p0_01.j2k') c = Jp2k(jfile).get_codestream(header_only=False) @@ -4964,412 +5502,6 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[4].ccme.decode('latin-1'), "DCP-Werkstatt") - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_broken_jp2_dump(self): - jfile = opj_data_file('input/nonregression/broken.jp2') - with self.assertWarns(UserWarning): - # colr box has bad length. - jp2 = Jp2k(jfile) - - ids = [box.box_id for box in jp2.box] - self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - - ids = [box.box_id for box in jp2.box[2].box] - self.assertEqual(ids, ['ihdr', 'colr']) - - # Signature box. Check for corruption. - self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) - - # File type box. - self.assertEqual(jp2.box[1].brand, 'jp2 ') - self.assertEqual(jp2.box[1].minor_version, 0) - self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') - - # Jp2 Header - # Image header - self.assertEqual(jp2.box[2].box[0].height, 152) - self.assertEqual(jp2.box[2].box[0].width, 203) - self.assertEqual(jp2.box[2].box[0].num_components, 3) - self.assertEqual(jp2.box[2].box[0].bits_per_component, 8) - self.assertEqual(jp2.box[2].box[0].signed, False) - self.assertEqual(jp2.box[2].box[0].compression, 7) # wavelet - self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) - self.assertEqual(jp2.box[2].box[0].ip_provided, False) - - # Jp2 Header - # Colour specification - self.assertEqual(jp2.box[2].box[1].method, - glymur.core.ENUMERATED_COLORSPACE) - self.assertEqual(jp2.box[2].box[1].precedence, 0) - self.assertEqual(jp2.box[2].box[1].approximation, 0) # not allowed? - self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) - - c = jp2.box[3].main_header - - ids = [x.marker_id for x in c.segment] - expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC'] - self.assertEqual(ids, expected) - - # SIZ: Image and tile size - # Profile: - self.assertEqual(c.segment[1].rsiz, 0) - # Reference grid size - self.assertEqual(c.segment[1].xsiz, 203) - self.assertEqual(c.segment[1].ysiz, 152) - # Reference grid offset - self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) - # Tile size - self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (203, 152)) - # Tile offset - self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) - # bitdepth - self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) - # signed - self.assertEqual(c.segment[1].signed, (False, False, False)) - # subsampling - self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), - [(1, 1)] * 3) - - # COM: comment - # Registration - self.assertEqual(c.segment[2].rcme, glymur.core.RCME_ISO_8859_1) - # Comment value - self.assertEqual(c.segment[2].ccme.decode('latin-1'), - "Creator: JasPer Version 1.701.0") - - # COD: Coding style default - self.assertFalse(c.segment[3].scod & 2) # no sop - self.assertFalse(c.segment[3].scod & 4) # no eph - self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP) - self.assertEqual(c.segment[3].layers, 1) # layers = 1 - self.assertEqual(c.segment[3].spcod[3], 1) # mct - self.assertEqual(c.segment[3].spcod[4], 5) # level - self.assertEqual(tuple(c.segment[3].code_block_size), - (64, 64)) # cblk - # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].spcod[7] & 0x01) - # Reset context probabilities - self.assertFalse(c.segment[3].spcod[7] & 0x02) - # Termination on each coding pass - self.assertFalse(c.segment[3].spcod[7] & 0x04) - # Vertically causal context - self.assertFalse(c.segment[3].spcod[7] & 0x08) - # Predictable termination - self.assertFalse(c.segment[3].spcod[7] & 0x0010) - # Segmentation symbols - self.assertFalse(c.segment[3].spcod[7] & 0x0020) - self.assertEqual(c.segment[3].spcod[8], - glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) - self.assertEqual(len(c.segment[3].spcod), 9) - - # QCD: Quantization default - self.assertEqual(c.segment[4].sqcd & 0x1f, 0) - self.assertEqual(c.segment[4].guard_bits, 2) - self.assertEqual(c.segment[4].mantissa, [0] * 16) - self.assertEqual(c.segment[4].exponent, - [8] + [9, 9, 10] * 5) - - # QCC: Quantization component - # associated component - self.assertEqual(c.segment[5].cqcc, 1) - self.assertEqual(c.segment[5].guard_bits, 2) - # quantization type - self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[5].mantissa, [0] * 16) - self.assertEqual(c.segment[5].exponent, - [8] + [9, 9, 10] * 5) - - # QCC: Quantization component - # associated component - self.assertEqual(c.segment[6].cqcc, 2) - self.assertEqual(c.segment[6].guard_bits, 2) - # quantization type - self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[6].mantissa, [0] * 16) - self.assertEqual(c.segment[6].exponent, - [8] + [9, 9, 10] * 5) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2, 'assertWarns'.") - def test_NR_broken2_jp2_dump(self): - # Invalid marker ID on codestream. - jfile = opj_data_file('input/nonregression/broken2.jp2') - with self.assertWarns(UserWarning): - jp2 = Jp2k(jfile) - - self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_broken3_jp2_dump(self): - jfile = opj_data_file('input/nonregression/broken3.jp2') - with self.assertWarns(UserWarning): - # colr box has bad length. - jp2 = Jp2k(jfile) - - ids = [box.box_id for box in jp2.box] - self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - - ids = [box.box_id for box in jp2.box[2].box] - self.assertEqual(ids, ['ihdr', 'colr']) - - # Signature box. Check for corruption. - self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) - - # File type box. - self.assertEqual(jp2.box[1].brand, 'jp2 ') - self.assertEqual(jp2.box[1].minor_version, 0) - self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') - - # Jp2 Header - # Image header - self.assertEqual(jp2.box[2].box[0].height, 152) - self.assertEqual(jp2.box[2].box[0].width, 203) - self.assertEqual(jp2.box[2].box[0].num_components, 3) - self.assertEqual(jp2.box[2].box[0].bits_per_component, 8) - self.assertEqual(jp2.box[2].box[0].signed, False) - self.assertEqual(jp2.box[2].box[0].compression, 7) # wavelet - self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) - self.assertEqual(jp2.box[2].box[0].ip_provided, False) - - # Jp2 Header - # Colour specification - self.assertEqual(jp2.box[2].box[1].method, - glymur.core.ENUMERATED_COLORSPACE) - self.assertEqual(jp2.box[2].box[1].precedence, 0) - self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 - self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) - - c = jp2.box[3].main_header - - ids = [x.marker_id for x in c.segment] - expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC'] - self.assertEqual(ids, expected) - - # SIZ: Image and tile size - # Profile: - self.assertEqual(c.segment[1].rsiz, 0) - # Reference grid size - self.assertEqual(c.segment[1].xsiz, 203) - self.assertEqual(c.segment[1].ysiz, 152) - # Reference grid offset - self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) - # Tile size - self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (203, 152)) - # Tile offset - self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) - # bitdepth - self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) - # signed - self.assertEqual(c.segment[1].signed, (False, False, False)) - # subsampling - self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), - [(1, 1)] * 3) - - # COM: comment - # Registration - self.assertEqual(c.segment[2].rcme, glymur.core.RCME_ISO_8859_1) - # Comment value - self.assertEqual(c.segment[2].ccme.decode('latin-1'), - "Creator: JasPer Vers)on 1.701.0") - - # COD: Coding style default - self.assertFalse(c.segment[3].scod & 2) # no sop - self.assertFalse(c.segment[3].scod & 4) # no eph - self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP) - self.assertEqual(c.segment[3].layers, 1) # layers = 1 - self.assertEqual(c.segment[3].spcod[3], 1) # mct - self.assertEqual(c.segment[3].spcod[4], 5) # level - self.assertEqual(tuple(c.segment[3].code_block_size), - (64, 64)) # cblk - # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].spcod[7] & 0x01) - # Reset context probabilities - self.assertFalse(c.segment[3].spcod[7] & 0x02) - # Termination on each coding pass - self.assertFalse(c.segment[3].spcod[7] & 0x04) - # Vertically causal context - self.assertFalse(c.segment[3].spcod[7] & 0x08) - # Predictable termination - self.assertFalse(c.segment[3].spcod[7] & 0x0010) - # Segmentation symbols - self.assertFalse(c.segment[3].spcod[7] & 0x0020) - self.assertEqual(c.segment[3].spcod[8], - glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) - self.assertEqual(len(c.segment[3].spcod), 9) - - # QCD: Quantization default - self.assertEqual(c.segment[4].sqcd & 0x1f, 0) - self.assertEqual(c.segment[4].guard_bits, 2) - self.assertEqual(c.segment[4].mantissa, [0] * 16) - self.assertEqual(c.segment[4].exponent, - [8] + [9, 9, 10] * 5) - - # QCC: Quantization component - # associated component - self.assertEqual(c.segment[5].cqcc, 1) - self.assertEqual(c.segment[5].guard_bits, 2) - # quantization type - self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[5].mantissa, [0] * 16) - self.assertEqual(c.segment[5].exponent, - [8] + [9, 9, 10] * 5) - - # QCC: Quantization component - # associated component - self.assertEqual(c.segment[6].cqcc, 2) - self.assertEqual(c.segment[6].guard_bits, 2) - # quantization type - self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[6].mantissa, [0] * 16) - self.assertEqual(c.segment[6].exponent, - [8] + [9, 9, 10] * 5) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2, 'assertWarns'") - def test_NR_broken4_jp2_dump(self): - # Has an invalid marker in the main header - jfile = opj_data_file('input/nonregression/broken4.jp2') - with self.assertWarns(UserWarning): - jp2 = Jp2k(jfile) - - self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') - - def test_NR_file409752(self): - jfile = opj_data_file('input/nonregression/file409752.jp2') - jp2 = Jp2k(jfile) - - ids = [box.box_id for box in jp2.box] - self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - - ids = [box.box_id for box in jp2.box[2].box] - self.assertEqual(ids, ['ihdr', 'colr']) - - # Signature box. Check for corruption. - self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) - - # File type box. - self.assertEqual(jp2.box[1].brand, 'jp2 ') - self.assertEqual(jp2.box[1].minor_version, 0) - self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') - - # Jp2 Header - # Image header - self.assertEqual(jp2.box[2].box[0].height, 243) - self.assertEqual(jp2.box[2].box[0].width, 720) - self.assertEqual(jp2.box[2].box[0].num_components, 3) - self.assertEqual(jp2.box[2].box[0].bits_per_component, 8) - self.assertEqual(jp2.box[2].box[0].signed, False) - self.assertEqual(jp2.box[2].box[0].compression, 7) # wavelet - self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) - self.assertEqual(jp2.box[2].box[0].ip_provided, False) - - # Jp2 Header - # Colour specification - self.assertEqual(jp2.box[2].box[1].method, - glymur.core.ENUMERATED_COLORSPACE) - self.assertEqual(jp2.box[2].box[1].precedence, 0) - self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 - self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.YCC) - - c = jp2.box[3].main_header - - ids = [x.marker_id for x in c.segment] - expected = ['SOC', 'SIZ', 'COD', 'QCD'] - self.assertEqual(ids, expected) - - # SIZ: Image and tile size - # Profile: - self.assertEqual(c.segment[1].rsiz, 0) - # Reference grid size - self.assertEqual(c.segment[1].xsiz, 720) - self.assertEqual(c.segment[1].ysiz, 243) - # Reference grid offset - self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) - # Tile size - self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (720, 243)) - # Tile offset - self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) - # bitdepth - self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) - # signed - self.assertEqual(c.segment[1].signed, (False, False, False)) - # subsampling - self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), - [(1, 1), (2, 1), (2, 1)]) - - # COD: Coding style default - self.assertFalse(c.segment[2].scod & 2) # no sop - self.assertFalse(c.segment[2].scod & 4) # no eph - self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) - self.assertEqual(c.segment[2].layers, 1) # layers = 1 - self.assertEqual(c.segment[2].spcod[3], 0) # mct - self.assertEqual(c.segment[2].spcod[4], 5) # level - self.assertEqual(tuple(c.segment[2].code_block_size), - (32, 128)) # cblk - # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].spcod[7] & 0x01) - # Reset context probabilities - self.assertFalse(c.segment[2].spcod[7] & 0x02) - # Termination on each coding pass - self.assertFalse(c.segment[2].spcod[7] & 0x04) - # Vertically causal context - self.assertFalse(c.segment[2].spcod[7] & 0x08) - # Predictable termination - self.assertFalse(c.segment[2].spcod[7] & 0x0010) - # Segmentation symbols - self.assertFalse(c.segment[2].spcod[7] & 0x0020) - self.assertEqual(c.segment[2].spcod[8], - glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].spcod), 9) - - # QCD: Quantization default - self.assertEqual(c.segment[3].sqcd & 0x1f, 2) - self.assertEqual(c.segment[3].guard_bits, 1) - self.assertEqual(c.segment[3].mantissa, - [1816, 1792, 1792, 1724, 1770, 1770, 1724, 1868, - 1868, 1892, 3, 3, 69, 2002, 2002, 1889]) - self.assertEqual(c.segment[3].exponent, - [13] * 4 + [12] * 3 + [11] * 3 + [9] * 6) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc_patch_jp2(self): - lst = ['input', 'nonregression', - 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2'] - jfile = opj_data_file('/'.join(lst)) - with self.assertWarns(UserWarning): - Jp2k(jfile) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_gdal_fuzzer_check_comp_dx_dy_jp2_dump(self): - lst = ['input', 'nonregression', 'gdal_fuzzer_check_comp_dx_dy.jp2'] - jfile = opj_data_file('/'.join(lst)) - with self.assertWarns(UserWarning): - Jp2k(jfile) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_gdal_fuzzer_check_number_of_tiles(self): - # Has an impossible tiling setup. - lst = ['input', 'nonregression', - 'gdal_fuzzer_check_number_of_tiles.jp2'] - jfile = opj_data_file('/'.join(lst)) - with self.assertWarns(UserWarning): - Jp2k(jfile) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_gdal_fuzzer_unchecked_numresolutions_dump(self): - # Has an invalid number of resolutions. - lst = ['input', 'nonregression', - 'gdal_fuzzer_unchecked_numresolutions.jp2'] - jfile = opj_data_file('/'.join(lst)) - with self.assertWarns(UserWarning): - Jp2k(jfile) - def test_NR_issue104_jpxstream_dump(self): jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') jp2 = Jp2k(jfile) @@ -6319,122 +6451,6 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) - def test_NR_text_GBR_dump(self): - # brand is 'jp2 ', but has any icc profile. - # Verify the warning on python3, but ignore it otherwise. - jfile = opj_data_file('input/nonregression/text_GBR.jp2') - if sys.hexversion > 0x03030000: - with self.assertWarns(UserWarning): - jp2 = Jp2k(jfile) - else: - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - jp2 = Jp2k(jfile) - - ids = [box.box_id for box in jp2.box] - lst = ['jP ', 'ftyp', 'rreq', 'jp2h', - 'uuid', 'uuid', 'uuid', 'uuid', 'jp2c'] - self.assertEqual(ids, lst) - - ids = [box.box_id for box in jp2.box[3].box] - self.assertEqual(ids, ['ihdr', 'colr', 'res ']) - - # Signature box. Check for corruption. - self.assertEqual(jp2.box[0].signature, (13, 10, 135, 10)) - - # File type box. - self.assertEqual(jp2.box[1].brand, 'jp2 ') - self.assertEqual(jp2.box[1].minor_version, 0) - self.assertEqual(jp2.box[1].compatibility_list[0], 'jp2 ') - - # Reader requirements. - # Compositing layer uses any icc profile - self.assertTrue(44 in jp2.box[2].standard_flag) - - # Jp2 Header - # Image header - self.assertEqual(jp2.box[3].box[0].height, 400) - self.assertEqual(jp2.box[3].box[0].width, 400) - self.assertEqual(jp2.box[3].box[0].num_components, 3) - self.assertEqual(jp2.box[3].box[0].bits_per_component, 8) - self.assertEqual(jp2.box[3].box[0].signed, False) - self.assertEqual(jp2.box[3].box[0].compression, 7) # wavelet - self.assertEqual(jp2.box[3].box[0].colorspace_unknown, True) - self.assertEqual(jp2.box[3].box[0].ip_provided, False) - - # Jp2 Header - # Colour specification - self.assertEqual(jp2.box[3].box[1].method, - glymur.core.ANY_ICC_PROFILE) - self.assertEqual(jp2.box[3].box[1].precedence, 2) - self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact - self.assertEqual(jp2.box[3].box[1].icc_profile['Size'], 1328) - self.assertIsNone(jp2.box[3].box[1].colorspace) - - # UUID boxes. All mentioned in the RREQ box. - self.assertEqual(jp2.box[2].vendor_feature[0], jp2.box[4].uuid) - self.assertEqual(jp2.box[2].vendor_feature[1], jp2.box[5].uuid) - self.assertEqual(jp2.box[2].vendor_feature[2], jp2.box[6].uuid) - self.assertEqual(jp2.box[2].vendor_feature[3], jp2.box[7].uuid) - - c = jp2.box[8].main_header - - ids = [x.marker_id for x in c.segment] - expected = ['SOC', 'SIZ', 'COD', 'QCD'] - self.assertEqual(ids, expected) - - # SIZ: Image and tile size - # Profile: - self.assertEqual(c.segment[1].rsiz, 0) - # Reference grid size - self.assertEqual(c.segment[1].xsiz, 400) - self.assertEqual(c.segment[1].ysiz, 400) - # Reference grid offset - self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) - # Tile size - self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) - # Tile offset - self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) - # bitdepth - self.assertEqual(c.segment[1].bitdepth, (8, 8, 8)) - # signed - self.assertEqual(c.segment[1].signed, (False, False, False)) - # subsampling - self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), - [(1, 1)] * 3) - - # COD: Coding style default - self.assertFalse(c.segment[2].scod & 2) # no sop - self.assertFalse(c.segment[2].scod & 4) # no eph - self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) - self.assertEqual(c.segment[2].layers, 6) # layers = 6 - self.assertEqual(c.segment[2].spcod[3], 1) # mct - self.assertEqual(c.segment[2].spcod[4], 5) # level - self.assertEqual(tuple(c.segment[2].code_block_size), - (32, 32)) # cblk - # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].spcod[7] & 0x01) - # Reset context probabilities - self.assertFalse(c.segment[2].spcod[7] & 0x02) - # Termination on each coding pass - self.assertFalse(c.segment[2].spcod[7] & 0x04) - # Vertically causal context - self.assertFalse(c.segment[2].spcod[7] & 0x08) - # Predictable termination - self.assertFalse(c.segment[2].spcod[7] & 0x0010) - # Segmentation symbols - self.assertFalse(c.segment[2].spcod[7] & 0x0020) - self.assertEqual(c.segment[2].spcod[8], - glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) - self.assertEqual(len(c.segment[2].spcod), 9) - - # QCD: Quantization default - self.assertEqual(c.segment[3].sqcd & 0x1f, 0) - self.assertEqual(c.segment[3].guard_bits, 2) - self.assertEqual(c.segment[3].mantissa, [0] * 16) - self.assertEqual(c.segment[3].exponent, - [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) - @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") @@ -6684,16 +6700,6 @@ class TestSuite2point1(unittest.TestCase): with self.assertRaises(RuntimeError): Jp2k(jfile).read() - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self): - # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it - # really does deserve a warning. - relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2' - jfile = opj_data_file(relpath) - with self.assertWarns(UserWarning): - Jp2k(jfile).read() - def test_NR_DEC_issue206_image_000_jp2_42_decode(self): jfile = opj_data_file('input/nonregression/issue206_image-000.jp2') Jp2k(jfile).read() diff --git a/glymur/test/test_opj_suite_neg.py b/glymur/test/test_opj_suite_neg.py index f6ef098..5a475a2 100644 --- a/glymur/test/test_opj_suite_neg.py +++ b/glymur/test/test_opj_suite_neg.py @@ -13,6 +13,7 @@ import re import sys import tempfile import unittest +import warnings import numpy as np @@ -77,14 +78,13 @@ class TestSuiteNegative(unittest.TestCase): jp2k.get_codestream(header_only=False) self.assertTrue(True) - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") def test_nr_illegalclrtransform(self): """EOC marker is bad""" relpath = 'input/nonregression/illegalcolortransform.j2k' jfile = opj_data_file(relpath) jp2k = Jp2k(jfile) - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') codestream = jp2k.get_codestream(header_only=False) # Verify that the last segment returned in the codestream is SOD, @@ -119,8 +119,6 @@ class TestSuiteNegative(unittest.TestCase): with self.assertRaises(IOError): j.write(data, cbsize=(2, 2048)) - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") def test_exceeded_box(self): """should warn if reading past end of a box""" # Verify that a warning is issued if we read past the end of a box @@ -128,7 +126,8 @@ class TestSuiteNegative(unittest.TestCase): # short. infile = os.path.join(OPJ_DATA_ROOT, 'input/nonregression/mem-b2ace68c-1381.jp2') - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('ignore') Jp2k(infile) @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index db40530..6734d01 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -70,7 +70,6 @@ class TestPrinting(unittest.TestCase): self.assertTrue(True) - @unittest.skipIf(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") def test_unknown_superbox(self): """Verify that we can handle an unknown superbox.""" with tempfile.NamedTemporaryFile(suffix='.jpx') as tfile: @@ -87,14 +86,19 @@ class TestPrinting(unittest.TestCase): tfile.write(write_buffer) tfile.flush() - with self.assertWarns(UserWarning): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') jpx = Jp2k(tfile.name) + self.assertTrue(len(w), 1) + glymur.set_printoptions(short=True) with patch('sys.stdout', new=StringIO()) as fake_out: print(jpx.box[-1]) actual = fake_out.getvalue().strip() - lines = ["Unknown Box (b'grp ') @ (1399071, 20)"] - expected = '\n'.join(lines) + if sys.hexversion < 0x03000000: + expected = "Unknown Box (grp ) @ (1399071, 20)" + else: + expected = "Unknown Box (b'grp ') @ (1399071, 20)" self.assertEqual(actual, expected) def test_printoptions_bad_argument(self): @@ -767,7 +771,7 @@ class TestPrintingOpjDataRoot(unittest.TestCase): with warnings.catch_warnings(): warnings.simplefilter("ignore") jp2 = Jp2k(jfile) - codestream = jp2.get_codestream() + codestream = jp2.get_codestream() with patch('sys.stdout', new=StringIO()) as fake_out: print(codestream.segment[2]) actual = fake_out.getvalue().strip()