Esempio n. 1
0
 def test_item_undefined_length(self):
     """Test exception raised if item length undefined."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\xFF\xFF\xFF\xFF' \
                  b'\x00\x00\x00\x01'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     with pytest.raises(ValueError,
                        match="Encapsulated data fragment had Undefined "
                              "Length at data position 0x4"):
         read_item(fp)
Esempio n. 2
0
 def test_item_undefined_length(self):
     """Test exception raised if item length undefined."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\xFF\xFF\xFF\xFF' \
                  b'\x00\x00\x00\x01'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     with pytest.raises(ValueError,
                        match="Encapsulated data fragment had Undefined "
                        "Length at data position 0x4"):
         read_item(fp)
Esempio n. 3
0
 def test_multi_fragments_no_delimiter(self):
     """Test multi fragments are returned OK"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x06\x00\x00\x00' \
                  b'\x01\x02\x03\x04\x05\x06'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) == b'\x01\x02\x03\x04\x05\x06'
Esempio n. 4
0
 def test_multi_fragments_no_delimiter(self):
     """Test multi fragments are returned OK"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x06\x00\x00\x00' \
                  b'\x01\x02\x03\x04\x05\x06'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) == b'\x01\x02\x03\x04\x05\x06'
Esempio n. 5
0
 def test_item_sequence_delimiter_zero_length(self):
     """Test that the fragments are returned if seq delimiter hit."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\xDD\xE0' \
                  b'\x00\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x02\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) is None
     assert read_item(fp) == b'\x02\x00\x00\x00'
Esempio n. 6
0
 def test_item_sequence_delimiter(self):
     """Test non-zero length seq delimiter reads correctly."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\xDD\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x02\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) is None
     assert read_item(fp) == b'\x02\x00\x00\x00'
Esempio n. 7
0
 def test_item_sequence_delimiter_zero_length(self):
     """Test that the fragments are returned if seq delimiter hit."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\xDD\xE0' \
                  b'\x00\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x02\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) is None
     assert read_item(fp) == b'\x02\x00\x00\x00'
Esempio n. 8
0
 def test_item_sequence_delimiter(self):
     """Test non-zero length seq delimiter reads correctly."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\xDD\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x02\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) is None
     assert read_item(fp) == b'\x02\x00\x00\x00'
Esempio n. 9
0
 def test_single_fragment_no_delimiter(self):
     """Test single fragment is returned OK"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
Esempio n. 10
0
 def test_item_bad_tag(self):
     """Test item is read if it has an unexpected tag"""
     # This should raise an exception instead
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\x10\x00\x10\x00' \
                  b'\x04\x00\x00\x00' \
                  b'\xFF\x00\xFF\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x02\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) == b'\xFF\x00\xFF\x00'
     assert read_item(fp) == b'\x02\x00\x00\x00'
Esempio n. 11
0
 def test_single_fragment_no_delimiter(self):
     """Test single fragment is returned OK"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
Esempio n. 12
0
 def test_item_bad_tag(self):
     """Test item is read if it has an unexpected tag"""
     # This should raise an exception instead
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\x10\x00\x10\x00' \
                  b'\x04\x00\x00\x00' \
                  b'\xFF\x00\xFF\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x02\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) == b'\xFF\x00\xFF\x00'
     assert read_item(fp) == b'\x02\x00\x00\x00'