def test_conversion(self): """ Check converting to PDU item works correctly """ primitive = SOPClassCommonExtendedNegotiation() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.4' primitive.service_class_uid = b'1.2.840.10008.4.2' primitive.related_general_sop_class_identification = [ '1.2.840.10008.5.1.4.1.1.88.22' ] item = primitive.from_primitive() assert item.encode() == ( b'\x57\x00\x00\x4f\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30' b'\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x34\x00' b'\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x34' b'\x2e\x32\x00\x1f\x00\x1d\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30' b'\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x38\x38' b'\x2e\x32\x32')
def test_assignment_and_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = SOPClassCommonExtendedNegotiation() ## Check assignment # SOP Class UID reference_uid = UID('1.2.840.10008.5.1.4.1.1.2') primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' assert primitive.sop_class_uid == reference_uid primitive.sop_class_uid = 'abc' assert primitive.sop_class_uid == 'abc' primitive.sop_class_uid = '1.2.840.10008.5.1.4.1.1.2' assert primitive.sop_class_uid == reference_uid primitive.sop_class_uid = UID('1.2.840.10008.5.1.4.1.1.2') assert primitive.sop_class_uid == reference_uid # Service Class UID primitive.service_class_uid = b'1.2.840.10008.5.1.4.1.1.2' assert primitive.service_class_uid == reference_uid primitive.service_class_uid = 'abc' assert primitive.service_class_uid == 'abc' primitive.service_class_uid = '1.2.840.10008.5.1.4.1.1.2' assert primitive.service_class_uid == reference_uid primitive.service_class_uid = UID('1.2.840.10008.5.1.4.1.1.2') assert primitive.service_class_uid == reference_uid # Related General SOP Class Identification ref_list = [ UID('1.2.840.10008.5.1.4.1.1.2'), UID('1.2.840.10008.5.1.4.1.1.3'), UID('1.2.840.10008.5.1.4.1.1.4') ] uid_list = [] uid_list.append(b'1.2.840.10008.5.1.4.1.1.2') uid_list.append('1.2.840.10008.5.1.4.1.1.3') uid_list.append(UID('1.2.840.10008.5.1.4.1.1.4')) primitive.related_general_sop_class_identification = uid_list assert primitive.related_general_sop_class_identification == ref_list primitive.related_general_sop_class_identification = ['abc'] assert primitive.related_general_sop_class_identification == ['abc'] with pytest.raises(TypeError): primitive.related_general_sop_class_identification = 'test' ## Check exceptions # SOP Class UID with pytest.raises(TypeError): primitive.sop_class_uid = 10 with pytest.raises(TypeError): primitive.sop_class_uid = 45.2 # Service Class UID with pytest.raises(TypeError): primitive.service_class_uid = 10 with pytest.raises(TypeError): primitive.service_class_uid = 45.2 # Related General SOP Class Identification with pytest.raises(TypeError): primitive.related_general_sop_class_identification = [10] with pytest.raises(TypeError): primitive.related_general_sop_class_identification = [45.2] # No value set primitive = SOPClassCommonExtendedNegotiation() with pytest.raises(ValueError): item = primitive.from_primitive() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' with pytest.raises(ValueError): item = primitive.from_primitive() primitive = SOPClassCommonExtendedNegotiation() primitive.service_class_uid = b'1.2.840.10008.5.1.4.1.1.2' with pytest.raises(ValueError): item = primitive.from_primitive()