Refactored OPJ_DATA_ROOT handling into a fixture. Closes #108

This commit is contained in:
jevans 2013-08-28 21:35:22 -04:00
commit 8a8cccb8ab
7 changed files with 501 additions and 619 deletions

View file

@ -1,6 +1,7 @@
""" """
Test fixtures common to more than one test point. Test fixtures common to more than one test point.
""" """
import os
import re import re
import sys import sys
import warnings import warnings
@ -27,6 +28,19 @@ if glymur.lib.openjp2.OPENJP2 is not None:
NO_READ_BACKEND_MSG = "Matplotlib with the PIL backend must be available in " NO_READ_BACKEND_MSG = "Matplotlib with the PIL backend must be available in "
NO_READ_BACKEND_MSG += "order to run the tests in this suite." NO_READ_BACKEND_MSG += "order to run the tests in this suite."
try:
OPJ_DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
OPJ_DATA_ROOT = None
except:
raise
def opj_data_file(relative_file_name):
"""Compact way of forming a full filename from OpenJPEG's test suite."""
jfile = os.path.join(OPJ_DATA_ROOT, relative_file_name)
return jfile
try: try:
from matplotlib.pyplot import imread from matplotlib.pyplot import imread

View file

@ -20,16 +20,10 @@ else:
import numpy as np import numpy as np
from glymur import Jp2k from glymur import Jp2k
from .fixtures import OPJ_DATA_ROOT, opj_data_file
try:
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
DATA_ROOT = None
except:
raise
@unittest.skipIf(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")
class TestICC(unittest.TestCase): class TestICC(unittest.TestCase):
"""ICC profile tests""" """ICC profile tests"""
@ -42,7 +36,7 @@ class TestICC(unittest.TestCase):
def test_file5(self): def test_file5(self):
"""basic ICC profile""" """basic ICC profile"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file5.jp2') filename = opj_data_file('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)
@ -75,8 +69,7 @@ class TestICC(unittest.TestCase):
"Uses features introduced in 3.2.") "Uses features introduced in 3.2.")
def test_invalid_profile_header(self): def test_invalid_profile_header(self):
"""invalid ICC header data should cause UserWarning""" """invalid ICC header data should cause UserWarning"""
jfile = os.path.join(DATA_ROOT, jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
'input/nonregression/orb-blue10-lin-jp2.jp2')
# assertWarns in Python 3.3 (python2.7/pylint issue) # assertWarns in Python 3.3 (python2.7/pylint issue)
# pylint: disable=E1101 # pylint: disable=E1101

View file

@ -25,10 +25,6 @@ if sys.hexversion < 0x02070000:
else: else:
import unittest import unittest
if sys.hexversion <= 0x03030000:
from mock import patch
else:
from unittest.mock import patch
import warnings import warnings
import numpy as np import numpy as np
@ -39,13 +35,7 @@ from glymur import Jp2k
from .fixtures import OPENJP2_IS_V2_OFFICIAL from .fixtures import OPENJP2_IS_V2_OFFICIAL
from .fixtures import OPENJPEG_VERSION from .fixtures import OPENJPEG_VERSION
from .fixtures import OPJ_DATA_ROOT, opj_data_file
try:
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
DATA_ROOT = None
except:
raise
# Doc tests should be run as well. # Doc tests should be run as well.
@ -380,7 +370,7 @@ class TestJp2k(unittest.TestCase):
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
j2k.read() j2k.read()
@unittest.skipIf(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")
def test_read_differing_subsamples(self): def test_read_differing_subsamples(self):
"""should error out with read used on differently subsampled images""" """should error out with read used on differently subsampled images"""
@ -388,7 +378,7 @@ class TestJp2k(unittest.TestCase):
# on an image with differing subsamples # on an image with differing subsamples
# #
# Issue 86. # Issue 86.
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k') filename = opj_data_file('input/conformance/p0_05.j2k')
j = Jp2k(filename) j = Jp2k(filename)
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
j.read() j.read()
@ -1039,7 +1029,7 @@ class TestJp2k15(unittest.TestCase):
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
j2k.read() j2k.read()
@unittest.skipIf(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")
def test_read_differing_subsamples(self): def test_read_differing_subsamples(self):
"""should error out with read used on differently subsampled images""" """should error out with read used on differently subsampled images"""
@ -1047,7 +1037,7 @@ class TestJp2k15(unittest.TestCase):
# on an image with differing subsamples # on an image with differing subsamples
# #
# Issue 86. # Issue 86.
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k') filename = opj_data_file('input/conformance/p0_05.j2k')
j = Jp2k(filename) j = Jp2k(filename)
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
j.read() j.read()
@ -1347,7 +1337,8 @@ class TestJp2k15(unittest.TestCase):
self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ') self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ')
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
@unittest.skipIf(re.match('1\.[345]\.\d', OPENJPEG_VERSION) is not None, @unittest.skipIf(re.match(r"""1\.[345]\.\d""",
OPENJPEG_VERSION) is not None,
"Segfault on official v1.x series.") "Segfault on official v1.x series.")
def test_openjpeg_library_message(self): def test_openjpeg_library_message(self):
"""Verify the error message produced by the openjpeg library""" """Verify the error message produced by the openjpeg library"""
@ -1426,6 +1417,5 @@ class TestJp2k15(unittest.TestCase):
self.assertFalse('Make' in exif['Image'].keys()) self.assertFalse('Make' in exif['Image'].keys())
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

File diff suppressed because it is too large Load diff

View file

@ -23,23 +23,17 @@ else:
import numpy as np import numpy as np
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
from .fixtures import OPJ_DATA_ROOT, opj_data_file
from glymur import Jp2k from glymur import Jp2k
import glymur import glymur
try:
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
DATA_ROOT = None
except:
raise
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
"Missing openjp2 library.") "Missing openjp2 library.")
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
@unittest.skipIf(DATA_ROOT is None, @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set") "OPJ_OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegative(unittest.TestCase): class TestSuiteNegative(unittest.TestCase):
"""Test suite for certain negative tests from openjpeg suite.""" """Test suite for certain negative tests from openjpeg suite."""
@ -54,7 +48,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_psnr_with_cratios(self): def test_psnr_with_cratios(self):
"""Using psnr with cratios options is not allowed.""" """Using psnr with cratios options is not allowed."""
# Not an OpenJPEG test, but close. # Not an OpenJPEG test, but close.
infile = os.path.join(DATA_ROOT, 'input/nonregression/Bretagne1.ppm') infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -64,7 +58,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_nr_marker_not_compliant(self): def test_nr_marker_not_compliant(self):
"""non-compliant marker, should still be able to read""" """non-compliant marker, should still be able to read"""
relpath = 'input/nonregression/MarkerIsNotCompliant.j2k' relpath = 'input/nonregression/MarkerIsNotCompliant.j2k'
jfile = os.path.join(DATA_ROOT, relpath) jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile) jp2k = Jp2k(jfile)
jp2k.get_codestream(header_only=False) jp2k.get_codestream(header_only=False)
self.assertTrue(True) self.assertTrue(True)
@ -74,7 +68,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_nr_illegalclrtransform(self): def test_nr_illegalclrtransform(self):
"""EOC marker is bad""" """EOC marker is bad"""
relpath = 'input/nonregression/illegalcolortransform.j2k' relpath = 'input/nonregression/illegalcolortransform.j2k'
jfile = os.path.join(DATA_ROOT, relpath) jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile) jp2k = Jp2k(jfile)
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
codestream = jp2k.get_codestream(header_only=False) codestream = jp2k.get_codestream(header_only=False)
@ -87,7 +81,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_nr_cannotreadwnosizeknown(self): def test_nr_cannotreadwnosizeknown(self):
"""not sure exactly what is wrong with this file""" """not sure exactly what is wrong with this file"""
relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k' relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
jfile = os.path.join(DATA_ROOT, relpath) jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile) jp2k = Jp2k(jfile)
jp2k.get_codestream(header_only=False) jp2k.get_codestream(header_only=False)
self.assertTrue(True) self.assertTrue(True)
@ -118,7 +112,7 @@ class TestSuiteNegative(unittest.TestCase):
# Verify that a warning is issued if we read past the end of a box # Verify that a warning is issued if we read past the end of a box
# This file has a palette (pclr) box whose length is impossibly # This file has a palette (pclr) box whose length is impossibly
# short. # short.
infile = os.path.join(DATA_ROOT, infile = os.path.join(OPJ_DATA_ROOT,
'input/nonregression/mem-b2ace68c-1381.jp2') 'input/nonregression/mem-b2ace68c-1381.jp2')
with self.assertWarns(UserWarning): with self.assertWarns(UserWarning):
Jp2k(infile) Jp2k(infile)

View file

@ -19,23 +19,17 @@ else:
import unittest import unittest
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
from .fixtures import OPJ_DATA_ROOT, opj_data_file
from glymur import Jp2k from glymur import Jp2k
import glymur import glymur
try:
data_root = os.environ['OPJ_DATA_ROOT']
except KeyError:
data_root = None
except:
raise
@unittest.skipIf(os.name == "nt", "no write support on windows, period") @unittest.skipIf(os.name == "nt", "no write support on windows, period")
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
"Missing openjp2 library.") "Missing openjp2 library.")
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
@unittest.skipIf(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")
class TestSuiteWrite(unittest.TestCase): class TestSuiteWrite(unittest.TestCase):
"""Tests for writing with openjp2 backend. """Tests for writing with openjp2 backend.
@ -51,7 +45,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne1_ppm_1_encode(self): def test_NR_ENC_Bretagne1_ppm_1_encode(self):
"""NR-ENC-Bretagne1.ppm-1-encode""" """NR-ENC-Bretagne1.ppm-1-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm') infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -115,7 +109,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne1_ppm_2_encode(self): def test_NR_ENC_Bretagne1_ppm_2_encode(self):
"""NR-ENC-Bretagne1.ppm-2-encode""" """NR-ENC-Bretagne1.ppm-2-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm') infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -180,7 +174,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne1_ppm_3_encode(self): def test_NR_ENC_Bretagne1_ppm_3_encode(self):
"""NR-ENC-Bretagne1.ppm-3-encode""" """NR-ENC-Bretagne1.ppm-3-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm') infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -247,7 +241,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_4_encode(self): def test_NR_ENC_Bretagne2_ppm_4_encode(self):
"""NR-ENC-Bretagne2.ppm-4-encode""" """NR-ENC-Bretagne2.ppm-4-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -316,7 +310,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_5_encode(self): def test_NR_ENC_Bretagne2_ppm_5_encode(self):
"""NR-ENC-Bretagne2.ppm-5-encode""" """NR-ENC-Bretagne2.ppm-5-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -379,7 +373,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_6_encode(self): def test_NR_ENC_Bretagne2_ppm_6_encode(self):
"""NR-ENC-Bretagne2.ppm-6-encode""" """NR-ENC-Bretagne2.ppm-6-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -447,7 +441,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_7_encode(self): def test_NR_ENC_Bretagne2_ppm_7_encode(self):
"""NR-ENC-Bretagne2.ppm-7-encode""" """NR-ENC-Bretagne2.ppm-7-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -514,7 +508,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_8_encode(self): def test_NR_ENC_Bretagne2_ppm_8_encode(self):
"""NR-ENC-Bretagne2.ppm-8-encode""" """NR-ENC-Bretagne2.ppm-8-encode"""
infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -578,7 +572,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Cevennes1_bmp_9_encode(self): def test_NR_ENC_Cevennes1_bmp_9_encode(self):
"""NR-ENC-Cevennes1.bmp-9-encode""" """NR-ENC-Cevennes1.bmp-9-encode"""
infile = os.path.join(data_root, 'input/nonregression/Cevennes1.bmp') infile = opj_data_file('input/nonregression/Cevennes1.bmp')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -641,7 +635,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Cevennes2_ppm_10_encode(self): def test_NR_ENC_Cevennes2_ppm_10_encode(self):
"""NR-ENC-Cevennes2.ppm-10-encode""" """NR-ENC-Cevennes2.ppm-10-encode"""
infile = os.path.join(data_root, 'input/nonregression/Cevennes2.ppm') infile = opj_data_file('input/nonregression/Cevennes2.ppm')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
@ -704,8 +698,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Rome_bmp_11_encode(self): def test_NR_ENC_Rome_bmp_11_encode(self):
"""NR-ENC-Rome.bmp-11-encode""" """NR-ENC-Rome.bmp-11-encode"""
data = read_image(os.path.join(data_root, data = read_image(opj_data_file('input/nonregression/Rome.bmp'))
'input/nonregression/Rome.bmp'))
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
jp2 = Jp2k(tfile.name, 'wb') jp2 = Jp2k(tfile.name, 'wb')
jp2.write(data, psnr=[30, 35, 50], prog='LRCP', numres=3) jp2.write(data, psnr=[30, 35, 50], prog='LRCP', numres=3)
@ -804,8 +797,7 @@ class TestSuiteWrite(unittest.TestCase):
"""NR-ENC-random-issue-0005.tif-12-encode""" """NR-ENC-random-issue-0005.tif-12-encode"""
# opj_decompress has trouble reading it, but that is not an issue here. # opj_decompress has trouble reading it, but that is not an issue here.
# The nature of the image itself seems to give the compressor trouble. # The nature of the image itself seems to give the compressor trouble.
infile = os.path.join(data_root, infile = opj_data_file('input/nonregression/random-issue-0005.tif')
'input/nonregression/random-issue-0005.tif')
data = read_image(infile) data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')

View file

@ -32,13 +32,7 @@ else:
import glymur import glymur
from glymur import Jp2k from glymur import Jp2k
from .fixtures import OPJ_DATA_ROOT, opj_data_file
try:
DATA_ROOT = os.environ['OPJ_DATA_ROOT']
except KeyError:
DATA_ROOT = None
except:
raise
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
@ -287,11 +281,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_icc_profile(self): def test_icc_profile(self):
"""verify printing of colr box with ICC profile""" """verify printing of colr box with ICC profile"""
filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2') filename = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings(): with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile. # brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore") warnings.simplefilter("ignore")
@ -356,11 +350,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_crg(self): def test_crg(self):
"""verify printing of CRG segment""" """verify printing of CRG segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') filename = opj_data_file('input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -371,11 +365,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_rgn(self): def test_rgn(self):
"""verify printing of RGN segment""" """verify printing of RGN segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') filename = opj_data_file('input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -388,11 +382,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_sop(self): def test_sop(self):
"""verify printing of SOP segment""" """verify printing of SOP segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') filename = opj_data_file('input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -403,11 +397,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_cme(self): def test_cme(self):
"""Test printing a CME or comment marker segment.""" """Test printing a CME or comment marker segment."""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_02.j2k') filename = opj_data_file('input/conformance/p0_02.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
# 2nd to last segment in the main header # 2nd to last segment in the main header
@ -431,11 +425,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_plt_segment(self): def test_plt_segment(self):
"""verify printing of PLT segment""" """verify printing of PLT segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_07.j2k') filename = opj_data_file('input/conformance/p0_07.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -450,11 +444,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_pod_segment(self): def test_pod_segment(self):
"""verify printing of POD segment""" """verify printing of POD segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_13.j2k') filename = opj_data_file('input/conformance/p0_13.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -480,11 +474,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_ppm_segment(self): def test_ppm_segment(self):
"""verify printing of PPM segment""" """verify printing of PPM segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p1_03.j2k') filename = opj_data_file('input/conformance/p1_03.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -498,11 +492,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_ppt_segment(self): def test_ppt_segment(self):
"""verify printing of ppt segment""" """verify printing of ppt segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p1_06.j2k') filename = opj_data_file('input/conformance/p1_06.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False) codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -610,11 +604,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_tlm_segment(self): def test_tlm_segment(self):
"""verify printing of TLM segment""" """verify printing of TLM segment"""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_15.j2k') filename = opj_data_file('input/conformance/p0_15.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -704,11 +698,11 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x02070000, @unittest.skipIf(sys.hexversion < 0x02070000,
"Differences in XML printing between 2.6 and 2.7") "Differences in XML printing between 2.6 and 2.7")
@unittest.skipIf(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")
def test_xml(self): def test_xml(self):
"""verify printing of XML box""" """verify printing of XML box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file1.jp2') filename = opj_data_file('input/conformance/file1.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2]) print(j.box[2])
@ -735,11 +729,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_channel_definition(self): def test_channel_definition(self):
"""verify printing of cdef box""" """verify printing of cdef box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file2.jp2') filename = opj_data_file('input/conformance/file2.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2]) print(j.box[2].box[2])
@ -751,11 +745,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_component_mapping(self): def test_component_mapping(self):
"""verify printing of cmap box""" """verify printing of cmap box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2') filename = opj_data_file('input/conformance/file9.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2]) print(j.box[2].box[2])
@ -767,11 +761,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_palette7(self): def test_palette7(self):
"""verify printing of pclr box""" """verify printing of pclr box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2') filename = opj_data_file('input/conformance/file9.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1]) print(j.box[2].box[1])
@ -781,11 +775,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_rreq(self): def test_rreq(self):
"""verify printing of reader requirements box""" """verify printing of reader requirements box"""
filename = os.path.join(DATA_ROOT, 'input/conformance/file7.jp2') filename = opj_data_file('input/conformance/file7.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2]) print(j.box[2])
@ -805,11 +799,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_differing_subsamples(self): def test_differing_subsamples(self):
"""verify printing of SIZ with different subsampling... Issue 86.""" """verify printing of SIZ with different subsampling... Issue 86."""
filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k') filename = opj_data_file('input/conformance/p0_05.j2k')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
codestream = j.get_codestream() codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
@ -828,11 +822,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_palette_box(self): def test_palette_box(self):
"""Verify that palette (pclr) boxes are printed without error.""" """Verify that palette (pclr) boxes are printed without error."""
filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2') filename = opj_data_file('input/conformance/file9.jp2')
j = glymur.Jp2k(filename) j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1]) print(j.box[2].box[1])
@ -921,13 +915,13 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03000000, @unittest.skipIf(sys.hexversion < 0x03000000,
"Ordered dicts not printing well in 2.7") "Ordered dicts not printing well in 2.7")
@unittest.skipIf(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")
def test_jpx_approx_icc_profile(self): def test_jpx_approx_icc_profile(self):
"""verify jpx with approx field equal to zero""" """verify jpx with approx field equal to zero"""
# ICC profiles may be used in JP2, but the approximation field should # ICC profiles may be used in JP2, but the approximation field should
# be zero unless we have jpx. This file does both. # be zero unless we have jpx. This file does both.
filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2') filename = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings(): with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile. # brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore") warnings.simplefilter("ignore")
@ -966,11 +960,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines) expected = '\n'.join(lines)
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
@unittest.skipIf(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")
def test_uuid(self): def test_uuid(self):
"""verify printing of UUID box""" """verify printing of UUID box"""
filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2') filename = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings(): with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile. # brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore") warnings.simplefilter("ignore")