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 fragments = generate_pixel_data_fragment(fp) assert next(fragments) == b'\x01\x00\x00\x00' pytest.raises(StopIteration, next, fragments)
def test_not_little_endian(self): """Test reading big endian raises exception""" bytestream = b'\xFE\xFF\x00\xE0' \ b'\x04\x00\x00\x00' \ b'\x01\x00\x00\x00' fp = DicomBytesIO(bytestream) fp.is_little_endian = False fragments = generate_pixel_data_fragment(fp) assert_raises_regex(ValueError, "'fp.is_little_endian' must be True", next, fragments) pytest.raises(StopIteration, next, fragments)
def test_not_little_endian(self): """Test reading big endian raises exception""" bytestream = b'\xFE\xFF\x00\xE0' \ b'\x04\x00\x00\x00' \ b'\x01\x00\x00\x00' fp = DicomBytesIO(bytestream) fp.is_little_endian = False fragments = generate_pixel_data_fragment(fp) with pytest.raises(ValueError, match="'fp.is_little_endian' must be True"): next(fragments) pytest.raises(StopIteration, next, fragments)
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 fragments = generate_pixel_data_fragment(fp) assert_raises_regex( ValueError, "Undefined item length at offset 4 when " "parsing the encapsulated pixel data " "fragments.", next, fragments) pytest.raises(StopIteration, next, fragments)
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 fragments = generate_pixel_data_fragment(fp) assert next(fragments) == b'\x01\x00\x00\x00' assert next(fragments) == b'\x01\x02\x03\x04\x05\x06' pytest.raises(StopIteration, next, fragments)
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 fragments = generate_pixel_data_fragment(fp) with pytest.raises(ValueError, match="Undefined item length at offset 4 when " "parsing the encapsulated pixel data " "fragments."): next(fragments) pytest.raises(StopIteration, next, fragments)
def test_item_sequence_delimiter(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 fragments = generate_pixel_data_fragment(fp) assert next(fragments) == b'\x01\x00\x00\x00' pytest.raises(StopIteration, next, fragments)
def test_item_bad_tag(self): """Test exception raised if item has unexpected tag""" bytestream = b'\xFE\xFF\x00\xE0' \ b'\x04\x00\x00\x00' \ b'\x01\x00\x00\x00' \ b'\x10\x00\x10\x00' \ 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 fragments = generate_pixel_data_fragment(fp) assert next(fragments) == b'\x01\x00\x00\x00' assert_raises_regex( ValueError, "Unexpected tag '\(0010, 0010\)' at offset 12 " "when parsing the encapsulated pixel data " "fragment items.", next, fragments) pytest.raises(StopIteration, next, fragments)
def test_item_bad_tag(self): """Test exception raised if item has unexpected tag""" bytestream = b'\xFE\xFF\x00\xE0' \ b'\x04\x00\x00\x00' \ b'\x01\x00\x00\x00' \ b'\x10\x00\x10\x00' \ 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 fragments = generate_pixel_data_fragment(fp) assert next(fragments) == b'\x01\x00\x00\x00' with pytest.raises(ValueError, match="Unexpected tag '\(0010, 0010\)' at offset " "12 when parsing the encapsulated pixel data " "fragment items."): next(fragments) pytest.raises(StopIteration, next, fragments)