From 7e99287bc3500a19d4f6394c774bcc38b749750a Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 10 Sep 2014 20:40:37 -0400 Subject: [PATCH] Starting issue254 --- glymur/__init__.py | 1 - glymur/command_line.py | 0 glymur/test/test_jp2dump.py | 118 ++++++++++++++++++++++++++++++++++++ setup.py | 4 +- 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 glymur/command_line.py create mode 100644 glymur/test/test_jp2dump.py diff --git a/glymur/__init__.py b/glymur/__init__.py index f39d6ef..5826f8c 100644 --- a/glymur/__init__.py +++ b/glymur/__init__.py @@ -9,7 +9,6 @@ __version__ = version.version from .jp2k import Jp2k from .jp2dump import jp2dump from .jp2box import get_printoptions, set_printoptions -from .jp2box import get_parseoptions, set_parseoptions from . import data diff --git a/glymur/command_line.py b/glymur/command_line.py new file mode 100644 index 0000000..e69de29 diff --git a/glymur/test/test_jp2dump.py b/glymur/test/test_jp2dump.py new file mode 100644 index 0000000..6396300 --- /dev/null +++ b/glymur/test/test_jp2dump.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +"""Test suite for jp2dump console script. +""" +import os +import re +import struct +import sys +import tempfile +import warnings +import unittest + +if sys.hexversion < 0x03000000: + from StringIO import StringIO +else: + from io import StringIO + +if sys.hexversion <= 0x03030000: + from mock import patch +else: + from unittest.mock import patch + +import lxml.etree as ET + +import glymur +from glymur import command_line + + +class TestJp2dump(unittest.TestCase): + """Tests for verifying how jp2dump console script works.""" + def setUp(self): + self.jpxfile = glymur.data.jpxfile() + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + # Reset printoptions for every test. + glymur.set_printoptions(short=False, xml=True, codestream=True) + + def tearDown(self): + pass + + def test_default_nemo(self): + """Should be able to dump a JP2 file's metadata.""" + with patch('sys.stdout', new=StringIO()) as fake_out: + sys.argv = ['', self.jp2file] + command_line.main() + actual = fake_out.getvalue().strip() + # Remove the file line, as that is filesystem-dependent. + lines = actual.split('\n') + actual = '\n'.join(lines[1:]) + + self.fail('Finish the test.') + + def test_codestream_0(self): + """Verify dumping with -c 0, supressing all codestream details.""" + with patch('sys.stdout', new=StringIO()) as fake_out: + sys.argv = ['', '-c', '0', self.jp2file] + command_line.main() + actual = fake_out.getvalue().strip() + # Remove the file line, as that is filesystem-dependent. + lines = actual.split('\n') + actual = '\n'.join(lines[1:]) + + self.fail('Finish the test.') + + def test_codestream_1(self): + """Verify dumping with -c 1, printing headers.""" + with patch('sys.stdout', new=StringIO()) as fake_out: + sys.argv = ['', '-c', '1', self.jp2file] + command_line.main() + actual = fake_out.getvalue().strip() + # Remove the file line, as that is filesystem-dependent. + lines = actual.split('\n') + actual = '\n'.join(lines[1:]) + + self.fail('Finish the test.') + + def test_codestream_2(self): + """Verify dumping with -c 2, full details.""" + with patch('sys.stdout', new=StringIO()) as fake_out: + sys.argv = ['', '-c', '2', self.jp2file] + command_line.main() + actual = fake_out.getvalue().strip() + # Remove the file line, as that is filesystem-dependent. + lines = actual.split('\n') + actual = '\n'.join(lines[1:]) + + self.fail('Finish the test.') + + def test_codestream_invalid(self): + """Verify dumping with -c 3, not allowd.""" + self.fail('Finish the test.') + with self.assertRaises(ValueError): + sys.argv = ['', '-c', '3', self.jp2file] + command_line.main() + + def test_short(self): + """Verify dumping with -s, short option.""" + with patch('sys.stdout', new=StringIO()) as fake_out: + sys.argv = ['', '-s', self.jp2file] + command_line.main() + actual = fake_out.getvalue().strip() + # Remove the file line, as that is filesystem-dependent. + lines = actual.split('\n') + actual = '\n'.join(lines[1:]) + + self.fail('Finish the test.') + + def test_suppress_xml(self): + """Verify dumping with -x, suppress XML.""" + with patch('sys.stdout', new=StringIO()) as fake_out: + sys.argv = ['', '-x', self.jp2file] + command_line.main() + actual = fake_out.getvalue().strip() + # Remove the file line, as that is filesystem-dependent. + lines = actual.split('\n') + actual = '\n'.join(lines[1:]) + + self.fail('Finish the test.') diff --git a/setup.py b/setup.py index 94d692e..5be9368 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,9 @@ kwargs = {'name': 'glymur', 'packages': ['glymur', 'glymur.data', 'glymur.test', 'glymur.lib', 'glymur.lib.test'], 'package_data': {'glymur': ['data/*.jp2', 'data/*.j2k', 'data/*.jpx']}, - 'scripts': ['bin/jp2dump'], + 'entry_points': { + 'console_scripts': ['jp2dump=glymur.command_line:main'], + }, 'license': 'MIT', 'test_suite': 'glymur.test'}