pylint work, #99

This commit is contained in:
jevans 2013-08-11 20:23:50 -04:00
commit 11b29028fc

View file

@ -1,9 +1,15 @@
""" """
These tests deal with JPX/JP2/J2K images in the format-corpus repository. These tests deal with JPX/JP2/J2K images in the format-corpus repository.
""" """
#pylint: disable-all # R0904: Not too many methods in unittest.
# pylint: disable=R0904
# E1101: assertWarns introduced in python 3.2
# pylint: disable=E1101
import os import os
from os.path import join
import sys import sys
if sys.hexversion < 0x02070000: if sys.hexversion < 0x02070000:
@ -11,106 +17,98 @@ if sys.hexversion < 0x02070000:
else: else:
import unittest import unittest
import warnings
from glymur import Jp2k from glymur import Jp2k
import glymur
try: try:
format_corpus_data_root = os.environ['FORMAT_CORPUS_DATA_ROOT'] FORMAT_CORPUS_DATA_ROOT = os.environ['FORMAT_CORPUS_DATA_ROOT']
except KeyError: except KeyError:
format_corpus_data_root = None FORMAT_CORPUS_DATA_ROOT = None
try: try:
opj_data_root = os.environ['OPJ_DATA_ROOT'] OPJ_DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError: except KeyError:
opj_data_root = None OPJ_DATA_ROOT = None
@unittest.skipIf(format_corpus_data_root is None, @unittest.skipIf(FORMAT_CORPUS_DATA_ROOT is None,
"FORMAT_CORPUS_DATA_ROOT environment variable not set") "FORMAT_CORPUS_DATA_ROOT environment variable not set")
@unittest.skipIf(sys.hexversion < 0x03020000, @unittest.skipIf(sys.hexversion < 0x03020000,
"Requires features introduced in 3.2 (assertWarns)") "Requires features introduced in 3.2 (assertWarns)")
class TestSuiteFormatCorpus(unittest.TestCase): class TestSuiteFormatCorpus(unittest.TestCase):
"""Test suite for files in format corpus repository."""
def setUp(self):
pass
def tearDown(self):
pass
def test_balloon_trunc1(self): def test_balloon_trunc1(self):
# Has one byte shaved off of EOC marker. """Has one byte shaved off of EOC marker."""
jfile = os.path.join(format_corpus_data_root, jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
'jp2k-test/byteCorruption/balloon_trunc1.jp2') 'jp2k-test/byteCorruption/balloon_trunc1.jp2')
j2k = Jp2k(jfile) j2k = Jp2k(jfile)
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
c = j2k.get_codestream(header_only=False) codestream = j2k.get_codestream(header_only=False)
# The last segment is truncated, so there should not be an EOC marker. # The last segment is truncated, so there should not be an EOC marker.
self.assertNotEqual(c.segment[-1].marker_id, 'EOC') self.assertNotEqual(codestream.segment[-1].marker_id, 'EOC')
# The codestream is not as long as claimed. # The codestream is not as long as claimed.
with self.assertRaises(OSError): with self.assertRaises(OSError):
j2k.read(rlevel=-1) j2k.read(rlevel=-1)
def test_balloon_trunc2(self): def test_balloon_trunc2(self):
# Shortened by 5000 bytes. """Shortened by 5000 bytes."""
jfile = os.path.join(format_corpus_data_root, jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
'jp2k-test/byteCorruption/balloon_trunc2.jp2') 'jp2k-test/byteCorruption/balloon_trunc2.jp2')
j2k = Jp2k(jfile) j2k = Jp2k(jfile)
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
c = j2k.get_codestream(header_only=False) codestream = j2k.get_codestream(header_only=False)
# The last segment is truncated, so there should not be an EOC marker. # The last segment is truncated, so there should not be an EOC marker.
self.assertNotEqual(c.segment[-1].marker_id, 'EOC') self.assertNotEqual(codestream.segment[-1].marker_id, 'EOC')
# The codestream is not as long as claimed. # The codestream is not as long as claimed.
with self.assertRaises(OSError): with self.assertRaises(OSError):
j2k.read(rlevel=-1) j2k.read(rlevel=-1)
def test_balloon_trunc3(self): def test_balloon_trunc3(self):
# Most of last tile is missing. """Most of last tile is missing."""
jfile = os.path.join(format_corpus_data_root, jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
'jp2k-test/byteCorruption/balloon_trunc3.jp2') 'jp2k-test/byteCorruption/balloon_trunc3.jp2')
j2k = Jp2k(jfile) j2k = Jp2k(jfile)
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
c = j2k.get_codestream(header_only=False) codestream = j2k.get_codestream(header_only=False)
# The last segment is truncated, so there should not be an EOC marker. # The last segment is truncated, so there should not be an EOC marker.
self.assertNotEqual(c.segment[-1].marker_id, 'EOC') self.assertNotEqual(codestream.segment[-1].marker_id, 'EOC')
# Should error out, it does not. # Should error out, it does not.
#with self.assertRaises(OSError): #with self.assertRaises(OSError):
# j2k.read(rlevel=-1) # j2k.read(rlevel=-1)
def test_jp2_brand_vs_any_icc_profile(self): def test_jp2_brand_any_icc_profile(self):
# If 'jp2 ', then the method cannot be any icc profile. """If 'jp2 ', then the method cannot be any icc profile."""
jfile = os.path.join(format_corpus_data_root, jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
'jp2k-test', 'icc', 'jp2k-test', 'icc',
'balloon_eciRGBv2_ps_adobeplugin.jpf') 'balloon_eciRGBv2_ps_adobeplugin.jpf')
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
j2k = Jp2k(jfile) Jp2k(jfile)
def test_jp2_brand_vs_any_icc_profile_multiple_colr(self): def test_jp2_brand_iccpr_mult_colr(self):
# Has colr box, one that conforms, one that does not. """Has colr box, one that conforms, one that does not."""
# Wrong 'brand' field; contains two versions of ICC profile: one # Wrong 'brand' field; contains two versions of ICC profile: one
# embedded using "Any ICC" method; other embedded using "Restricted # embedded using "Any ICC" method; other embedded using "Restricted
# ICC" method, with description ("Modified eciRGB v2") and profileClass # ICC" method, with description ("Modified eciRGB v2") and profileClass
# ("Input Device") changed relative to original profile. # ("Input Device") changed relative to original profile.
lst = [format_corpus_data_root, 'jp2k-test', 'icc', jfile = join(FORMAT_CORPUS_DATA_ROOT, 'jp2k-test', 'icc',
'balloon_eciRGBv2_ps_adobeplugin_jp2compatible.jpf'] 'balloon_eciRGBv2_ps_adobeplugin_jp2compatible.jpf')
jfile = os.path.join(*lst)
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
j2k = Jp2k(jfile) Jp2k(jfile)
@unittest.skipIf(opj_data_root is None, @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set") "OPJ_DATA_ROOT environment variable not set")
@unittest.skipIf(sys.hexversion < 0x03020000, @unittest.skipIf(sys.hexversion < 0x03020000,
"Requires features introduced in 3.2 (assertWarns)") "Requires features introduced in 3.2 (assertWarns)")
class TestSuiteOpj(unittest.TestCase): class TestSuiteOpj(unittest.TestCase):
"""Test suite for files in openjpeg repository."""
def setUp(self): def setUp(self):
pass pass
@ -118,12 +116,12 @@ class TestSuiteOpj(unittest.TestCase):
def tearDown(self): def tearDown(self):
pass pass
def test_jp2_brand_vs_any_icc_profile(self): def test_jp2_brand_any_icc_profile(self):
# If 'jp2 ', then the method cannot be any icc profile. """If 'jp2 ', then the method cannot be any icc profile."""
filename = os.path.join(opj_data_root, filename = os.path.join(OPJ_DATA_ROOT,
'input/nonregression/text_GBR.jp2') 'input/nonregression/text_GBR.jp2')
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
j2k = Jp2k(filename) Jp2k(filename)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()