File: test_commandline_jpeg2jp2.py

package info (click to toggle)
glymur 0.14.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,104 kB
  • sloc: python: 17,238; makefile: 129; xml: 102; sh: 62
file content (253 lines) | stat: -rw-r--r-- 6,774 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
"""
Test command line interface to JPEG2JP2
"""

# standard library imports
import unittest
from unittest.mock import patch

# 3rd party library imports

# Local imports
from glymur import JPEG2JP2, command_line, reset_option
from . import fixtures
from .fixtures import (
    OPENJPEG_NOT_AVAILABLE,
    OPENJPEG_NOT_AVAILABLE_MSG,
    CANNOT_USE_IMPORTLIB_METADATA
)


@unittest.skipIf(OPENJPEG_NOT_AVAILABLE, OPENJPEG_NOT_AVAILABLE_MSG)
@unittest.skipIf(
    CANNOT_USE_IMPORTLIB_METADATA,
    'missing importlib.metadata.files ?'
)
class TestSuite(fixtures.TestJPEGCommon):

    def test_smoke(self):
        """
        SCENARIO:  no special options

        EXPECTED RESULT:  no errors
        """
        new = ['', str(self.retina), str(self.temp_jp2_filename)]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_verbosity(self):
        """
        SCENARIO:  verbosity is specified on the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--verbosity', 'info'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_tilesize(self):
        """
        SCENARIO:  tilesize is specified on the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--tilesize', '512', '512'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_psnr(self):
        """
        SCENARIO:  specify psnr via the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--psnr', '30', '35', '40', '0'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_irreversible(self):
        """
        SCENARIO:  specify the irreversible transform via the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--irreversible'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_plt(self):
        """
        SCENARIO:  specify the PLT markers via the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--plt'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_eph(self):
        """
        SCENARIO:  specify the EPH markers via the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--eph'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_sop(self):
        """
        SCENARIO:  specify the SOP markers via the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--sop'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_progression_order(self):
        """
        SCENARIO:  specify the procession order via the command line

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--prog', 'rlcp'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_number_of_resolutions(self):
        """
        SCENARIO:  specify resolution

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--numres', '6'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_num_threads(self):
        """
        SCENARIO:  specify number of threads to use

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--num-threads', '4'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

        reset_option('all')

    def test_icc_profile(self):
        """
        SCENARIO:  specify to include an ICC profile

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.rocket), str(self.temp_jp2_filename),
            '--include-icc-profile',
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_layers(self):
        """
        SCENARIO:  specify compression ratios

        EXPECTED RESULT:  no errors
        """
        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--cratio', '200', '50', '10'
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()

    def test_resolution_boxes(self):
        """
        SCENARIO:  specify capture and display resolution

        EXPECTED RESULT:  no errors
        """
        vresc, hresc = 0.1, 0.2
        vresd, hresd = 0.3, 0.4

        new = [
            '', str(self.retina), str(self.temp_jp2_filename),
            '--capture-resolution', str(vresc), str(hresc),
            '--display-resolution', str(vresd), str(hresd),
        ]
        with (
            patch('sys.argv', new=new),
            patch.object(JPEG2JP2, 'run', new=lambda x: None)
        ):
            command_line.jpeg2jp2()