Merge branch 'issue93' into devel
This commit is contained in:
commit
1322b03dae
1 changed files with 34 additions and 46 deletions
|
|
@ -6,16 +6,18 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
if sys.hexversion < 0x03000000:
|
|
||||||
from StringIO import StringIO
|
|
||||||
else:
|
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
if sys.hexversion < 0x02070000:
|
if sys.hexversion < 0x02070000:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
else:
|
else:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
if sys.hexversion <= 0x03030000:
|
||||||
|
from mock import patch
|
||||||
|
from StringIO import StringIO
|
||||||
|
else:
|
||||||
|
from unittest.mock import patch
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
import glymur
|
import glymur
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,15 +26,11 @@ import glymur
|
||||||
class TestCallbacks(unittest.TestCase):
|
class TestCallbacks(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Save sys.stdout.
|
|
||||||
self.stdout = sys.stdout
|
|
||||||
sys.stdout = StringIO()
|
|
||||||
self.jp2file = glymur.data.nemo()
|
self.jp2file = glymur.data.nemo()
|
||||||
self.j2kfile = glymur.data.goodstuff()
|
self.j2kfile = glymur.data.goodstuff()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# Restore stdout.
|
pass
|
||||||
sys.stdout = self.stdout
|
|
||||||
|
|
||||||
@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):
|
||||||
|
|
@ -43,8 +41,9 @@ class TestCallbacks(unittest.TestCase):
|
||||||
tiledata = j.read(tile=0)
|
tiledata = j.read(tile=0)
|
||||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||||
j = glymur.Jp2k(tfile.name, 'wb')
|
j = glymur.Jp2k(tfile.name, 'wb')
|
||||||
j.write(tiledata, verbose=True)
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
actual = sys.stdout.getvalue().strip()
|
j.write(tiledata, verbose=True)
|
||||||
|
actual = fake_out.getvalue().strip()
|
||||||
expected = '[INFO] tile number 1 / 1'
|
expected = '[INFO] tile number 1 / 1'
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
|
@ -52,8 +51,9 @@ class TestCallbacks(unittest.TestCase):
|
||||||
# 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)
|
||||||
d = j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150))
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
actual = sys.stdout.getvalue().strip()
|
d = j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150))
|
||||||
|
actual = fake_out.getvalue().strip()
|
||||||
|
|
||||||
lines = ['[INFO] Start to read j2k main header (0).',
|
lines = ['[INFO] Start to read j2k main header (0).',
|
||||||
'[INFO] Main header has been correctly decoded.',
|
'[INFO] Main header has been correctly decoded.',
|
||||||
|
|
@ -72,47 +72,35 @@ class TestCallbacks15(unittest.TestCase):
|
||||||
"""This test suite is for OpenJPEG 1.5.1 properties.
|
"""This test suite is for OpenJPEG 1.5.1 properties.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
|
||||||
cls.openjp2 = glymur.lib.openjp2.OPENJP2
|
|
||||||
glymur.lib.openjp2.OPENJP2 = None
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
# Restore OPENJP2
|
|
||||||
glymur.lib.openjp2.OPENJP2 = cls.openjp2
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Save sys.stdout.
|
|
||||||
self.stdout = sys.stdout
|
|
||||||
sys.stdout = StringIO()
|
|
||||||
self.jp2file = glymur.data.nemo()
|
self.jp2file = glymur.data.nemo()
|
||||||
self.j2kfile = glymur.data.goodstuff()
|
self.j2kfile = glymur.data.goodstuff()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# Restore stdout.
|
pass
|
||||||
sys.stdout = self.stdout
|
|
||||||
|
|
||||||
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 that we get the expected stdio output when our internal info
|
||||||
# callback handler is enabled.
|
# callback handler is enabled.
|
||||||
j = glymur.Jp2k(self.j2kfile)
|
with patch('glymur.lib.openjp2.OPENJP2', new=None):
|
||||||
d = j.read(rlevel=1, verbose=True)
|
# Force to use OPENJPEG instead of OPENJP2.
|
||||||
actual = sys.stdout.getvalue().strip()
|
j = glymur.Jp2k(self.j2kfile)
|
||||||
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+
|
d = j.read(rlevel=1, verbose=True)
|
||||||
\[INFO\]\s-\stiers-1\stook\s
|
actual = fake_out.getvalue().strip()
|
||||||
[0-9]+\.[0-9]+\ss\s+
|
|
||||||
\[INFO\]\s-\sdwt\stook\s
|
regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+
|
||||||
(-){0,1}[0-9]+\.[0-9]+\ss\s+
|
\[INFO\]\s-\stiers-1\stook\s
|
||||||
\[INFO\]\s-\stile\sdecoded\sin\s
|
[0-9]+\.[0-9]+\ss\s+
|
||||||
[0-9]+\.[0-9]+\ss""",
|
\[INFO\]\s-\sdwt\stook\s
|
||||||
re.VERBOSE)
|
(-){0,1}[0-9]+\.[0-9]+\ss\s+
|
||||||
if sys.hexversion <= 0x03020000:
|
\[INFO\]\s-\stile\sdecoded\sin\s
|
||||||
self.assertRegexpMatches(actual, regex)
|
[0-9]+\.[0-9]+\ss""",
|
||||||
else:
|
re.VERBOSE)
|
||||||
self.assertRegex(actual, regex)
|
if sys.hexversion <= 0x03020000:
|
||||||
|
self.assertRegexpMatches(actual, regex)
|
||||||
|
else:
|
||||||
|
self.assertRegex(actual, regex)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue