Skip to content

Commit

Permalink
added tests for metricprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
deichmab-draeger committed Oct 4, 2023
1 parent df879ae commit 450c8d8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/sdc11073/roles/metricprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def _set_numeric_value(self, params: ExecuteParameters) -> ExecuteResult:
def _set_string(self, params: ExecuteParameters) -> ExecuteResult:
"""Set a string value (ExecuteHandler)."""
value = params.operation_request.argument
pm_types = self._mdib.data_model.pm_types
self._logger.info('set value %s from %s to %s',
params.operation_instance.operation_target_handle,
params.operation_instance.current_value, value)
Expand All @@ -159,12 +158,5 @@ def _set_string(self, params: ExecuteParameters) -> ExecuteResult:
if state.MetricValue is None:
state.mk_metric_value()
state.MetricValue.Value = value
# SF1823: For Metrics with the MetricCategory = Set|Preset that are being modified as a result of a
# SetValue or SetString operation a Metric Provider shall set the MetricQuality / Validity = Vld.
metric_descriptor_container = self._mdib.descriptions.handle.get_one(
params.operation_instance.operation_target_handle)
if metric_descriptor_container.MetricCategory in (pm_types.MetricCategory.SETTING,
pm_types.MetricCategory.PRESETTING):
state.MetricValue.Validity = pm_types.MeasurementValidity.VALID
return ExecuteResult(params.operation_instance.operation_target_handle,
self._mdib.data_model.msg_types.InvocationState.FINISHED)
24 changes: 24 additions & 0 deletions tests/70041_MDIB_Final.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@
<pm:ConceptDescription Lang="en-US">An operation to set the time zone of a clock.</pm:ConceptDescription>
</pm:Type>
</pm:Operation>
<pm:Operation xsi:type="pm:SetStringOperationDescriptor" Handle="0x34F06409.op" DescriptorVersion="2" SafetyClassification="MedA" OperationTarget="0x34F06409" MaxTimeToFinish="PT00H00M02S" Retriggerable="false">
<ext:Extension>
<msg:Retrievability>
<msg:By Method="Get"/>
<msg:By Method="Ep"/>
</msg:Retrievability>
</ext:Extension>
<pm:Type Code="0815">
<pm:ConceptDescription Lang="en-US">An operation to set the patient category.</pm:ConceptDescription>
</pm:Type>
</pm:Operation>

<pm:Operation xsi:type="pm:SetValueOperationDescriptor" Handle="0x34F04383.op" DescriptorVersion="2" SafetyClassification="MedA" OperationTarget="0x34F04383" MaxTimeToFinish="PT00H00M02S" Retriggerable="false">
<ext:Extension>
<msg:Retrievability>
<msg:By Method="Get"/>
<msg:By Method="Ep"/>
</msg:Retrievability>
</ext:Extension>
<pm:Type Code="0815-1">
<pm:ConceptDescription Lang="en-US">An operation to set a numeric value.</pm:ConceptDescription>
</pm:Type>
</pm:Operation>

</pm:Sco>
<pm:MetaData>
<pm:Udi>
Expand Down
53 changes: 52 additions & 1 deletion tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,55 @@ def test_set_operating_mode(self):
operation.set_operating_mode(op_mode)
time.sleep(1)
operation_state = client_mdib.states.descriptor_handle.get_one(operation_handle)
self.assertEqual(operation_state.OperatingMode, op_mode)
self.assertEqual(operation_state.OperatingMode, op_mode)

def test_set_string_value(self):
"""Verify that metricprovider instantiated an operation for SetString call.
OperationTarget of operation 0815 is an EnumStringMetricState.
"""
set_service = self.sdc_client.client('Set')
client_mdib = ConsumerMdib(self.sdc_client)
client_mdib.init_mdib()
coding = pm_types.Coding('0815')
my_operation_descriptor = self.sdc_device.mdib.descriptions.coding.get_one(coding, allow_none=True)

operation_handle = my_operation_descriptor.Handle
for value in ('ADULT', 'PEDIATRIC'):
self._logger.info('string value = %s', value)
future = set_service.set_string(operation_handle=operation_handle, requested_string=value)
result = future.result(timeout=SET_TIMEOUT)
state = result.InvocationInfo.InvocationState
self.assertEqual(state, msg_types.InvocationState.FINISHED)
self.assertIsNone(result.InvocationInfo.InvocationError)
self.assertEqual(0, len(result.InvocationInfo.InvocationErrorMessage))

# verify that the corresponding state has been updated
state = client_mdib.states.descriptor_handle.get_one(my_operation_descriptor.OperationTarget)
self.assertEqual(state.MetricValue.Value, value)

def test_set_metric_value(self):
"""Verify that metricprovider instantiated an operation for SetNumericValue call.
OperationTarget of operation 0815-1 is a NumericMetricState.
"""
set_service = self.sdc_client.client('Set')
client_mdib = ConsumerMdib(self.sdc_client)
client_mdib.init_mdib()
coding = pm_types.Coding('0815-1')
my_operation_descriptor = self.sdc_device.mdib.descriptions.coding.get_one(coding, allow_none=True)

operation_handle = my_operation_descriptor.Handle
for value in (Decimal(1), Decimal(42)):
self._logger.info('metric value = %s', value)
future = set_service.set_numeric_value(operation_handle=operation_handle,
requested_numeric_value=value)
result = future.result(timeout=SET_TIMEOUT)
state = result.InvocationInfo.InvocationState
self.assertEqual(state, msg_types.InvocationState.FINISHED)
self.assertIsNone(result.InvocationInfo.InvocationError)
self.assertEqual(0, len(result.InvocationInfo.InvocationErrorMessage))

# verify that the corresponding state has been updated
state = client_mdib.states.descriptor_handle.get_one(my_operation_descriptor.OperationTarget)
self.assertEqual(state.MetricValue.Value, value)

0 comments on commit 450c8d8

Please sign in to comment.