2828HAS_JPEG_LS_PLUGIN = '1.2.840.10008.1.2.4.80' in decoders
2929HAS_JPEG_2K_PLUGIN = '1.2.840.10008.1.2.4.90' in decoders
3030
31+ RUN_JPEG = HAS_JPEG_PLUGIN and HAS_PYDICOM
32+ RUN_JPEGLS = HAS_JPEG_LS_PLUGIN and HAS_PYDICOM
33+ RUN_JPEG2K = HAS_JPEG_2K_PLUGIN and HAS_PYDICOM
34+
3135
3236@pytest .mark .skipif (not HAS_PYDICOM or HAS_PLUGINS , reason = "Plugins available" )
3337class TestNoPlugins (object ):
@@ -68,9 +72,9 @@ def test_get_pixeldata_no_lj_syntax(self):
6872 handler .get_pixeldata (ds )
6973
7074
71- @pytest .mark .skipif (not HAS_PYDICOM or not HAS_PLUGINS , reason = "No plugins" )
7275class TestPlugins (object ):
7376 """Test interaction with plugins."""
77+ @pytest .mark .skipif (not RUN_JPEG , reason = "No JPEG plugin" )
7478 def test_pixel_array (self ):
7579 # Should basically just not mess up the usual pydicom behaviour
7680 index = get_indexed_datasets ('1.2.840.10008.1.2.4.50' )
@@ -106,6 +110,7 @@ def test_should_change_PI(self):
106110 result = handler .should_change_PhotometricInterpretation_to_RGB (None )
107111 assert result is False
108112
113+ @pytest .mark .skipif (not RUN_JPEG , reason = "No JPEG plugin" )
109114 def test_missing_required (self ):
110115 """Test missing required element raises."""
111116 index = get_indexed_datasets ('1.2.840.10008.1.2.4.50' )
@@ -118,6 +123,7 @@ def test_missing_required(self):
118123 with pytest .raises (AttributeError , match = msg ):
119124 ds .pixel_array
120125
126+ @pytest .mark .skipif (not RUN_JPEG , reason = "No JPEG plugin" )
121127 def test_ybr_full_422 (self ):
122128 """Test YBR_FULL_422 data decoded."""
123129 index = get_indexed_datasets ('1.2.840.10008.1.2.4.50' )
@@ -126,7 +132,7 @@ def test_ybr_full_422(self):
126132 arr = ds .pixel_array
127133
128134
129- @pytest .mark .skipif (not HAS_PYDICOM or not HAS_JPEG_PLUGIN , reason = "No plugin" )
135+ @pytest .mark .skipif (not RUN_JPEG , reason = "No JPEG plugin" )
130136class TestJPEGPlugin (object ):
131137 """Test interaction with plugins that support JPEG."""
132138 uid = '1.2.840.10008.1.2.4.50'
@@ -154,7 +160,7 @@ def test_pixel_array(self):
154160 assert 255 == arr [95 , 50 ]
155161
156162
157- @pytest .mark .skipif (not HAS_PYDICOM or not HAS_JPEG_LS_PLUGIN , reason = "No plugin" )
163+ @pytest .mark .skipif (not RUN_JPEGLS , reason = "No JPEG-LS plugin" )
158164class TestJPEGLSPlugin (object ):
159165 """Test interaction with plugins that support JPEG-LS."""
160166 uid = '1.2.840.10008.1.2.4.80'
@@ -175,7 +181,7 @@ def test_pixel_array(self):
175181 )
176182
177183
178- @pytest .mark .skipif (not HAS_PYDICOM or not HAS_JPEG_2K_PLUGIN , reason = "No plugin" )
184+ @pytest .mark .skipif (not RUN_JPEG2K , reason = "No JPEG 2000 plugin" )
179185class TestJPEG2KPlugin (object ):
180186 """Test interaction with plugins that support JPEG 2000."""
181187 uid = '1.2.840.10008.1.2.4.90'
@@ -213,29 +219,33 @@ def test_pixel_array(self):
213219 [175 , 17 , 0 ]] == arr [175 :195 , 28 , :].tolist ()
214220
215221
216- @pytest .mark .skipif (not HAS_PYDICOM or not HAS_PLUGINS , reason = "No plugins" )
217222class TestUtils (object ):
218223 """Test the pydicom.utils functions."""
224+ @pytest .mark .skipif (not RUN_JPEG2K , reason = "No JPEG 2000 plugin" )
219225 def test_generate_frames_single_1s (self ):
220226 """Test with single frame, 1 sample/px."""
221- index = get_indexed_datasets ('1.2.840.10008.1.2.4.50 ' )
222- ds = index ['JPEGBaseline_1s_1f_u_08_08 .dcm' ]['ds' ]
227+ index = get_indexed_datasets ('1.2.840.10008.1.2.4.90 ' )
228+ ds = index ['693_J2KR .dcm' ]['ds' ]
223229 assert 1 == getattr (ds , 'NumberOfFrames' , 1 )
224230 assert 1 == ds .SamplesPerPixel
225- frames = generate_frames (ds )
226- arr = next (frames )
231+ frame_gen = generate_frames (ds )
232+ arr = next (frame_gen )
227233 with pytest .raises (StopIteration ):
228- next (frames )
234+ next (frame_gen )
229235
230236 assert arr .flags .writeable
231- assert 'uint8 ' == arr .dtype
237+ assert 'int16 ' == arr .dtype
232238 assert (ds .Rows , ds .Columns ) == arr .shape
233- assert 64 == arr [76 , 22 ]
239+ assert (
240+ [1022 , 1051 , 1165 , 1442 , 1835 , 2096 , 2074 , 1868 , 1685 , 1603 ] ==
241+ arr [290 , 135 :145 ].tolist ()
242+ )
234243
244+ @pytest .mark .skipif (not RUN_JPEG2K , reason = "No JPEG 2000 plugin" )
235245 def test_generate_frames_1s (self ):
236246 """Test with multiple frames, 1 sample/px."""
237- index = get_indexed_datasets ('1.2.840.10008.1.2.4.80 ' )
238- ds = index ['emri_small_jpeg_ls_lossless .dcm' ]['ds' ]
247+ index = get_indexed_datasets ('1.2.840.10008.1.2.4.90 ' )
248+ ds = index ['emri_small_jpeg_2k_lossless .dcm' ]['ds' ]
239249 assert ds .NumberOfFrames > 1
240250 assert 1 == ds .SamplesPerPixel
241251 frames = generate_frames (ds )
@@ -246,6 +256,7 @@ def test_generate_frames_1s(self):
246256 assert (ds .Rows , ds .Columns ) == arr .shape
247257 assert 163 == arr [12 , 23 ]
248258
259+ @pytest .mark .skipif (not RUN_JPEG , reason = "No JPEG plugin" )
249260 def test_generate_frames_3s_0p (self ):
250261 """Test with multiple frames, 3 sample/px, 0 planar conf."""
251262 index = get_indexed_datasets ('1.2.840.10008.1.2.4.50' )
@@ -260,9 +271,3 @@ def test_generate_frames_3s_0p(self):
260271 assert 'uint8' == arr .dtype
261272 assert (ds .Rows , ds .Columns , 3 ) == arr .shape
262273 assert [48 , 128 , 128 ] == arr [159 , 290 , :].tolist ()
263-
264- @pytest .mark .skip ()
265- def test_generate_frames_3s_1p (self ):
266- """Test 3 sample/px, 1 planar conf."""
267- # No data
268- pass
0 commit comments