Print options remaining persistent across invocations. #162

This commit is contained in:
John Evans 2014-02-10 06:58:11 -05:00
commit 47d8e8470b
2 changed files with 25 additions and 4 deletions

View file

@ -2829,7 +2829,7 @@ _BOX_WITH_ID = {
_printoptions = {'short': False, 'xml': True, 'codestream': True}
def set_printoptions(short=False, xml=True, codestream=True):
def set_printoptions(**kwargs):
"""Set printing options.
These options determine the way JPEG 2000 boxes are displayed.
@ -2856,9 +2856,10 @@ def set_printoptions(short=False, xml=True, codestream=True):
>>> import glymur
>>> glymur.set_printoptions(short=False, xml=True, codestream=True)
"""
_printoptions['short'] = short
_printoptions['xml'] = xml
_printoptions['codestream'] = codestream
for key, value in kwargs.items():
if key not in ['short', 'xml', 'codestream']:
raise TypeError('"{0}" not a valid keyword parameter.'.format(key))
_printoptions[key] = value
def get_printoptions():
"""Return the current print options.

View file

@ -48,6 +48,26 @@ class TestPrinting(unittest.TestCase):
def tearDown(self):
pass
def test_printoptions_bad_argument(self):
"""Verify error when bad parameter to set_printoptions"""
with self.assertRaises(TypeError):
glymur.set_printoptions(hi='low')
def test_printopt_no_codestr_then_no_xml(self):
"""Verify printed output when codestream=False and xml=False, #162"""
# The print options should be persistent across invocations.
glymur.set_printoptions(codestream=False)
glymur.set_printoptions(xml=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
glymur.jp2dump(self.jp2file)
actual = fake_out.getvalue().strip()
# Get rid of the filename line, as it is not set in stone.
lst = actual.split('\n')
lst = lst[1:]
actual = '\n'.join(lst)
self.assertEqual(actual, fixtures.nemo_dump_no_codestream_no_xml)
def test_printopt_no_codestr_or_xml(self):
"""Verify printed output when codestream=False and xml=False"""
glymur.set_printoptions(codestream=False, xml=False)