def setUp(self): self.jpxfile = glymur.data.jpxfile() self.jp2file = glymur.data.nemo() self.j2kfile = glymur.data.goodstuff() # Reset printoptions for every test. glymur.set_printoptions(short=False, xml=True, codestream=True)
def 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 unknown superbox. write_buffer = struct.pack('>I4s', 20, 'grp '.encode()) tfile.write(write_buffer) # Add a free box inside of it. We won't be able to identify it, # but it's there. write_buffer = struct.pack('>I4sI', 12, 'free'.encode(), 0) tfile.write(write_buffer) tfile.flush() with self.assertWarns(UserWarning): jpx = Jp2k(tfile.name) glymur.set_printoptions(short=True) with patch('sys.stdout', new=StringIO()) as fake_out: print(jpx.box[-1]) actual = fake_out.getvalue().strip() if sys.hexversion < 0x03000000: expected = "Unknown Box (grp ) @ (1399071, 20)" else: expected = "Unknown Box (b'grp ') @ (1399071, 20)" self.assertEqual(actual, expected)
def test_bad_deprecated_print_option(self): """ Verify exception when a bad option is given to old set_printoption """ with self.assertRaises(KeyError): with warnings.catch_warnings(): warnings.simplefilter('ignore') glymur.set_printoptions(blah='value-blah')
def test_suppress_codestream_old_option(self): """ Verify printing with codestream suppressed, deprecated """ jp2 = Jp2k(self.jp2file) with warnings.catch_warnings(): warnings.simplefilter('ignore') glymur.set_printoptions(codestream=False) with patch('sys.stdout', new=StringIO()) as fake_out: print(jp2) actual = fake_out.getvalue().strip() # Get rid of the file line, that's kind of volatile. actual = '\n'.join(actual.splitlines()[1:]) expected = fixtures.nemo_dump_no_codestream self.assertEqual(actual, expected) with warnings.catch_warnings(): warnings.simplefilter('ignore') opt = glymur.get_printoptions()['codestream'] self.assertFalse(opt)
def test_old_short_option(self): """ Verify printing with deprecated set_printoptions "short" """ jp2 = Jp2k(self.jp2file) with warnings.catch_warnings(): warnings.simplefilter('ignore') glymur.set_printoptions(short=True) with patch('sys.stdout', new=StringIO()) as fake_out: print(jp2) actual = fake_out.getvalue().strip() # Get rid of the file line, that's kind of volatile. actual = '\n'.join(actual.splitlines()[1:]) expected = fixtures.nemo_dump_short self.assertEqual(actual, expected) with warnings.catch_warnings(): warnings.simplefilter('ignore') opt = glymur.get_printoptions()['short'] self.assertTrue(opt)
def test_old_short_option(self): """ Verify printing with deprecated set_printoptions "short" """ jp2 = Jp2k(self.jp2file) with warnings.catch_warnings(): warnings.simplefilter('ignore') glymur.set_printoptions(short=True) actual = str(jp2) # Get rid of leading "File" line, as that is volatile. actual = '\n'.join(actual.splitlines()[1:]) expected = fixtures.nemo_dump_short self.assertEqual(actual, expected) with warnings.catch_warnings(): warnings.simplefilter('ignore') opt = glymur.get_printoptions()['short'] self.assertTrue(opt)
def test_suppress_xml_old_option(self): """ Verify printing with xml suppressed, deprecated method """ jp2 = Jp2k(self.jp2file) with warnings.catch_warnings(): warnings.simplefilter('ignore') glymur.set_printoptions(xml=False) with patch('sys.stdout', new=StringIO()) as fake_out: print(jp2) actual = fake_out.getvalue().strip() # Get rid of the file line, that's kind of volatile. actual = '\n'.join(actual.splitlines()[1:]) # shave off the XML and non-main-header segments expected = fixtures.nemo_dump_no_xml self.assertEqual(actual, expected) with warnings.catch_warnings(): warnings.simplefilter('ignore') opt = glymur.get_printoptions()['xml'] self.assertFalse(opt)
def test_suppress_xml_old_option(self): """ Verify printing with xml suppressed, deprecated method """ jp2 = Jp2k(self.jp2file) with warnings.catch_warnings(): warnings.simplefilter('ignore') glymur.set_printoptions(xml=False) actual = str(jp2) # Get rid of leading "File" line, as that is volatile. actual = '\n'.join(actual.splitlines()[1:]) # shave off the XML and non-main-header segments expected = fixtures.nemo_dump_no_xml self.assertEqual(actual, expected) with warnings.catch_warnings(): warnings.simplefilter('ignore') opt = glymur.get_printoptions()['xml'] self.assertFalse(opt)
def test_deprecated_set_get_printoptions(self): """ Verify deprecated get_printoptions and set_printoptions """ with self.assertWarns(DeprecationWarning): glymur.set_printoptions(short=True) with self.assertWarns(DeprecationWarning): glymur.set_printoptions(xml=True) with self.assertWarns(DeprecationWarning): glymur.set_printoptions(codestream=True) with self.assertWarns(DeprecationWarning): glymur.get_printoptions()
def test_printoptions_bad_argument(self): """Verify error when bad parameter to set_printoptions""" with self.assertRaises(TypeError): glymur.set_printoptions(hi='low')