diff --git a/glymur/test/test_jp2box_xml.py b/glymur/test/test_jp2box_xml.py index 9194a49..8650895 100644 --- a/glymur/test/test_jp2box_xml.py +++ b/glymur/test/test_jp2box_xml.py @@ -94,6 +94,8 @@ class TestXML(unittest.TestCase): def tearDown(self): os.unlink(self.xmlfile) + @unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") def test_invalid_utf8(self): """Bad byte sequence that cannot be parsed.""" filename = opj_data_file(os.path.join('input', diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 6a819ac..2b8b26c 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -289,69 +289,6 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_crg(self): - """verify printing of CRG segment""" - filename = opj_data_file('input/conformance/p0_03.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream() - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[-5]) - actual = fake_out.getvalue().strip() - lines = ['CRG marker segment @ (87, 6)', - ' Vertical, Horizontal offset: (0.50, 1.00)'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_rgn(self): - """verify printing of RGN segment""" - filename = opj_data_file('input/conformance/p0_03.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream(header_only=False) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[12]) - actual = fake_out.getvalue().strip() - lines = ['RGN marker segment @ (310, 5)', - ' Associated component: 0', - ' ROI style: 0', - ' Parameter: 7'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_sop(self): - """verify printing of SOP segment""" - filename = opj_data_file('input/conformance/p0_03.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream(header_only=False) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[-2]) - actual = fake_out.getvalue().strip() - lines = ['SOP marker segment @ (12836, 4)', - ' Nsop: 15'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_cme(self): - """Test printing a CME or comment marker segment.""" - filename = opj_data_file('input/conformance/p0_02.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream() - # 2nd to last segment in the main header - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[-2]) - actual = fake_out.getvalue().strip() - lines = ['CME marker segment @ (85, 45)', - ' "Creator: AV-J2K (c) 2000,2001 Algo Vision"'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - def test_eoc_segment(self): """verify printing of eoc segment""" j = glymur.Jp2k(self.jp2file) @@ -364,91 +301,6 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_plt_segment(self): - """verify printing of PLT segment""" - filename = opj_data_file('input/conformance/p0_07.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream(header_only=False) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[49935]) - actual = fake_out.getvalue().strip() - - lines = ['PLT marker segment @ (7871146, 38)', - ' Index: 0', - ' Iplt: [9, 122, 19, 30, 27, 9, 41, 62, 18, 29, 261,' - + ' 55, 82, 299, 93, 941, 951, 687, 1729, 1443, 1008, 2168,' - + ' 2188, 2223]'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_pod_segment(self): - """verify printing of POD segment""" - filename = opj_data_file('input/conformance/p0_13.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream() - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[8]) - actual = fake_out.getvalue().strip() - - lines = ['POD marker segment @ (878, 20)', - ' Progression change 0:', - ' Resolution index start: 0', - ' Component index start: 0', - ' Layer index end: 1', - ' Resolution index end: 33', - ' Component index end: 128', - ' Progression order: RLCP', - ' Progression change 1:', - ' Resolution index start: 0', - ' Component index start: 128', - ' Layer index end: 1', - ' Resolution index end: 33', - ' Component index end: 257', - ' Progression order: CPRL'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_ppm_segment(self): - """verify printing of PPM segment""" - filename = opj_data_file('input/conformance/p1_03.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream() - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[9]) - actual = fake_out.getvalue().strip() - - lines = ['PPM marker segment @ (213, 43712)', - ' Index: 0', - ' Data: 43709 uninterpreted bytes'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_ppt_segment(self): - """verify printing of ppt segment""" - filename = opj_data_file('input/conformance/p1_06.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream(header_only=False) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[6]) - actual = fake_out.getvalue().strip() - - lines = ['PPT marker segment @ (155, 109)', - ' Index: 0', - ' Packet headers: 106 uninterpreted bytes'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - def test_qcc_segment(self): """verify printing of qcc segment""" j = glymur.Jp2k(self.jp2file) @@ -543,25 +395,6 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_tlm_segment(self): - """verify printing of TLM segment""" - filename = opj_data_file('input/conformance/p0_15.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream() - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[10]) - actual = fake_out.getvalue().strip() - - lines = ['TLM marker segment @ (268, 28)', - ' Index: 0', - ' Tile number: (0, 1, 2, 3)', - ' Length: (4267, 2117, 4080, 2081)'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - def test_xmp(self): """Verify the printing of a UUID/XMP box.""" j = glymur.Jp2k(self.jp2file) @@ -621,17 +454,6 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lst) self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_xml(self): - """verify printing of XML box""" - filename = opj_data_file('input/conformance/file1.jp2') - j = glymur.Jp2k(filename) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(j.box[2]) - actual = fake_out.getvalue().strip() - self.assertEqual(actual, fixtures.file1_xml) - @unittest.skipIf(sys.hexversion < 0x03000000, "Only trusting python3 for printing non-ascii chars") def test_xml_latin1(self): @@ -689,101 +511,6 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_channel_definition(self): - """verify printing of cdef box""" - filename = opj_data_file('input/conformance/file2.jp2') - j = glymur.Jp2k(filename) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(j.box[2].box[2]) - actual = fake_out.getvalue().strip() - lines = ['Channel Definition Box (cdef) @ (81, 28)', - ' Channel 0 (color) ==> (3)', - ' Channel 1 (color) ==> (2)', - ' Channel 2 (color) ==> (1)'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_component_mapping(self): - """verify printing of cmap box""" - filename = opj_data_file('input/conformance/file9.jp2') - j = glymur.Jp2k(filename) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(j.box[2].box[2]) - actual = fake_out.getvalue().strip() - lines = ['Component Mapping Box (cmap) @ (848, 20)', - ' Component 0 ==> palette column 0', - ' Component 0 ==> palette column 1', - ' Component 0 ==> palette column 2'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_palette7(self): - """verify printing of pclr box""" - filename = opj_data_file('input/conformance/file9.jp2') - j = glymur.Jp2k(filename) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(j.box[2].box[1]) - actual = fake_out.getvalue().strip() - lines = ['Palette Box (pclr) @ (66, 782)', - ' Size: (256 x 3)'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skip("file7 no longer has a rreq") - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_rreq(self): - """verify printing of reader requirements box""" - filename = opj_data_file('input/nonregression/text_GBR.jp2') - j = glymur.Jp2k(filename) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(j.box[2]) - actual = fake_out.getvalue().strip() - self.assertEqual(actual, fixtures.text_GBR_rreq) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_differing_subsamples(self): - """verify printing of SIZ with different subsampling... Issue 86.""" - filename = opj_data_file('input/conformance/p0_05.j2k') - j = glymur.Jp2k(filename) - codestream = j.get_codestream() - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[1]) - actual = fake_out.getvalue().strip() - lines = ['SIZ marker segment @ (2, 50)', - ' Profile: 0', - ' Reference Grid Height, Width: (1024 x 1024)', - ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', - ' Reference Tile Height, Width: (1024 x 1024)', - ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', - ' Bitdepth: (8, 8, 8, 8)', - ' Signed: (False, False, False, False)', - ' Vertical, Horizontal Subsampling: ' - + '((1, 1), (1, 1), (2, 2), (2, 2))'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_palette_box(self): - """Verify that palette (pclr) boxes are printed without error.""" - filename = opj_data_file('input/conformance/file9.jp2') - j = glymur.Jp2k(filename) - with patch('sys.stdout', new=StringIO()) as fake_out: - print(j.box[2].box[1]) - actual = fake_out.getvalue().strip() - lines = ['Palette Box (pclr) @ (66, 782)', - ' Size: (256 x 3)'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") def test_less_common_boxes(self): """verify uinf, ulst, url, res, resd, resc box printing""" @@ -861,8 +588,304 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") + @unittest.skipIf(sys.hexversion < 0x03000000, + "Ordered dicts not printing well in 2.7") + def test_exif_uuid(self): + """Verify printing of exif information""" + with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile: + + with open(self.jp2file, 'rb') as ifptr: + tfile.write(ifptr.read()) + + # Write L, T, UUID identifier. + tfile.write(struct.pack('>I4s', 76, b'uuid')) + tfile.write(b'JpgTiffExif->JP2') + + tfile.write(b'Exif\x00\x00') + xbuffer = struct.pack(' (3)', + ' Channel 1 (color) ==> (2)', + ' Channel 2 (color) ==> (1)'] + expected = '\n'.join(lines) + self.assertEqual(actual, expected) + + def test_component_mapping(self): + """verify printing of cmap box""" + filename = opj_data_file('input/conformance/file9.jp2') + j = glymur.Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + print(j.box[2].box[2]) + actual = fake_out.getvalue().strip() + lines = ['Component Mapping Box (cmap) @ (848, 20)', + ' Component 0 ==> palette column 0', + ' Component 0 ==> palette column 1', + ' Component 0 ==> palette column 2'] + expected = '\n'.join(lines) + self.assertEqual(actual, expected) + + def test_palette7(self): + """verify printing of pclr box""" + filename = opj_data_file('input/conformance/file9.jp2') + j = glymur.Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + print(j.box[2].box[1]) + actual = fake_out.getvalue().strip() + lines = ['Palette Box (pclr) @ (66, 782)', + ' Size: (256 x 3)'] + expected = '\n'.join(lines) + self.assertEqual(actual, expected) + + @unittest.skip("file7 no longer has a rreq") + def test_rreq(self): + """verify printing of reader requirements box""" + filename = opj_data_file('input/nonregression/text_GBR.jp2') + j = glymur.Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + print(j.box[2]) + actual = fake_out.getvalue().strip() + self.assertEqual(actual, fixtures.text_GBR_rreq) + + def test_differing_subsamples(self): + """verify printing of SIZ with different subsampling... Issue 86.""" + filename = opj_data_file('input/conformance/p0_05.j2k') + j = glymur.Jp2k(filename) + codestream = j.get_codestream() + with patch('sys.stdout', new=StringIO()) as fake_out: + print(codestream.segment[1]) + actual = fake_out.getvalue().strip() + lines = ['SIZ marker segment @ (2, 50)', + ' Profile: 0', + ' Reference Grid Height, Width: (1024 x 1024)', + ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', + ' Reference Tile Height, Width: (1024 x 1024)', + ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', + ' Bitdepth: (8, 8, 8, 8)', + ' Signed: (False, False, False, False)', + ' Vertical, Horizontal Subsampling: ' + + '((1, 1), (1, 1), (2, 2), (2, 2))'] + expected = '\n'.join(lines) + self.assertEqual(actual, expected) + + def test_palette_box(self): + """Verify that palette (pclr) boxes are printed without error.""" + filename = opj_data_file('input/conformance/file9.jp2') + j = glymur.Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + print(j.box[2].box[1]) + actual = fake_out.getvalue().strip() + lines = ['Palette Box (pclr) @ (66, 782)', + ' Size: (256 x 3)'] + expected = '\n'.join(lines) + self.assertEqual(actual, expected) + def test_icc_profile(self): """verify icc profile printing with a jpx""" # ICC profiles may be used in JP2, but the approximation field should @@ -885,8 +908,6 @@ class TestPrinting(unittest.TestCase): self.assertEqual(actual, expected) - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") def test_uuid(self): """verify printing of UUID box""" filename = opj_data_file('input/nonregression/text_GBR.jp2') @@ -932,46 +953,6 @@ class TestPrinting(unittest.TestCase): actual = fake_out.getvalue().strip() self.assertEqual(actual, fixtures.issue_183_colr) - @unittest.skipIf(sys.hexversion < 0x03000000, - "Ordered dicts not printing well in 2.7") - def test_exif_uuid(self): - """Verify printing of exif information""" - with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile: - - with open(self.jp2file, 'rb') as ifptr: - tfile.write(ifptr.read()) - - # Write L, T, UUID identifier. - tfile.write(struct.pack('>I4s', 76, b'uuid')) - tfile.write(b'JpgTiffExif->JP2') - - tfile.write(b'Exif\x00\x00') - xbuffer = struct.pack('