pylint work, #99
This commit is contained in:
parent
1a84ca2386
commit
11b29028fc
1 changed files with 40 additions and 42 deletions
|
|
@ -1,9 +1,15 @@
|
|||
"""
|
||||
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
|
||||
from os.path import join
|
||||
import sys
|
||||
|
||||
if sys.hexversion < 0x02070000:
|
||||
|
|
@ -11,106 +17,98 @@ if sys.hexversion < 0x02070000:
|
|||
else:
|
||||
import unittest
|
||||
|
||||
import warnings
|
||||
|
||||
from glymur import Jp2k
|
||||
import glymur
|
||||
|
||||
try:
|
||||
format_corpus_data_root = os.environ['FORMAT_CORPUS_DATA_ROOT']
|
||||
FORMAT_CORPUS_DATA_ROOT = os.environ['FORMAT_CORPUS_DATA_ROOT']
|
||||
except KeyError:
|
||||
format_corpus_data_root = None
|
||||
FORMAT_CORPUS_DATA_ROOT = None
|
||||
|
||||
try:
|
||||
opj_data_root = os.environ['OPJ_DATA_ROOT']
|
||||
OPJ_DATA_ROOT = os.environ['OPJ_DATA_ROOT']
|
||||
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")
|
||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||
"Requires features introduced in 3.2 (assertWarns)")
|
||||
class TestSuiteFormatCorpus(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
"""Test suite for files in format corpus repository."""
|
||||
|
||||
def test_balloon_trunc1(self):
|
||||
# Has one byte shaved off of EOC marker.
|
||||
jfile = os.path.join(format_corpus_data_root,
|
||||
"""Has one byte shaved off of EOC marker."""
|
||||
jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
|
||||
'jp2k-test/byteCorruption/balloon_trunc1.jp2')
|
||||
j2k = Jp2k(jfile)
|
||||
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.
|
||||
self.assertNotEqual(c.segment[-1].marker_id, 'EOC')
|
||||
self.assertNotEqual(codestream.segment[-1].marker_id, 'EOC')
|
||||
|
||||
# The codestream is not as long as claimed.
|
||||
with self.assertRaises(OSError):
|
||||
j2k.read(rlevel=-1)
|
||||
|
||||
def test_balloon_trunc2(self):
|
||||
# Shortened by 5000 bytes.
|
||||
jfile = os.path.join(format_corpus_data_root,
|
||||
"""Shortened by 5000 bytes."""
|
||||
jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
|
||||
'jp2k-test/byteCorruption/balloon_trunc2.jp2')
|
||||
j2k = Jp2k(jfile)
|
||||
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.
|
||||
self.assertNotEqual(c.segment[-1].marker_id, 'EOC')
|
||||
self.assertNotEqual(codestream.segment[-1].marker_id, 'EOC')
|
||||
|
||||
# The codestream is not as long as claimed.
|
||||
with self.assertRaises(OSError):
|
||||
j2k.read(rlevel=-1)
|
||||
|
||||
def test_balloon_trunc3(self):
|
||||
# Most of last tile is missing.
|
||||
jfile = os.path.join(format_corpus_data_root,
|
||||
"""Most of last tile is missing."""
|
||||
jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
|
||||
'jp2k-test/byteCorruption/balloon_trunc3.jp2')
|
||||
j2k = Jp2k(jfile)
|
||||
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.
|
||||
self.assertNotEqual(c.segment[-1].marker_id, 'EOC')
|
||||
self.assertNotEqual(codestream.segment[-1].marker_id, 'EOC')
|
||||
|
||||
# Should error out, it does not.
|
||||
#with self.assertRaises(OSError):
|
||||
# j2k.read(rlevel=-1)
|
||||
|
||||
def test_jp2_brand_vs_any_icc_profile(self):
|
||||
# If 'jp2 ', then the method cannot be any icc profile.
|
||||
jfile = os.path.join(format_corpus_data_root,
|
||||
def test_jp2_brand_any_icc_profile(self):
|
||||
"""If 'jp2 ', then the method cannot be any icc profile."""
|
||||
jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
|
||||
'jp2k-test', 'icc',
|
||||
'balloon_eciRGBv2_ps_adobeplugin.jpf')
|
||||
with self.assertWarns(UserWarning):
|
||||
j2k = Jp2k(jfile)
|
||||
Jp2k(jfile)
|
||||
|
||||
def test_jp2_brand_vs_any_icc_profile_multiple_colr(self):
|
||||
# Has colr box, one that conforms, one that does not.
|
||||
def test_jp2_brand_iccpr_mult_colr(self):
|
||||
"""Has colr box, one that conforms, one that does not."""
|
||||
|
||||
# Wrong 'brand' field; contains two versions of ICC profile: one
|
||||
# embedded using "Any ICC" method; other embedded using "Restricted
|
||||
# ICC" method, with description ("Modified eciRGB v2") and profileClass
|
||||
# ("Input Device") changed relative to original profile.
|
||||
lst = [format_corpus_data_root, 'jp2k-test', 'icc',
|
||||
'balloon_eciRGBv2_ps_adobeplugin_jp2compatible.jpf']
|
||||
jfile = os.path.join(*lst)
|
||||
jfile = join(FORMAT_CORPUS_DATA_ROOT, 'jp2k-test', 'icc',
|
||||
'balloon_eciRGBv2_ps_adobeplugin_jp2compatible.jpf')
|
||||
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")
|
||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||
"Requires features introduced in 3.2 (assertWarns)")
|
||||
class TestSuiteOpj(unittest.TestCase):
|
||||
"""Test suite for files in openjpeg repository."""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
|
@ -118,12 +116,12 @@ class TestSuiteOpj(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_jp2_brand_vs_any_icc_profile(self):
|
||||
# If 'jp2 ', then the method cannot be any icc profile.
|
||||
filename = os.path.join(opj_data_root,
|
||||
def test_jp2_brand_any_icc_profile(self):
|
||||
"""If 'jp2 ', then the method cannot be any icc profile."""
|
||||
filename = os.path.join(OPJ_DATA_ROOT,
|
||||
'input/nonregression/text_GBR.jp2')
|
||||
with self.assertWarns(UserWarning):
|
||||
j2k = Jp2k(filename)
|
||||
Jp2k(filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue