def test_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = C_ECHO() # MessageID with pytest.raises(TypeError): primitive.MessageID = 'halp' with pytest.raises(TypeError): primitive.MessageID = 1.111 with pytest.raises(ValueError): primitive.MessageID = 65536 with pytest.raises(ValueError): primitive.MessageID = -1 # MessageIDBeingRespondedTo with pytest.raises(TypeError): primitive.MessageIDBeingRespondedTo = 'halp' with pytest.raises(TypeError): primitive.MessageIDBeingRespondedTo = 1.111 with pytest.raises(ValueError): primitive.MessageIDBeingRespondedTo = 65536 with pytest.raises(ValueError): primitive.MessageIDBeingRespondedTo = -1 # AffectedSOPClassUID with pytest.raises(TypeError): primitive.AffectedSOPClassUID = 45.2 with pytest.raises(TypeError): primitive.AffectedSOPClassUID = 100 # Status with pytest.raises(TypeError): primitive.Status = 19.4
def test_assignment(self): """ Check assignment works correctly """ primitive = C_ECHO() primitive.MessageID = 11 assert primitive.MessageID == 11 primitive.MessageIDBeingRespondedTo = 13 assert primitive.MessageIDBeingRespondedTo == 13 # AffectedSOPClassUID primitive.AffectedSOPClassUID = '1.1.1' assert primitive.AffectedSOPClassUID == UID('1.1.1') assert isinstance(primitive.AffectedSOPClassUID, UID) primitive.AffectedSOPClassUID = UID('1.1.2') assert primitive.AffectedSOPClassUID == UID('1.1.2') assert isinstance(primitive.AffectedSOPClassUID, UID) primitive.AffectedSOPClassUID = b'1.1.3' assert primitive.AffectedSOPClassUID == UID('1.1.3') assert isinstance(primitive.AffectedSOPClassUID, UID) # Known status primitive.Status = 0x0000 assert primitive.Status == 0x0000 # Unknown status primitive.Status = 0x9999 assert primitive.Status == 0x9999 primitive.Status = 0xEE01 assert primitive.Status == 0xEE01
def test_uid_exceptions_false(self): """Test ValueError raised with ENFORCE_UID_CONFORMANCE = False.""" primitive = C_ECHO() _config.ENFORCE_UID_CONFORMANCE = False primitive.AffectedSOPClassUID = 'abc' assert primitive.AffectedSOPClassUID == 'abc' # Can't have more than 64 characters with pytest.raises(ValueError): primitive.AffectedSOPClassUID = 'abc' * 22
def test_uid_exceptions_true(self): """Test ValueError raised with ENFORCE_UID_CONFORMANCE = True.""" primitive = C_ECHO() _config.ENFORCE_UID_CONFORMANCE = True with pytest.raises(ValueError): primitive.AffectedSOPClassUID = 'abc'
def test_is_valid_request(self): """Test C_ECHO.is_valid_request""" primitive = C_ECHO() assert not primitive.is_valid_request primitive.MessageID = 1 assert not primitive.is_valid_request primitive.AffectedSOPClassUID = '1.2' assert primitive.is_valid_request
def test_callback_send_c_echo(self): """Check callback for sending DIMSE C-ECHO messages.""" # C-ECHO-RQ primitive = C_ECHO() primitive.MessageID = 1 primitive.AffectedSOPClassUID = '1.1.1' self.dimse.send_msg(primitive, 1) # C-ECHO-RSP primitive = C_ECHO() primitive.MessageIDBeingRespondedTo = 1 primitive.Status = 0x0000 self.dimse.send_msg(primitive, 1)
def test_conversion_rq(self): """ Check conversion to a -RQ PDU produces the correct output """ primitive = C_ECHO() primitive.MessageID = 7 primitive.AffectedSOPClassUID = '1.2.840.10008.1.1' dimse_msg = C_ECHO_RQ() dimse_msg.primitive_to_message(primitive) pdvs = [] for fragment in dimse_msg.encode_msg(1, 16382): pdvs.append(fragment) cs_pdv = pdvs[0].presentation_data_value_list[0][1] assert cs_pdv == c_echo_rq_cmd