From 86ac1c4ae5cc48ae6cb4142dfa2e804e686b89da Mon Sep 17 00:00:00 2001 From: John Evans Date: Thu, 13 Mar 2014 21:39:24 -0400 Subject: [PATCH] Fixed test skipping when no OPJ_DATA_ROOT present. #185 --- glymur/test/test_jp2box_xml.py | 2 ++ glymur/test/test_jp2k.py | 30 +++++++++++++++--------------- glymur/test/test_printing.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/glymur/test/test_jp2box_xml.py b/glymur/test/test_jp2box_xml.py index ff589f9..2531f0d 100644 --- a/glymur/test/test_jp2box_xml.py +++ b/glymur/test/test_jp2box_xml.py @@ -287,6 +287,8 @@ class TestBadButRecoverableXmlFile(unittest.TestCase): b'this is a test') +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") class TestXML_OpjDataRoot(unittest.TestCase): """Test suite for XML boxes, requires OPJ_DATA_ROOT.""" diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 16a1b80..f6eb691 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -109,21 +109,6 @@ class TestJp2k(unittest.TestCase): rgb_from_idx[r, c] = palette[idx[r, c]] np.testing.assert_array_equal(rgb, rgb_from_idx) - def test_no_cxform_cmap(self): - """Bands as physically ordered, not as physically intended""" - # This file has the components physically reversed. The cmap box - # tells the decoder how to order them, but this flag prevents that. - filename = opj_data_file('input/conformance/file2.jp2') - j = Jp2k(filename) - ycbcr = j.read() - crcby = j.read(no_cxform=True) - - expected = np.zeros(ycbcr.shape, ycbcr.dtype) - for k in range(crcby.shape[2]): - expected[:,:,crcby.shape[2] - k - 1] = crcby[:,:,k] - - np.testing.assert_array_equal(ycbcr, expected) - def test_file_not_present(self): """Should error out if reading from a file that does not exist""" # Verify that we error out appropriately if not given an existing file @@ -813,6 +798,21 @@ class TestJp2kOpjDataRoot(unittest.TestCase): with self.assertRaises(RuntimeError): j.read() + def test_no_cxform_cmap(self): + """Bands as physically ordered, not as physically intended""" + # This file has the components physically reversed. The cmap box + # tells the decoder how to order them, but this flag prevents that. + filename = opj_data_file('input/conformance/file2.jp2') + j = Jp2k(filename) + ycbcr = j.read() + crcby = j.read(no_cxform=True) + + expected = np.zeros(ycbcr.shape, ycbcr.dtype) + for k in range(crcby.shape[2]): + expected[:,:,crcby.shape[2] - k - 1] = crcby[:,:,k] + + np.testing.assert_array_equal(ycbcr, expected) + if __name__ == "__main__": diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 554e6de..fe09583 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -965,6 +965,19 @@ class TestPrintingOpjDataRoot(unittest.TestCase): actual = fake_out.getvalue().strip() self.assertEqual(actual, fixtures.issue_183_colr) + def test_bom(self): + """Byte order markers are illegal in UTF-8. Issue 185""" + filename = opj_data_file(os.path.join('input', + 'nonregression', + 'issue171.jp2')) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + jp2 = Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + # No need to verify, it's enough that we don't error out. + print(jp2) + + self.assertTrue(True) if __name__ == "__main__": unittest.main()