pylint work, #99
This commit is contained in:
parent
ee2f950500
commit
1fe62a9d9e
2 changed files with 50 additions and 39 deletions
|
|
@ -775,12 +775,15 @@ class Segment(object):
|
||||||
length : int
|
length : int
|
||||||
Length of marker segment in bytes. This number does not include the
|
Length of marker segment in bytes. This number does not include the
|
||||||
two bytes constituting the marker.
|
two bytes constituting the marker.
|
||||||
|
data : bytes iterable or None
|
||||||
|
Uninterpreted buffer of raw bytes, only used where a segment is not
|
||||||
|
well understood.
|
||||||
"""
|
"""
|
||||||
def __init__(self, marker_id='', offset=-1, length=-1, data=None):
|
def __init__(self, marker_id='', offset=-1, length=-1, data=None):
|
||||||
self.marker_id = marker_id
|
self.marker_id = marker_id
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
self.length = length
|
self.length = length
|
||||||
self._data = data
|
self.data = data
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
msg = '{0} marker segment @ ({1}, {2})'.format(self.marker_id,
|
msg = '{0} marker segment @ ({1}, {2})'.format(self.marker_id,
|
||||||
|
|
@ -1203,8 +1206,8 @@ class PPMsegment(Segment):
|
||||||
Segment.__init__(self, marker_id='PPM')
|
Segment.__init__(self, marker_id='PPM')
|
||||||
self.zppm = zppm
|
self.zppm = zppm
|
||||||
|
|
||||||
# both Nppm and Ippms information stored in _data
|
# both Nppm and Ippms information stored in data
|
||||||
self._data = data
|
self.data = data
|
||||||
|
|
||||||
self.length = length
|
self.length = length
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
|
|
@ -1213,7 +1216,7 @@ class PPMsegment(Segment):
|
||||||
msg = Segment.__str__(self)
|
msg = Segment.__str__(self)
|
||||||
msg += '\n Index: {0}'
|
msg += '\n Index: {0}'
|
||||||
msg += '\n Data: {1} uninterpreted bytes'
|
msg += '\n Data: {1} uninterpreted bytes'
|
||||||
msg = msg.format(self.zppm, len(self._data))
|
msg = msg.format(self.zppm, len(self.data))
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,13 @@
|
||||||
#pylint: disable-all
|
"""
|
||||||
|
Test suite for codestream parsing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# unittest doesn't work well with R0904.
|
||||||
|
# pylint: disable=R0904
|
||||||
|
|
||||||
|
# tempfile.TemporaryDirectory, unittest.assertWarns introduced in 3.2
|
||||||
|
# pylint: disable=E1101
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -9,23 +18,21 @@ if sys.hexversion < 0x02070000:
|
||||||
else:
|
else:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import pkg_resources
|
|
||||||
|
|
||||||
from glymur import Jp2k
|
from glymur import Jp2k
|
||||||
import glymur
|
import glymur
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data_root = os.environ['OPJ_DATA_ROOT']
|
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
data_root = None
|
DATA_ROOT = None
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(data_root is None,
|
@unittest.skipIf(DATA_ROOT is None,
|
||||||
"OPJ_DATA_ROOT environment variable not set")
|
"OPJ_DATA_ROOT environment variable not set")
|
||||||
class TestCodestream(unittest.TestCase):
|
class TestCodestream(unittest.TestCase):
|
||||||
|
"""Test suite for unusual codestream cases."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.jp2file = glymur.data.nemo()
|
self.jp2file = glymur.data.nemo()
|
||||||
|
|
@ -35,75 +42,76 @@ class TestCodestream(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||||
def test_reserved_marker_segment(self):
|
def test_reserved_marker_segment(self):
|
||||||
|
"""Reserved marker segments are ok."""
|
||||||
|
|
||||||
# Some marker segments were reserved in FCD15444-1. Since that
|
# Some marker segments were reserved in FCD15444-1. Since that
|
||||||
# standard is old, some of them may have come into use.
|
# standard is old, some of them may have come into use.
|
||||||
#
|
#
|
||||||
# Let's inject a reserved marker segment into a file that
|
# Let's inject a reserved marker segment into a file that
|
||||||
# we know something about to make sure we can still parse it.
|
# we know something about to make sure we can still parse it.
|
||||||
filename = os.path.join(data_root, 'input/conformance/p0_01.j2k')
|
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_01.j2k')
|
||||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||||
with open(filename, 'rb') as ifile:
|
with open(filename, 'rb') as ifile:
|
||||||
# Everything up until the first QCD marker.
|
# Everything up until the first QCD marker.
|
||||||
buffer = ifile.read(45)
|
read_buffer = ifile.read(45)
|
||||||
tfile.write(buffer)
|
tfile.write(read_buffer)
|
||||||
|
|
||||||
# Write the new marker segment, 0xff6f = 65391
|
# Write the new marker segment, 0xff6f = 65391
|
||||||
buffer = struct.pack('>HHB', int(65391), int(3), int(0))
|
read_buffer = struct.pack('>HHB', int(65391), int(3), int(0))
|
||||||
tfile.write(buffer)
|
tfile.write(read_buffer)
|
||||||
|
|
||||||
# Get the rest of the input file.
|
# Get the rest of the input file.
|
||||||
buffer = ifile.read()
|
read_buffer = ifile.read()
|
||||||
tfile.write(buffer)
|
tfile.write(read_buffer)
|
||||||
tfile.flush()
|
tfile.flush()
|
||||||
|
|
||||||
j = Jp2k(tfile.name)
|
codestream = Jp2k(tfile.name).get_codestream()
|
||||||
c = j.get_codestream()
|
|
||||||
|
|
||||||
self.assertEqual(c.segment[2].marker_id, '0xff6f')
|
self.assertEqual(codestream.segment[2].marker_id, '0xff6f')
|
||||||
self.assertEqual(c.segment[2].length, 3)
|
self.assertEqual(codestream.segment[2].length, 3)
|
||||||
self.assertEqual(c.segment[2]._data, b'\x00')
|
self.assertEqual(codestream.segment[2].data, b'\x00')
|
||||||
|
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
"Uses features introduced in 3.2.")
|
"Uses features introduced in 3.2.")
|
||||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||||
def test_unknown_marker_segment(self):
|
def test_unknown_marker_segment(self):
|
||||||
|
"""Should warn for an unknown marker."""
|
||||||
# Let's inject a marker segment whose marker does not appear to
|
# Let's inject a marker segment whose marker does not appear to
|
||||||
# be valid. We still parse the file, but warn about the offending
|
# be valid. We still parse the file, but warn about the offending
|
||||||
# marker.
|
# marker.
|
||||||
filename = os.path.join(data_root, 'input/conformance/p0_01.j2k')
|
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_01.j2k')
|
||||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||||
with open(filename, 'rb') as ifile:
|
with open(filename, 'rb') as ifile:
|
||||||
# Everything up until the first QCD marker.
|
# Everything up until the first QCD marker.
|
||||||
buffer = ifile.read(45)
|
read_buffer = ifile.read(45)
|
||||||
tfile.write(buffer)
|
tfile.write(read_buffer)
|
||||||
|
|
||||||
# Write the new marker segment, 0xff79 = 65401
|
# Write the new marker segment, 0xff79 = 65401
|
||||||
buffer = struct.pack('>HHB', int(65401), int(3), int(0))
|
read_buffer = struct.pack('>HHB', int(65401), int(3), int(0))
|
||||||
tfile.write(buffer)
|
tfile.write(read_buffer)
|
||||||
|
|
||||||
# Get the rest of the input file.
|
# Get the rest of the input file.
|
||||||
buffer = ifile.read()
|
read_buffer = ifile.read()
|
||||||
tfile.write(buffer)
|
tfile.write(read_buffer)
|
||||||
tfile.flush()
|
tfile.flush()
|
||||||
|
|
||||||
with self.assertWarns(UserWarning):
|
with self.assertWarns(UserWarning):
|
||||||
j = Jp2k(tfile.name)
|
codestream = Jp2k(tfile.name).get_codestream()
|
||||||
c = j.get_codestream()
|
|
||||||
|
|
||||||
self.assertEqual(c.segment[2].marker_id, '0xff79')
|
self.assertEqual(codestream.segment[2].marker_id, '0xff79')
|
||||||
self.assertEqual(c.segment[2].length, 3)
|
self.assertEqual(codestream.segment[2].length, 3)
|
||||||
self.assertEqual(c.segment[2]._data, b'\x00')
|
self.assertEqual(codestream.segment[2].data, b'\x00')
|
||||||
|
|
||||||
def test_psot_is_zero(self):
|
def test_psot_is_zero(self):
|
||||||
# Psot=0 in SOT is perfectly legal. Issue #78.
|
"""Psot=0 in SOT is perfectly legal. Issue #78."""
|
||||||
filename = os.path.join(data_root,
|
filename = os.path.join(DATA_ROOT,
|
||||||
'input/nonregression/123.j2c')
|
'input/nonregression/123.j2c')
|
||||||
j = Jp2k(filename)
|
j = Jp2k(filename)
|
||||||
c = j.get_codestream(header_only=False)
|
codestream = j.get_codestream(header_only=False)
|
||||||
|
|
||||||
# The codestream is valid, so we should be able to get the entire
|
# The codestream is valid, so we should be able to get the entire
|
||||||
# codestream, so the last one is EOC.
|
# codestream, so the last one is EOC.
|
||||||
self.assertEqual(c.segment[-1].marker_id, 'EOC')
|
self.assertEqual(codestream.segment[-1].marker_id, 'EOC')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue