pylint work, #99
This commit is contained in:
parent
63168e6b3a
commit
ee2f950500
4 changed files with 66 additions and 40 deletions
|
|
@ -3,10 +3,6 @@
|
||||||
License: MIT
|
License: MIT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# W0201: Since we are using ctypes Structures, we often have to access
|
|
||||||
# attributes that are not defined in __init__ but in _fields_ instead.
|
|
||||||
# pylint: disable=W0201
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
if sys.hexversion >= 0x03030000:
|
if sys.hexversion >= 0x03030000:
|
||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
#pylint: disable-all
|
"""
|
||||||
|
Test suite for openjpeg's callback functions.
|
||||||
|
"""
|
||||||
|
# R0904: Seems like pylint is fooled in this situation
|
||||||
|
# pylint: disable=R0904
|
||||||
|
|
||||||
|
# 'mock' most certainly is in unittest (Python 3.3)
|
||||||
|
# pylint: disable=E0611,F0401
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
@ -24,6 +31,7 @@ import glymur
|
||||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestCallbacks(unittest.TestCase):
|
class TestCallbacks(unittest.TestCase):
|
||||||
|
"""Test suite for callbacks."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.jp2file = glymur.data.nemo()
|
self.jp2file = glymur.data.nemo()
|
||||||
|
|
@ -34,7 +42,7 @@ class TestCallbacks(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||||
def test_info_callback_on_write(self):
|
def test_info_callback_on_write(self):
|
||||||
# Verify the messages printed when writing an image in verbose mode.
|
"""Verify messages printed when writing an image in verbose mode."""
|
||||||
j = glymur.Jp2k(self.jp2file)
|
j = glymur.Jp2k(self.jp2file)
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
|
|
@ -47,12 +55,14 @@ class TestCallbacks(unittest.TestCase):
|
||||||
expected = '[INFO] tile number 1 / 1'
|
expected = '[INFO] tile number 1 / 1'
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
def test_info_warning_callbacks_on_read(self):
|
def test_info_callbacks_on_read(self):
|
||||||
|
"""stdio output when info callback handler is enabled"""
|
||||||
|
|
||||||
# Verify that we get the expected stdio output when our internal info
|
# Verify that we get the expected stdio output when our internal info
|
||||||
# callback handler is enabled.
|
# callback handler is enabled.
|
||||||
j = glymur.Jp2k(self.j2kfile)
|
j = glymur.Jp2k(self.j2kfile)
|
||||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
d = j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150))
|
j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150))
|
||||||
actual = fake_out.getvalue().strip()
|
actual = fake_out.getvalue().strip()
|
||||||
|
|
||||||
lines = ['[INFO] Start to read j2k main header (0).',
|
lines = ['[INFO] Start to read j2k main header (0).',
|
||||||
|
|
@ -80,13 +90,16 @@ class TestCallbacks15(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_info_callbacks_on_read(self):
|
def test_info_callbacks_on_read(self):
|
||||||
# Verify that we get the expected stdio output when our internal info
|
"""Verify stdout when reading.
|
||||||
# callback handler is enabled.
|
|
||||||
|
Verify that we get the expected stdio output when our internal info
|
||||||
|
callback handler is enabled.
|
||||||
|
"""
|
||||||
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
||||||
# Force to use OPENJPEG instead of OPENJP2.
|
# Force to use OPENJPEG instead of OPENJP2.
|
||||||
j = glymur.Jp2k(self.j2kfile)
|
j = glymur.Jp2k(self.j2kfile)
|
||||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
d = j.read(rlevel=1, verbose=True)
|
j.read(rlevel=1, verbose=True)
|
||||||
actual = fake_out.getvalue().strip()
|
actual = fake_out.getvalue().strip()
|
||||||
|
|
||||||
regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+
|
regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+
|
||||||
|
|
@ -97,6 +110,9 @@ class TestCallbacks15(unittest.TestCase):
|
||||||
\[INFO\]\s-\stile\sdecoded\sin\s
|
\[INFO\]\s-\stile\sdecoded\sin\s
|
||||||
[0-9]+\.[0-9]+\ss""",
|
[0-9]+\.[0-9]+\ss""",
|
||||||
re.VERBOSE)
|
re.VERBOSE)
|
||||||
|
|
||||||
|
# assertRegex in Python 3.3 (python2.7/pylint issue)
|
||||||
|
# pylint: disable=E1101
|
||||||
if sys.hexversion <= 0x03020000:
|
if sys.hexversion <= 0x03020000:
|
||||||
self.assertRegexpMatches(actual, regex)
|
self.assertRegexpMatches(actual, regex)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
"""These tests are for edge cases where OPENJPEG does not exist, but
|
"""These tests are for edge cases where OPENJPEG does not exist, but
|
||||||
OPENJP2 may be present in some form or other.
|
OPENJP2 may be present in some form or other.
|
||||||
"""
|
"""
|
||||||
#pylint: disable-all
|
# unittest doesn't work well with R0904.
|
||||||
|
# pylint: disable=R0904
|
||||||
|
|
||||||
|
# tempfile.TemporaryDirectory, unittest.assertWarns introduced in 3.2
|
||||||
|
# pylint: disable=E1101
|
||||||
|
|
||||||
|
# unittest.mock only in Python 3.3 (python2.7/pylint import issue)
|
||||||
|
# pylint: disable=E0611,F0401
|
||||||
|
|
||||||
|
|
||||||
import imp
|
import imp
|
||||||
import os
|
import os
|
||||||
|
|
@ -17,13 +25,9 @@ if sys.hexversion <= 0x03030000:
|
||||||
from mock import patch
|
from mock import patch
|
||||||
else:
|
else:
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
import warnings
|
|
||||||
|
|
||||||
import pkg_resources
|
|
||||||
|
|
||||||
import glymur
|
import glymur
|
||||||
from glymur import Jp2k
|
from glymur import Jp2k
|
||||||
from glymur.lib import openjp2 as opj2
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
|
|
@ -31,6 +35,7 @@ from glymur.lib import openjp2 as opj2
|
||||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Needs openjp2 library first before these tests make sense.")
|
"Needs openjp2 library first before these tests make sense.")
|
||||||
class TestSuite(unittest.TestCase):
|
class TestSuite(unittest.TestCase):
|
||||||
|
"""Test suite for configuration file operation."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|
@ -56,29 +61,33 @@ class TestSuite(unittest.TestCase):
|
||||||
filename = os.path.join(configdir, 'glymurrc')
|
filename = os.path.join(configdir, 'glymurrc')
|
||||||
with open(filename, 'wt') as tfile:
|
with open(filename, 'wt') as tfile:
|
||||||
tfile.write('[library]\n')
|
tfile.write('[library]\n')
|
||||||
|
|
||||||
|
# Need to reliably recover the location of the openjp2 library,
|
||||||
|
# so using '_name' appears to be the only way to do it.
|
||||||
|
# pylint: disable=W0212
|
||||||
libloc = glymur.lib.openjp2.OPENJP2._name
|
libloc = glymur.lib.openjp2.OPENJP2._name
|
||||||
line = 'openjp2: {0}\n'.format(libloc)
|
line = 'openjp2: {0}\n'.format(libloc)
|
||||||
tfile.write(line)
|
tfile.write(line)
|
||||||
tfile.flush()
|
tfile.flush()
|
||||||
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
||||||
imp.reload(glymur.lib.openjp2)
|
imp.reload(glymur.lib.openjp2)
|
||||||
j = Jp2k(self.jp2file)
|
Jp2k(self.jp2file)
|
||||||
|
|
||||||
def test_config_file_via_environ_is_wrong(self):
|
def test_xdg_env_config_file_is_bad(self):
|
||||||
# A non-existant library location should be rejected.
|
"""A non-existant library location should be rejected."""
|
||||||
with tempfile.TemporaryDirectory() as tdir:
|
with tempfile.TemporaryDirectory() as tdir:
|
||||||
configdir = os.path.join(tdir, 'glymur')
|
configdir = os.path.join(tdir, 'glymur')
|
||||||
os.mkdir(configdir)
|
os.mkdir(configdir)
|
||||||
fname = os.path.join(configdir, 'glymurrc')
|
fname = os.path.join(configdir, 'glymurrc')
|
||||||
with open(fname, 'w') as fp:
|
with open(fname, 'w') as fptr:
|
||||||
with tempfile.NamedTemporaryFile(suffix='.dylib') as tfile:
|
with tempfile.NamedTemporaryFile(suffix='.dylib') as tfile:
|
||||||
fp.write('[library]\n')
|
fptr.write('[library]\n')
|
||||||
fp.write('openjp2: {0}.not.there\n'.format(tfile.name))
|
fptr.write('openjp2: {0}.not.there\n'.format(tfile.name))
|
||||||
fp.flush()
|
fptr.flush()
|
||||||
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
||||||
# Misconfigured new configuration file should
|
# Misconfigured new configuration file should
|
||||||
# be rejected.
|
# be rejected.
|
||||||
with self.assertWarns(UserWarning) as cw:
|
with self.assertWarns(UserWarning):
|
||||||
imp.reload(glymur.lib.openjp2)
|
imp.reload(glymur.lib.openjp2)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,35 @@
|
||||||
#pylint: disable-all
|
"""
|
||||||
|
ICC profile tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# unittest doesn't work well with R0904.
|
||||||
|
# pylint: disable=R0904
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import struct
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
|
|
||||||
if sys.hexversion < 0x02070000:
|
if sys.hexversion < 0x02070000:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
else:
|
else:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import warnings
|
|
||||||
from xml.etree import cElementTree as ET
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pkg_resources
|
|
||||||
|
|
||||||
from glymur import Jp2k
|
from glymur import Jp2k
|
||||||
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 TestICC(unittest.TestCase):
|
class TestICC(unittest.TestCase):
|
||||||
|
"""ICC profile tests"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -38,7 +38,8 @@ class TestICC(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_file5(self):
|
def test_file5(self):
|
||||||
filename = os.path.join(data_root, 'input/conformance/file5.jp2')
|
"""basic ICC profile"""
|
||||||
|
filename = os.path.join(DATA_ROOT, 'input/conformance/file5.jp2')
|
||||||
j = Jp2k(filename)
|
j = Jp2k(filename)
|
||||||
profile = j.box[3].box[1].icc_profile
|
profile = j.box[3].box[1].icc_profile
|
||||||
self.assertEqual(profile['Size'], 546)
|
self.assertEqual(profile['Size'], 546)
|
||||||
|
|
@ -70,10 +71,14 @@ class TestICC(unittest.TestCase):
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
"Uses features introduced in 3.2.")
|
"Uses features introduced in 3.2.")
|
||||||
def test_invalid_profile_header(self):
|
def test_invalid_profile_header(self):
|
||||||
jfile = os.path.join(data_root,
|
"""invalid ICC header data should cause UserWarning"""
|
||||||
|
jfile = os.path.join(DATA_ROOT,
|
||||||
'input/nonregression/orb-blue10-lin-jp2.jp2')
|
'input/nonregression/orb-blue10-lin-jp2.jp2')
|
||||||
with self.assertWarns(UserWarning) as cw:
|
|
||||||
j = Jp2k(jfile)
|
# assertWarns in Python 3.3 (python2.7/pylint issue)
|
||||||
|
# pylint: disable=E1101
|
||||||
|
with self.assertWarns(UserWarning):
|
||||||
|
Jp2k(jfile)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue