pylint work, #99

This commit is contained in:
jevans 2013-08-11 20:08:15 -04:00
commit 1a84ca2386
2 changed files with 197 additions and 167 deletions

View file

@ -2,7 +2,12 @@
The tests here do not correspond directly to the OpenJPEG test suite, but
seem like logical negative tests to add.
"""
#pylint: disable-all
# E1101: assertWarns introduced in python 3.2
# pylint: disable=E1101
# R0904: Not too many methods in unittest.
# pylint: disable=R0904
import os
import sys
import tempfile
@ -13,9 +18,6 @@ else:
import unittest
import numpy as np
import pkg_resources
from glymur.lib import openjp2 as opj2
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
@ -23,9 +25,9 @@ from glymur import Jp2k
import glymur
try:
data_root = os.environ['OPJ_DATA_ROOT']
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
data_root = None
DATA_ROOT = None
except:
raise
@ -33,9 +35,10 @@ except:
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
"Missing openjp2 library.")
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegative(unittest.TestCase):
"""Test suite for certain negative tests from openjpeg suite."""
def setUp(self):
self.jp2file = glymur.data.nemo()
@ -45,45 +48,50 @@ class TestSuiteNegative(unittest.TestCase):
pass
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_negative_psnr_with_cratios(self):
# Using psnr with cratios options is not allowed.
def test_psnr_with_cratios(self):
"""Using psnr with cratios options is not allowed."""
# Not an OpenJPEG test, but close.
infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm')
infile = os.path.join(DATA_ROOT, 'input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, psnr=[30, 35, 40], cratios=[2, 3, 4])
def test_NR_MarkerIsNotCompliant_j2k_dump(self):
def test_nr_marker_not_compliant(self):
"""non-compliant marker, should still be able to read"""
relpath = 'input/nonregression/MarkerIsNotCompliant.j2k'
jfile = os.path.join(data_root, relpath)
jfile = os.path.join(DATA_ROOT, relpath)
jp2k = Jp2k(jfile)
c = jp2k.get_codestream(header_only=False)
jp2k.get_codestream(header_only=False)
self.assertTrue(True)
@unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.")
def test_NR_illegalcolortransform_dump(self):
# EOC marker is bad
def test_nr_illegalclrtransform(self):
"""EOC marker is bad"""
relpath = 'input/nonregression/illegalcolortransform.j2k'
jfile = os.path.join(data_root, relpath)
jfile = os.path.join(DATA_ROOT, relpath)
jp2k = Jp2k(jfile)
with self.assertWarns(UserWarning) as cw:
c = jp2k.get_codestream(header_only=False)
with self.assertWarns(UserWarning):
codestream = jp2k.get_codestream(header_only=False)
# Verify that the last segment returned in the codestream is SOD,
# not EOC. Codestream parsing should stop when we try to jump to
# the end of SOT.
self.assertEqual(c.segment[-1].marker_id, 'SOD')
self.assertEqual(codestream.segment[-1].marker_id, 'SOD')
def test_NR_Cannotreaddatawithnosizeknown_j2k(self):
def test_nr_cannotreadwnosizeknown(self):
"""not sure exactly what is wrong with this file"""
relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
jfile = os.path.join(data_root, relpath)
jfile = os.path.join(DATA_ROOT, relpath)
jp2k = Jp2k(jfile)
c = jp2k.get_codestream(header_only=False)
jp2k.get_codestream(header_only=False)
self.assertTrue(True)
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_code_block_dimensions(self):
"""don't allow extreme codeblock sizes"""
# opj_compress doesn't allow the dimensions of a codeblock
# to be too small or too big, so neither will we.
data = np.zeros((256, 256), dtype=np.uint8)
@ -91,55 +99,55 @@ class TestSuiteNegative(unittest.TestCase):
j = Jp2k(tfile.name, 'wb')
# opj_compress doesn't allow code block area to exceed 4096.
with self.assertRaises(IOError) as cr:
with self.assertRaises(IOError):
j.write(data, cbsize=(256, 256))
# opj_compress doesn't allow either dimension to be less than 4.
with self.assertRaises(IOError) as cr:
with self.assertRaises(IOError):
j.write(data, cbsize=(2048, 2))
with self.assertRaises(IOError) as cr:
with self.assertRaises(IOError):
j.write(data, cbsize=(2, 2048))
@unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.")
def test_exceeded_box(self):
"""should warn if reading past end of a box"""
# Verify that a warning is issued if we read past the end of a box
# This file has a palette (pclr) box whose length is impossibly
# short.
infile = os.path.join(data_root,
infile = os.path.join(DATA_ROOT,
'input/nonregression/mem-b2ace68c-1381.jp2')
with self.assertWarns(UserWarning) as cw:
j = Jp2k(infile)
with self.assertWarns(UserWarning):
Jp2k(infile)
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_precinct_size_not_multiple_of_two(self):
# Seems like precinct sizes should be powers of two.
def test_precinct_size_not_p2(self):
"""precinct sizes should be powers of two."""
ifile = Jp2k(self.j2kfile)
data = ifile.read(rlevel=2)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError) as ce:
with self.assertRaises(IOError):
ofile.write(data, psizes=[(13, 13)])
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_codeblock_size_not_multiple_of_two(self):
# Seems like code block sizes should be powers of two.
def test_cblk_size_not_power_of_two(self):
"""code block sizes should be powers of two."""
ifile = Jp2k(self.j2kfile)
data = ifile.read(rlevel=2)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError) as ce:
with self.assertRaises(IOError):
ofile.write(data, cbsize=(13, 12))
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_codeblock_size_with_precinct_size(self):
# Seems like code block sizes should never exceed half that of
# precinct size.
def test_cblk_size_precinct_size(self):
"""code block sizes should never exceed half that of precinct size."""
ifile = Jp2k(self.j2kfile)
data = ifile.read(rlevel=2)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError) as ce:
with self.assertRaises(IOError):
ofile.write(data,
cbsize=(64, 64),
psizes=[(64, 64)])

View file

@ -1,7 +1,15 @@
#pylint: disable-all
"""Test suite for printing.
"""
# C0302: don't care too much about having too many lines in a test module
# pylint: disable=C0302
# E061: unittest.mock introduced in 3.3 (python-2.7/pylint issue)
# pylint: disable=E0611,F0401
# R0904: Not too many methods in unittest.
# pylint: disable=R0904
import os
import pkg_resources
import re
import struct
import sys
import tempfile
@ -26,9 +34,9 @@ import glymur
from glymur import Jp2k
try:
data_root = os.environ['OPJ_DATA_ROOT']
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
data_root = None
DATA_ROOT = None
except:
raise
@ -122,12 +130,13 @@ class TestPrintingNeedsLib(unittest.TestCase):
+ '(0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), '
+ '(0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), '
+ '(0, 10)]']
self.expectedPlain = '\n'.join(lines)
self.expected_plain = '\n'.join(lines)
def tearDown(self):
pass
def test_asoc_label_box(self):
"""verify printing of asoc, label boxes"""
# Construct a fake file with an asoc and a label box, as
# OpenJPEG doesn't have such a file.
data = glymur.Jp2k(self.jp2file).read(rlevel=1)
@ -138,30 +147,30 @@ class TestPrintingNeedsLib(unittest.TestCase):
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2:
# Offset of the codestream is where we start.
buffer = tfile.read(77)
tfile2.write(buffer)
wbuffer = tfile.read(77)
tfile2.write(wbuffer)
# read the rest of the file, it's the codestream.
codestream = tfile.read()
# Write the asoc superbox.
# Length = 36, id is 'asoc'.
buffer = struct.pack('>I4s', int(56), b'asoc')
tfile2.write(buffer)
wbuffer = struct.pack('>I4s', int(56), b'asoc')
tfile2.write(wbuffer)
# Write the contained label box
buffer = struct.pack('>I4s', int(13), b'lbl ')
tfile2.write(buffer)
wbuffer = struct.pack('>I4s', int(13), b'lbl ')
tfile2.write(wbuffer)
tfile2.write('label'.encode())
# Write the xml box
# Length = 36, id is 'xml '.
buffer = struct.pack('>I4s', int(35), b'xml ')
tfile2.write(buffer)
wbuffer = struct.pack('>I4s', int(35), b'xml ')
tfile2.write(wbuffer)
buffer = '<test>this is a test</test>'
buffer = buffer.encode()
tfile2.write(buffer)
wbuffer = '<test>this is a test</test>'
wbuffer = wbuffer.encode()
tfile2.write(wbuffer)
# Now append the codestream.
tfile2.write(codestream)
@ -180,6 +189,7 @@ class TestPrintingNeedsLib(unittest.TestCase):
self.assertEqual(actual, expected)
def test_jp2dump(self):
"""basic jp2dump test"""
with patch('sys.stdout', new=StringIO()) as fake_out:
glymur.jp2dump(self._plain_nemo_file)
actual = fake_out.getvalue().strip()
@ -188,9 +198,10 @@ class TestPrintingNeedsLib(unittest.TestCase):
lst = actual.split('\n')
lst = lst[1:]
actual = '\n'.join(lst)
self.assertEqual(actual, self.expectedPlain)
self.assertEqual(actual, self.expected_plain)
def test_entire_file(self):
"""verify output from printing entire file"""
j = glymur.Jp2k(self._plain_nemo_file)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j)
@ -201,10 +212,11 @@ class TestPrintingNeedsLib(unittest.TestCase):
lst = lst[1:]
actual = '\n'.join(lst)
self.assertEqual(actual, self.expectedPlain)
self.assertEqual(actual, self.expected_plain)
class TestPrinting(unittest.TestCase):
"""Test suite for printing where the libraries are not needed"""
def setUp(self):
# Save sys.stdout.
@ -213,7 +225,8 @@ class TestPrinting(unittest.TestCase):
def tearDown(self):
pass
def test_COC_segment(self):
def test_coc_segment(self):
"""verify printing of COC segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -240,7 +253,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_COD_segment(self):
def test_cod_segment(self):
"""verify printing of COD segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -271,14 +285,13 @@ class TestPrinting(unittest.TestCase):
' Segmentation symbols: False']
expected = '\n'.join(lines)
self.actual = actual
self.expected = expected
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_icc_profile(self):
filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2')
"""verify printing of colr box with ICC profile"""
filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
@ -343,24 +356,26 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_CRG(self):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
def test_crg(self):
"""verify printing of CRG segment"""
filename = os.path.join(DATA_ROOT, '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 at (87, 6)',
lines = ['CRG marker segment @ (87, 6)',
' Vertical, Horizontal offset: (0.50, 1.00)']
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_RGN(self):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
def test_rgn(self):
"""verify printing of RGN segment"""
filename = os.path.join(DATA_ROOT, '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:
@ -373,10 +388,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_SOP(self):
filename = os.path.join(data_root, 'input/conformance/p0_03.j2k')
def test_sop(self):
"""verify printing of SOP segment"""
filename = os.path.join(DATA_ROOT, '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:
@ -387,11 +403,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_CME(self):
# Test printing a CME or comment marker segment.
filename = os.path.join(data_root, 'input/conformance/p0_02.j2k')
def test_cme(self):
"""Test printing a CME or comment marker segment."""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_02.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
# 2nd to last segment in the main header
@ -403,7 +419,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_EOC_segment(self):
def test_eoc_segment(self):
"""verify printing of eoc segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -414,10 +431,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_PLT_segment(self):
filename = os.path.join(data_root, 'input/conformance/p0_07.j2k')
def test_plt_segment(self):
"""verify printing of PLT segment"""
filename = os.path.join(DATA_ROOT, '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:
@ -432,10 +450,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_POD_segment(self):
filename = os.path.join(data_root, 'input/conformance/p0_13.j2k')
def test_pod_segment(self):
"""verify printing of POD segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_13.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -461,10 +480,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_PPM_segment(self):
filename = os.path.join(data_root, 'input/conformance/p1_03.j2k')
def test_ppm_segment(self):
"""verify printing of PPM segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p1_03.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -478,10 +498,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_PPT_segment(self):
filename = os.path.join(data_root, 'input/conformance/p1_06.j2k')
def test_ppt_segment(self):
"""verify printing of ppt segment"""
filename = os.path.join(DATA_ROOT, '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:
@ -495,7 +516,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_QCC_segment(self):
def test_qcc_segment(self):
"""verify printing of qcc segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -510,7 +532,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_QCD_segment_5x3_transform(self):
def test_qcd_segment_5x3_transform(self):
"""verify printing of qcd segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -524,7 +547,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_SIZ_segment(self):
def test_siz_segment(self):
"""verify printing of SIZ segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -545,7 +569,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_SOC_segment(self):
def test_soc_segment(self):
"""verify printing of SOC segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -556,7 +581,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_SOD_segment(self):
def test_sod_segment(self):
"""verify printing of SOD segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -567,7 +593,8 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
def test_SOT_segment(self):
def test_sot_segment(self):
"""verify printing of SOT segment"""
j = glymur.Jp2k(self.jp2file)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -581,13 +608,13 @@ class TestPrinting(unittest.TestCase):
' Number of tile parts: 1']
expected = '\n'.join(lines)
self.maxDiff = None
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_TLM_segment(self):
filename = os.path.join(data_root, 'input/conformance/p0_15.j2k')
def test_tlm_segment(self):
"""verify printing of TLM segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_15.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -605,7 +632,7 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x02070000,
"Differences in XML printing between 2.6 and 2.7")
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)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[4])
@ -627,6 +654,7 @@ class TestPrinting(unittest.TestCase):
self.assertEqual(actual, expected)
def test_codestream(self):
"""verify printing of entire codestream"""
j = glymur.Jp2k(self.jp2file)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.get_codestream())
@ -672,15 +700,15 @@ class TestPrinting(unittest.TestCase):
' CME marker segment @ (3209, 37)',
' "Created by OpenJPEG version 2.0.0"']
expected = '\n'.join(lst)
self.maxDiff = None
self.assertEqual(actual, expected)
@unittest.skipIf(sys.hexversion < 0x02070000,
"Differences in XML printing between 2.6 and 2.7")
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_xml(self):
filename = os.path.join(data_root, 'input/conformance/file1.jp2')
"""verify printing of XML box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file1.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2])
@ -707,10 +735,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_channel_definition(self):
filename = os.path.join(data_root, 'input/conformance/file2.jp2')
"""verify printing of cdef box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file2.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2])
@ -722,10 +751,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_component_mapping(self):
filename = os.path.join(data_root, 'input/conformance/file9.jp2')
"""verify printing of cmap box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2])
@ -737,10 +767,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_palette(self):
filename = os.path.join(data_root, 'input/conformance/file9.jp2')
def test_palette7(self):
"""verify printing of pclr box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1])
@ -750,10 +781,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_palette(self):
filename = os.path.join(data_root, 'input/conformance/file7.jp2')
def test_rreq(self):
"""verify printing of reader requirements box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file7.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2])
@ -773,25 +805,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
"OPJ_DATA_ROOT environment variable not set")
def test_CRG(self):
filename = os.path.join(data_root, '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[6])
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(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_differing_subsamples(self):
# Issue 86.
filename = os.path.join(data_root, 'input/conformance/p0_05.j2k')
"""verify printing of SIZ with different subsampling... Issue 86."""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@ -810,11 +828,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(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 = os.path.join(data_root, 'input/conformance/file9.jp2')
"""Verify that palette (pclr) boxes are printed without error."""
filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1])
@ -826,54 +844,56 @@ class TestPrinting(unittest.TestCase):
@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"""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
with open(self.jp2file, 'rb') as ifile:
# Everything up until the jp2c box.
buffer = ifile.read(77)
tfile.write(buffer)
wbuffer = ifile.read(77)
tfile.write(wbuffer)
# Write the UINF superbox
# Length = 50, id is uinf.
buffer = struct.pack('>I4s', int(50), b'uinf')
tfile.write(buffer)
wbuffer = struct.pack('>I4s', int(50), b'uinf')
tfile.write(wbuffer)
# Write the ULST box.
# Length is 26, 1 UUID, hard code that UUID as zeros.
buffer = struct.pack('>I4sHIIII', int(26), b'ulst', int(1),
int(0), int(0), int(0), int(0))
tfile.write(buffer)
wbuffer = struct.pack('>I4sHIIII', int(26), b'ulst', int(1),
int(0), int(0), int(0), int(0))
tfile.write(wbuffer)
# Write the URL box.
# Length is 16, version is one byte, flag is 3 bytes, url
# is the rest.
buffer = struct.pack('>I4sBBBB',
int(16), b'url ',
int(0), int(0), int(0), int(0))
tfile.write(buffer)
buffer = struct.pack('>ssss', b'a', b'b', b'c', b'd')
tfile.write(buffer)
wbuffer = struct.pack('>I4sBBBB',
int(16), b'url ',
int(0), int(0), int(0), int(0))
tfile.write(wbuffer)
wbuffer = struct.pack('>ssss', b'a', b'b', b'c', b'd')
tfile.write(wbuffer)
# Start the resolution superbox.
buffer = struct.pack('>I4s', int(44), b'res ')
tfile.write(buffer)
wbuffer = struct.pack('>I4s', int(44), b'res ')
tfile.write(wbuffer)
# Write the capture resolution box.
buffer = struct.pack('>I4sHHHHBB',
int(18), b'resc',
int(1), int(1), int(1), int(1),
int(0), int(1))
tfile.write(buffer)
wbuffer = struct.pack('>I4sHHHHBB',
int(18), b'resc',
int(1), int(1), int(1), int(1),
int(0), int(1))
tfile.write(wbuffer)
# Write the display resolution box.
buffer = struct.pack('>I4sHHHHBB',
int(18), b'resd',
int(1), int(1), int(1), int(1),
int(1), int(0))
tfile.write(buffer)
wbuffer = struct.pack('>I4sHHHHBB',
int(18), b'resd',
int(1), int(1), int(1), int(1),
int(1), int(0))
tfile.write(wbuffer)
# Get the rest of the input file.
buffer = ifile.read()
tfile.write(buffer)
wbuffer = ifile.read()
tfile.write(wbuffer)
tfile.flush()
jp2k = glymur.Jp2k(tfile.name)
@ -901,12 +921,13 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03000000,
"Ordered dicts not printing well in 2.7")
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_jpx_approximation_with_icc_profile(self):
def test_jpx_approx_icc_profile(self):
"""verify jpx with approx field equal to zero"""
# ICC profiles may be used in JP2, but the approximation field should
# be zero unless we have jpx. This file does both.
filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2')
filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
@ -945,11 +966,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(data_root is None,
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_uuid(self):
# UUID box
filename = os.path.join(data_root, 'input/nonregression/text_GBR.jp2')
"""verify printing of UUID box"""
filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
@ -968,6 +989,7 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03000000,
"Ordered dicts not printing well in 2.7")
def test_exif_uuid(self):
"""Verify printing of exif information"""
j = glymur.Jp2k(self.jp2file)
with patch('sys.stdout', new=StringIO()) as fake_out: