def test_conversion(self): """ Check converting to PDU item works correctly """ primitive = SCP_SCU_RoleSelectionNegotiation() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' primitive.scp_role = True primitive.scu_role = False item = primitive.from_primitive() self.assertTrue(item.encode() == b'\x54\x00\x00\x1d\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\x32\x00' \ b'\x01') primitive = SCP_SCU_RoleSelectionNegotiation() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' primitive.scp_role = False primitive.scu_role = False with self.assertRaises(ValueError): primitive.from_primitive()
def test_assignment_and_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = SCP_SCU_RoleSelectionNegotiation() ## 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' self.assertTrue(primitive.sop_class_uid == reference_uid) primitive.sop_class_uid = '1.2.840.10008.5.1.4.1.1.2' self.assertTrue(primitive.sop_class_uid == reference_uid) primitive.sop_class_uid = UID('1.2.840.10008.5.1.4.1.1.2') self.assertTrue(primitive.sop_class_uid == reference_uid) # SCP Role primitive.scp_role = False self.assertTrue(primitive.scp_role == False) # SCU Role primitive.scu_role = True self.assertTrue(primitive.scu_role == True) ## Check exceptions with pytest.raises(TypeError): primitive.sop_class_uid = 10 with pytest.raises(TypeError): primitive.sop_class_uid = 45.2 with pytest.raises(ValueError): primitive.sop_class_uid = 'abc' with pytest.raises(TypeError): primitive.scp_role = 1 with pytest.raises(TypeError): primitive.scp_role = 'abc' with pytest.raises(TypeError): primitive.scu_role = 1 with pytest.raises(TypeError): primitive.scu_role = 'abc' # No value set primitive = SCP_SCU_RoleSelectionNegotiation() 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.scp_role = False with pytest.raises(ValueError): item = primitive.from_primitive() primitive = SCP_SCU_RoleSelectionNegotiation() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' primitive.scu_role = True item = primitive.from_primitive() assert item.scu_role assert not item.scp_role primitive = SCP_SCU_RoleSelectionNegotiation() primitive.scp_role = True primitive.scu_role = True with pytest.raises(ValueError): item = primitive.from_primitive()