def test_unsupported_syntax_raises(self):
     """Test get_overlay_array raises if unsupported Transfer Syntax."""
     ds = dcmread(EXPL_1_1_1F)
     ds.file_meta.TransferSyntaxUID = '1.2.840.10008.1.2.4.50'
     with pytest.raises(NotImplementedError,
                        match=r' the transfer syntax is not supported'):
         get_overlay_array(ds, 0x6000)
 def test_no_overlay_data_raises(self):
     """Test get_overlay_array raises if dataset has no OverlayData."""
     ds = dcmread(EXPL_1_1_1F)
     del ds[0x6000, 0x3000]
     assert (0x6000, 0x3000) not in ds
     with pytest.raises(AttributeError, match=r' dataset: OverlayData'):
         get_overlay_array(ds, 0x6000)
 def test_missing_padding_warns(self):
     """A warning shall be issued if the padding for odd data is missing."""
     ds = dcmread(EXPL_1_1_1F)
     # Edit shape
     ds[0x6000, 0x0010].value = 15  # OverlayRows
     ds[0x6000, 0x0011].value = 14  # OverlayColumns
     ds[0x6000, 0x3000].value = ds[0x6000, 0x3000].value[:27]  # 15 * 14 / 8
     msg = r"The overlay data length is odd and misses a padding byte."
     with pytest.warns(UserWarning, match=msg):
         get_overlay_array(ds, 0x6000)
 def test_bad_length_raises(self):
     """Test bad pixel data length raises exception."""
     ds = dcmread(EXPL_1_1_1F)
     # Too short
     ds[0x6000, 0x3000].value = ds[0x6000, 0x3000][:-1]
     msg = (
         r"The length of the overlay data in the dataset \(29281 bytes\) "
         r"doesn't match the expected length \(29282 bytes\). "
         r"The dataset may be corrupted or there may be an issue "
         r"with the overlay data handler.")
     with pytest.raises(ValueError, match=msg):
         get_overlay_array(ds, 0x6000)
 def test_excess_padding(self):
     """A warning shall be issued excess padding present."""
     ds = dcmread(EXPL_1_1_1F)
     # Edit shape
     ds[0x6000, 0x0010].value = 15  # OverlayRows
     ds[0x6000, 0x0011].value = 14  # OverlayColumns
     overlay_data = ds[0x6000, 0x3000].value[:27] + b'\x00\x00\x00'
     ds[0x6000, 0x3000].value = overlay_data
     msg = (
         r"overlay data in the dataset \(30 bytes\) indicates it contains "
         r"excess padding. 3 bytes will be removed")
     with pytest.warns(UserWarning, match=msg):
         get_overlay_array(ds, 0x6000)
Ejemplo n.º 6
0
 def test_old_import(self):
     """Test that can import using the old path."""
     from pydicom.overlay_data_handlers import numpy_handler as np_old
     ds = dcmread(EXPL_1_1_1F)
     arr = np_old.get_overlay_array(ds, 0x6000)
     assert 0 == arr[0, 0]