Modernized printing tests.

Using recipe 14.1 described in "Python Cookbook", mock.patch works much
better.
This commit is contained in:
John Evans 2013-07-15 06:40:13 -04:00
commit c35bcaead0

View file

@ -15,6 +15,11 @@ if sys.hexversion < 0x03000000:
else: else:
from io import StringIO from io import StringIO
if sys.hexversion <= 0x03030000:
from mock import patch
else:
from unittest.mock import patch
import glymur import glymur
from glymur import Jp2k from glymur import Jp2k
@ -52,10 +57,6 @@ class TestPrintingNeedsLib(unittest.TestCase):
self.jp2file = glymur.data.nemo() self.jp2file = glymur.data.nemo()
self.j2kfile = glymur.data.goodstuff() self.j2kfile = glymur.data.goodstuff()
# Save sys.stdout.
self.stdout = sys.stdout
sys.stdout = StringIO()
# Save the output of dumping nemo.jp2 for more than one test. # Save the output of dumping nemo.jp2 for more than one test.
lines = ['JPEG 2000 Signature Box (jP ) @ (0, 12)', lines = ['JPEG 2000 Signature Box (jP ) @ (0, 12)',
' Signature: 0d0a870a', ' Signature: 0d0a870a',
@ -122,8 +123,7 @@ class TestPrintingNeedsLib(unittest.TestCase):
self.expectedPlain = '\n'.join(lines) self.expectedPlain = '\n'.join(lines)
def tearDown(self): def tearDown(self):
# Restore stdout. pass
sys.stdout = self.stdout
def test_asoc_label_box(self): def test_asoc_label_box(self):
# Construct a fake file with an asoc and a label box, as # Construct a fake file with an asoc and a label box, as
@ -166,8 +166,9 @@ class TestPrintingNeedsLib(unittest.TestCase):
tfile2.flush() tfile2.flush()
jasoc = glymur.Jp2k(tfile2.name) jasoc = glymur.Jp2k(tfile2.name)
print(jasoc.box[3]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(jasoc.box[3])
actual = fake_out.getvalue().strip()
lines = ['Association Box (asoc) @ (77, 56)', lines = ['Association Box (asoc) @ (77, 56)',
' Label Box (lbl ) @ (85, 13)', ' Label Box (lbl ) @ (85, 13)',
' Label: label', ' Label: label',
@ -177,20 +178,21 @@ class TestPrintingNeedsLib(unittest.TestCase):
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
def test_jp2dump(self): def test_jp2dump(self):
glymur.jp2dump(self._plain_nemo_file) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() glymur.jp2dump(self._plain_nemo_file)
actual = fake_out.getvalue().strip()
# Get rid of the filename line, as it is not set in stone. # Get rid of the filename line, as it is not set in stone.
lst = actual.split('\n') lst = actual.split('\n')
lst = lst[1:] lst = lst[1:]
actual = '\n'.join(lst) actual = '\n'.join(lst)
self.maxDiff = None
self.assertEqual(actual, self.expectedPlain) self.assertEqual(actual, self.expectedPlain)
def test_entire_file(self): def test_entire_file(self):
j = glymur.Jp2k(self._plain_nemo_file) j = glymur.Jp2k(self._plain_nemo_file)
print(j) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j)
actual = fake_out.getvalue().strip()
# Get rid of the filename line, as it is not set in stone. # Get rid of the filename line, as it is not set in stone.
lst = actual.split('\n') lst = actual.split('\n')
@ -204,20 +206,17 @@ class TestPrinting(unittest.TestCase):
def setUp(self): def setUp(self):
# Save sys.stdout. # Save sys.stdout.
self.stdout = sys.stdout self.jp2file = glymur.data.nemo()
sys.stdout = StringIO()
self.jp2file = pkg_resources.resource_filename(glymur.__name__,
"data/nemo.jp2")
def tearDown(self): def tearDown(self):
# Restore stdout. pass
sys.stdout = self.stdout
def test_COC_segment(self): def test_COC_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[6]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[6])
actual = fake_out.getvalue().strip()
lines = ['COC marker segment @ (3260, 9)', lines = ['COC marker segment @ (3260, 9)',
' Associated component: 1', ' Associated component: 1',
@ -237,14 +236,14 @@ class TestPrinting(unittest.TestCase):
' Segmentation symbols: False'] ' Segmentation symbols: False']
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.maxDiff = None
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
def test_COD_segment(self): def test_COD_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[2])
actual = fake_out.getvalue().strip()
lines = ['COD marker segment @ (3186, 12)', lines = ['COD marker segment @ (3186, 12)',
' Coding style:', ' Coding style:',
@ -279,8 +278,9 @@ class TestPrinting(unittest.TestCase):
def test_icc_profile(self): def test_icc_profile(self):
filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2') filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[3].box[1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[3].box[1])
actual = fake_out.getvalue().strip()
lin27 = ["Colour Specification Box (colr) @ (179, 1339)", lin27 = ["Colour Specification Box (colr) @ (179, 1339)",
" Method: any ICC profile", " Method: any ICC profile",
" Precedence: 2", " Precedence: 2",
@ -344,8 +344,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k') filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[-5]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[-5])
actual = fake_out.getvalue().strip()
lines = ['CRG marker segment at (87, 6)', lines = ['CRG marker segment at (87, 6)',
' Vertical, Horizontal offset: (0.50, 1.00)'] ' Vertical, Horizontal offset: (0.50, 1.00)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -357,8 +358,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k') filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[12]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[12])
actual = fake_out.getvalue().strip()
lines = ['RGN marker segment @ (310, 5)', lines = ['RGN marker segment @ (310, 5)',
' Associated component: 0', ' Associated component: 0',
' ROI style: 0', ' ROI style: 0',
@ -372,8 +374,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k') filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[-2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[-2])
actual = fake_out.getvalue().strip()
lines = ['SOP marker segment @ (12836, 4)', lines = ['SOP marker segment @ (12836, 4)',
' Nsop: 15'] ' Nsop: 15']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -387,8 +390,9 @@ class TestPrinting(unittest.TestCase):
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
# 2nd to last segment in the main header # 2nd to last segment in the main header
print(codestream.segment[-2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[-2])
actual = fake_out.getvalue().strip()
lines = ['CME marker segment @ (85, 45)', lines = ['CME marker segment @ (85, 45)',
' "Creator: AV-J2K (c) 2000,2001 Algo Vision"'] ' "Creator: AV-J2K (c) 2000,2001 Algo Vision"']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -397,8 +401,9 @@ class TestPrinting(unittest.TestCase):
def test_EOC_segment(self): def test_EOC_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[-1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[-1])
actual = fake_out.getvalue().strip()
lines = ['EOC marker segment @ (1135421, 0)'] lines = ['EOC marker segment @ (1135421, 0)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -410,8 +415,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_07.j2k') filename = os.path.join(data_root, 'input/conformance/p0_07.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[49935]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[49935])
actual = fake_out.getvalue().strip()
lines = ['PLT marker segment @ (7871146, 38)', lines = ['PLT marker segment @ (7871146, 38)',
' Index: 0', ' Index: 0',
@ -427,8 +433,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_13.j2k') filename = os.path.join(data_root, 'input/conformance/p0_13.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[8]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[8])
actual = fake_out.getvalue().strip()
lines = ['POD marker segment @ (878, 20)', lines = ['POD marker segment @ (878, 20)',
' Progression change 0:', ' Progression change 0:',
@ -455,8 +462,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p1_03.j2k') filename = os.path.join(data_root, 'input/conformance/p1_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[9]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[9])
actual = fake_out.getvalue().strip()
lines = ['PPM marker segment @ (213, 43712)', lines = ['PPM marker segment @ (213, 43712)',
' Index: 0', ' Index: 0',
@ -471,8 +479,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p1_06.j2k') filename = os.path.join(data_root, 'input/conformance/p1_06.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[6]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[6])
actual = fake_out.getvalue().strip()
lines = ['PPT marker segment @ (155, 109)', lines = ['PPT marker segment @ (155, 109)',
' Index: 0', ' Index: 0',
@ -484,8 +493,9 @@ class TestPrinting(unittest.TestCase):
def test_QCC_segment(self): def test_QCC_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[7]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[7])
actual = fake_out.getvalue().strip()
lines = ['QCC marker segment @ (3271, 8)', lines = ['QCC marker segment @ (3271, 8)',
' Associated Component: 1', ' Associated Component: 1',
@ -498,8 +508,9 @@ class TestPrinting(unittest.TestCase):
def test_QCD_segment_5x3_transform(self): def test_QCD_segment_5x3_transform(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[3]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[3])
actual = fake_out.getvalue().strip()
lines = ['QCD marker segment @ (3200, 7)', lines = ['QCD marker segment @ (3200, 7)',
' Quantization style: no quantization, 2 guard bits', ' Quantization style: no quantization, 2 guard bits',
@ -511,8 +522,9 @@ class TestPrinting(unittest.TestCase):
def test_SIZ_segment(self): def test_SIZ_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[1])
actual = fake_out.getvalue().strip()
lines = ['SIZ marker segment @ (3137, 47)', lines = ['SIZ marker segment @ (3137, 47)',
' Profile: 2', ' Profile: 2',
@ -531,8 +543,9 @@ class TestPrinting(unittest.TestCase):
def test_SOC_segment(self): def test_SOC_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[0]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[0])
actual = fake_out.getvalue().strip()
lines = ['SOC marker segment @ (3135, 0)'] lines = ['SOC marker segment @ (3135, 0)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -541,8 +554,9 @@ class TestPrinting(unittest.TestCase):
def test_SOD_segment(self): def test_SOD_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[10]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[10])
actual = fake_out.getvalue().strip()
lines = ['SOD marker segment @ (3302, 0)'] lines = ['SOD marker segment @ (3302, 0)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -551,8 +565,9 @@ class TestPrinting(unittest.TestCase):
def test_SOT_segment(self): def test_SOT_segment(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
print(codestream.segment[5]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[5])
actual = fake_out.getvalue().strip()
lines = ['SOT marker segment @ (3248, 10)', lines = ['SOT marker segment @ (3248, 10)',
' Tile part index: 0', ' Tile part index: 0',
@ -570,8 +585,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_15.j2k') filename = os.path.join(data_root, 'input/conformance/p0_15.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[10]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[10])
actual = fake_out.getvalue().strip()
lines = ['TLM marker segment @ (268, 28)', lines = ['TLM marker segment @ (268, 28)',
' Index: 0', ' Index: 0',
@ -586,8 +602,10 @@ class TestPrinting(unittest.TestCase):
def test_xmp(self): def test_xmp(self):
# Verify the printing of a UUID/XMP box. # Verify the printing of a UUID/XMP box.
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
print(j.box[4]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[4])
actual = fake_out.getvalue().strip()
lst = ['UUID Box (uuid) @ (715, 2412)', lst = ['UUID Box (uuid) @ (715, 2412)',
' UUID: be7acfcb-97a9-42e8-9c71-999491e3afac (XMP)', ' UUID: be7acfcb-97a9-42e8-9c71-999491e3afac (XMP)',
' UUID Data: ', ' UUID Data: ',
@ -605,8 +623,9 @@ class TestPrinting(unittest.TestCase):
def test_codestream(self): def test_codestream(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
print(j.get_codestream()) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.get_codestream())
actual = fake_out.getvalue().strip()
lst = ['Codestream:', lst = ['Codestream:',
' SOC marker segment @ (3135, 0)', ' SOC marker segment @ (3135, 0)',
' SIZ marker segment @ (3137, 47)', ' SIZ marker segment @ (3137, 47)',
@ -658,8 +677,9 @@ class TestPrinting(unittest.TestCase):
def test_xml(self): def test_xml(self):
filename = os.path.join(data_root, 'input/conformance/file1.jp2') filename = os.path.join(data_root, 'input/conformance/file1.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[2])
actual = fake_out.getvalue().strip()
lines = ['XML Box (xml ) @ (36, 439)', lines = ['XML Box (xml ) @ (36, 439)',
' <ns0:IMAGE_CREATION ' ' <ns0:IMAGE_CREATION '
@ -687,8 +707,9 @@ class TestPrinting(unittest.TestCase):
def test_channel_definition(self): def test_channel_definition(self):
filename = os.path.join(data_root, 'input/conformance/file2.jp2') filename = os.path.join(data_root, 'input/conformance/file2.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[2].box[2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[2].box[2])
actual = fake_out.getvalue().strip()
lines = ['Channel Definition Box (cdef) @ (81, 28)', lines = ['Channel Definition Box (cdef) @ (81, 28)',
' Channel 0 (color) ==> (3)', ' Channel 0 (color) ==> (3)',
' Channel 1 (color) ==> (2)', ' Channel 1 (color) ==> (2)',
@ -701,8 +722,9 @@ class TestPrinting(unittest.TestCase):
def test_component_mapping(self): def test_component_mapping(self):
filename = os.path.join(data_root, 'input/conformance/file9.jp2') filename = os.path.join(data_root, 'input/conformance/file9.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[2].box[2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[2].box[2])
actual = fake_out.getvalue().strip()
lines = ['Component Mapping Box (cmap) @ (848, 20)', lines = ['Component Mapping Box (cmap) @ (848, 20)',
' Component 0 ==> palette column 0', ' Component 0 ==> palette column 0',
' Component 0 ==> palette column 1', ' Component 0 ==> palette column 1',
@ -715,8 +737,9 @@ class TestPrinting(unittest.TestCase):
def test_palette(self): def test_palette(self):
filename = os.path.join(data_root, 'input/conformance/file9.jp2') filename = os.path.join(data_root, 'input/conformance/file9.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[2].box[1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[2].box[1])
actual = fake_out.getvalue().strip()
lines = ['Palette Box (pclr) @ (66, 782)', lines = ['Palette Box (pclr) @ (66, 782)',
' Size: (256 x 3)'] ' Size: (256 x 3)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -727,8 +750,9 @@ class TestPrinting(unittest.TestCase):
def test_palette(self): def test_palette(self):
filename = os.path.join(data_root, 'input/conformance/file7.jp2') filename = os.path.join(data_root, 'input/conformance/file7.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[2]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[2])
actual = fake_out.getvalue().strip()
lines = ['Reader Requirements Box (rreq) @ (44, 24)', lines = ['Reader Requirements Box (rreq) @ (44, 24)',
' Standard Features:', ' Standard Features:',
' Feature 005: ' ' Feature 005: '
@ -750,8 +774,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k') filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[6]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[6])
actual = fake_out.getvalue().strip()
lines = ['CRG marker segment @ (87, 6)', lines = ['CRG marker segment @ (87, 6)',
' Vertical, Horizontal offset: (0.50, 1.00)'] ' Vertical, Horizontal offset: (0.50, 1.00)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -764,8 +789,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/conformance/p0_05.j2k') filename = os.path.join(data_root, 'input/conformance/p0_05.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
print(codestream.segment[1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(codestream.segment[1])
actual = fake_out.getvalue().strip()
lines = ['SIZ marker segment @ (2, 50)', lines = ['SIZ marker segment @ (2, 50)',
' Profile: 0', ' Profile: 0',
' Reference Grid Height, Width: (1024 x 1024)', ' Reference Grid Height, Width: (1024 x 1024)',
@ -785,8 +811,9 @@ class TestPrinting(unittest.TestCase):
# Verify that palette (pclr) boxes are printed without error. # Verify that palette (pclr) boxes are printed without error.
filename = os.path.join(data_root, 'input/conformance/file9.jp2') filename = os.path.join(data_root, 'input/conformance/file9.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[2].box[1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[2].box[1])
actual = fake_out.getvalue().strip()
lines = ['Palette Box (pclr) @ (66, 782)', lines = ['Palette Box (pclr) @ (66, 782)',
' Size: (256 x 3)'] ' Size: (256 x 3)']
expected = '\n'.join(lines) expected = '\n'.join(lines)
@ -845,9 +872,10 @@ class TestPrinting(unittest.TestCase):
tfile.flush() tfile.flush()
jp2k = glymur.Jp2k(tfile.name) jp2k = glymur.Jp2k(tfile.name)
print(jp2k.box[3]) with patch('sys.stdout', new=StringIO()) as fake_out:
print(jp2k.box[4]) print(jp2k.box[3])
actual = sys.stdout.getvalue().strip() print(jp2k.box[4])
actual = fake_out.getvalue().strip()
lines = ['UUIDInfo Box (uinf) @ (77, 50)', lines = ['UUIDInfo Box (uinf) @ (77, 50)',
' UUID List Box (ulst) @ (85, 26)', ' UUID List Box (ulst) @ (85, 26)',
' UUID[0]: 00000000-0000-0000-0000-000000000000', ' UUID[0]: 00000000-0000-0000-0000-000000000000',
@ -876,8 +904,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2') filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[3].box[1]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[3].box[1])
actual = fake_out.getvalue().strip()
lines = ["Colour Specification Box (colr) @ (179, 1339)", lines = ["Colour Specification Box (colr) @ (179, 1339)",
" Method: any ICC profile", " Method: any ICC profile",
" Precedence: 2", " Precedence: 2",
@ -915,8 +944,9 @@ class TestPrinting(unittest.TestCase):
filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2') filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
print(j.box[4]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[4])
actual = fake_out.getvalue().strip()
lines = ['UUID Box (uuid) @ (1544, 25)', lines = ['UUID Box (uuid) @ (1544, 25)',
' UUID: 3a0d0218-0ae9-4115-b376-4bca41ce0e71', ' UUID: 3a0d0218-0ae9-4115-b376-4bca41ce0e71',
' UUID Data: 1 bytes'] ' UUID Data: 1 bytes']
@ -929,8 +959,9 @@ class TestPrinting(unittest.TestCase):
def test_exif_uuid(self): def test_exif_uuid(self):
j = glymur.Jp2k(self.jp2file) j = glymur.Jp2k(self.jp2file)
print(j.box[3]) with patch('sys.stdout', new=StringIO()) as fake_out:
actual = sys.stdout.getvalue().strip() print(j.box[3])
actual = fake_out.getvalue().strip()
lines = ["UUID Box (uuid) @ (77, 638)", lines = ["UUID Box (uuid) @ (77, 638)",
" UUID: 4a706754-6966-6645-7869-662d3e4a5032 (Exif)", " UUID: 4a706754-6966-6645-7869-662d3e4a5032 (Exif)",