def add_impl_name(self, primitive, name=b'A '): """Add an Implementation Version Name to the A-ASSOCIATE primitive.""" assert len(name) == 16 item = ImplementationVersionNameNotification() item.implementation_version_name = name primitive.user_information.append(item) return primitive
def test_conversion(self): """ Check converting to PDU item works correctly """ primitive = ImplementationVersionNameNotification() primitive.implementation_version_name = b'PYNETDICOM_090' item = primitive.from_primitive() assert item.encode() == ( b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f' b'\x30\x39\x30')
def test_assignment_and_exceptions(self): """Check incorrect setting for implementation_version_name raises""" primitive = ImplementationVersionNameNotification() ## Check assignment reference_name = "PYNETDICOM_090" ## Check maximum length allowable primitive.implementation_version_name = "1234567890ABCDEF" assert primitive.implementation_version_name == "1234567890ABCDEF" # bytes primitive.implementation_version_name = "PYNETDICOM_090" assert primitive.implementation_version_name == reference_name # str primitive.implementation_version_name = "PYNETDICOM_090" assert primitive.implementation_version_name == reference_name primitive.implementation_version_name = "P" assert primitive.implementation_version_name == "P" ## Check exceptions primitive = ImplementationVersionNameNotification() # No value set with pytest.raises(ValueError): item = primitive.from_primitive() # Non UID, bytes or str with pytest.raises(TypeError): primitive.implementation_version_name = 45.2 with pytest.raises(TypeError): primitive.implementation_version_name = 100 bad = "ABCD1234ABCD12345" msg = ( f"Invalid 'Implementation Version Name' value '{bad}' - must not " "exceed 16 characters" ) with pytest.raises(ValueError, match=msg): primitive.implementation_version_name = bad primitive.implementation_version_name = "" assert primitive.implementation_version_name == "" primitive.implementation_version_name = None assert primitive.implementation_version_name is None
def test_assignment_and_exceptions(self): """Check incorrect setting for implementation_version_name raises""" primitive = ImplementationVersionNameNotification() ## Check assignment reference_name = b'PYNETDICOM_090' ## Check maximum length allowable primitive.implementation_version_name = b'1234567890ABCDEF' assert primitive.implementation_version_name == b'1234567890ABCDEF' # bytes primitive.implementation_version_name = b'PYNETDICOM_090' assert primitive.implementation_version_name == reference_name # str primitive.implementation_version_name = 'PYNETDICOM_090' assert primitive.implementation_version_name == reference_name ## Check exceptions primitive = ImplementationVersionNameNotification() # No value set with pytest.raises(ValueError): item = primitive.from_primitive() # Non UID, bytes or str with pytest.raises(TypeError): primitive.implementation_version_name = 45.2 with pytest.raises(TypeError): primitive.implementation_version_name = 100 with pytest.raises(ValueError): primitive.implementation_version_name = 'ABCD1234ABCD12345'
def test_conversion(self): """ Check conversion to a PDU produces the correct output """ assoc = A_ASSOCIATE() assoc.application_context_name = "1.2.840.10008.3.1.1.1" assoc.calling_ae_title = 'ECHOSCU' assoc.called_ae_title = 'ANY-SCP' assoc.maximum_length_received = 16382 assoc.implementation_class_uid = '1.2.826.0.1.3680043.9.3811.0.9.0' imp_ver_name = ImplementationVersionNameNotification() imp_ver_name.implementation_version_name = 'PYNETDICOM_090' assoc.user_information.append(imp_ver_name) pc = PresentationContext() pc.context_id = 1 pc.abstract_syntax = '1.2.840.10008.1.1' pc.transfer_syntax = ['1.2.840.10008.1.2'] assoc.presentation_context_definition_list = [pc] pdu = A_ASSOCIATE_RQ() pdu.from_primitive(assoc) data = pdu.encode() assert data == ( b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43" b"\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43" b"\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00" b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e" b"\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e" b"\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31" b"\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31" b"\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30" b"\x38\x2e\x31\x2e\x32\x50\x00\x00\x3e\x51\x00\x00\x04\x00\x00\x3f" b"\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31" b"\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e" b"\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49" b"\x43\x4f\x4d\x5f\x30\x39\x30" )
def test_string(self): """Check the string output.""" primitive = ImplementationVersionNameNotification() primitive.implementation_version_name = b'PYNETDICOM3_090' assert 'PYNETDICOM3_090' in primitive.__str__()