From dc0c1950a259602c149abc3cb300254c6daab5be Mon Sep 17 00:00:00 2001 From: jevans Date: Sun, 19 Oct 2014 13:00:45 -0400 Subject: [PATCH] printing of default decompression parameters --- glymur/lib/openjp2.py | 7 +++++++ glymur/test/fixtures.py | 19 +++++++++++++++++++ glymur/test/test_printing.py | 29 ++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/glymur/lib/openjp2.py b/glymur/lib/openjp2.py index f3f5b5c..d5322ec 100644 --- a/glymur/lib/openjp2.py +++ b/glymur/lib/openjp2.py @@ -201,6 +201,13 @@ class DecompressionParametersType(ctypes.Structure): # maximum number of tiles ("flags", ctypes.c_uint32)] + def __str__(self): + msg = "{0}:\n".format(self.__class__) + for field_name, _ in self._fields_: + msg += " {0}: {1}\n".format( + field_name, getattr(self, field_name)) + return msg + class CompressionParametersType(ctypes.Structure): """Compression parameters. diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 4b3972c..1727d6f 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -900,3 +900,22 @@ goodstuff_with_full_header = r"""Codestream: Step size: [(0, 8), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), (0, 10)] SOD marker segment @ (164, 0) EOC marker segment @ (115218, 0)""" + +decompression_parameters_type = """: + cp_reduce: 0 + cp_layer: 0 + infile: b'' + outfile: b'' + decod_format: -1 + cod_format: -1 + DA_x0: 0 + DA_x1: 0 + DA_y0: 0 + DA_y1: 0 + m_verbose: 0 + tile_index: 0 + nb_tile_to_decode: 0 + jpwl_correct: 0 + jpwl_exp_comps: 0 + jpwl_max_tiles: 0 + flags: 0""" diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 49bbe6d..8c548b7 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -32,12 +32,13 @@ import lxml.etree as ET import glymur from glymur import Jp2k, command_line from . import fixtures -from .fixtures import OPJ_DATA_ROOT, opj_data_file -from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG -from .fixtures import text_gbr_27, text_gbr_33, text_gbr_34 +from .fixtures import ( + OPJ_DATA_ROOT, opj_data_file, + WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG, + WINDOWS_TMP_FILE_MSG, text_gbr_27, text_gbr_33, text_gbr_34 +) - -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) class TestPrinting(unittest.TestCase): """Tests for verifying how printing works.""" def setUp(self): @@ -617,6 +618,24 @@ class TestPrinting(unittest.TestCase): self.assertEqual(actual, expected) +@unittest.skipIf(re.match('1|2.0', glymur.version.openjpeg_version), + "Requires openjpeg 2.1.0 or higher") +class TestPrintingOpenjp2(unittest.TestCase): + """Tests for verifying how printing works on openjp2 library structures.""" + def setUp(self): + self.jp2file = glymur.data.nemo() + + def tearDown(self): + pass + + def test_decompression_parameters(self): + """printing DecompressionParametersType""" + dparams = glymur.lib.openjp2.set_default_decoder_parameters() + with patch('sys.stdout', new=StringIO()) as fake_out: + print(dparams) + actual = fake_out.getvalue().strip() + expected = fixtures.decompression_parameters_type + self.assertEqual(actual, expected) @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set")