def test_NumericMetricDescriptorContainer(self): dc = descriptorcontainers.NumericMetricDescriptorContainer( nsmapper=self.nsmapper, nodeName='MyDescriptor', handle='123', parentHandle='456', ) self.assertEqual(dc.Resolution, None) self.assertEqual(dc.AveragingPeriod, None)
def test_AbstractMetricStateContainer_Final(self): dc = descriptorcontainers.NumericMetricDescriptorContainer( nsmapper=self.nsmapper, nodeName='MyDescriptor', handle='123', parentHandle='456') sc = statecontainers.NumericMetricStateContainer( nsmapper=self.nsmapper, descriptorContainer=dc, node=None) self.assertEqual(sc.ActivationState, 'On') for value in ('foo', 'bar'): sc.ActivationState = value self.assertEqual(sc.ActivationState, value) node = sc.mkStateNode() self.assertEqual(node.get('ActivationState'), value) self.assertEqual(sc.ActiveDeterminationPeriod, None) for value in (21, 42): sc.ActiveDeterminationPeriod = value self.assertEqual(sc.ActiveDeterminationPeriod, value) node = sc.mkStateNode() self.assertEqual( node.get('ActiveDeterminationPeriod'), containerproperties.DurationConverter.toXML(value)) sc.BodySite = [pmtypes.CodedValue('ABC')] sc.PhysicalConnector = pmtypes.PhysicalConnectorInfo( [pmtypes.LocalizedText('ABC')], 1) # test creation from node node = sc.mkStateNode() sc2 = statecontainers.NumericMetricStateContainer( nsmapper=self.nsmapper, descriptorContainer=dc, node=node) self.assertEqual(sc.ActivationState, sc2.ActivationState) self.assertEqual(sc.ActiveDeterminationPeriod, sc2.ActiveDeterminationPeriod) self.assertEqual(sc.BodySite, sc2.BodySite) self.assertEqual(sc.PhysicalConnector, sc2.PhysicalConnector) self._verifyAbstractStateContainerDataEqual(sc, sc2) # test update from Node sc.ActivationState = 'something else' sc.ActiveDeterminationPeriod += 1 sc.BodySite = [pmtypes.CodedValue('DEF')] sc.PhysicalConnector = pmtypes.PhysicalConnectorInfo( [pmtypes.LocalizedText('DEF')], 2) sc.incrementState() node = sc.mkStateNode() sc2.updateFromNode(node) self.assertEqual(sc.ActivationState, sc2.ActivationState) self.assertEqual(sc.BodySite, sc2.BodySite) self.assertEqual(sc.PhysicalConnector, sc2.PhysicalConnector) self.assertEqual(sc.ActiveDeterminationPeriod, sc2.ActiveDeterminationPeriod) self._verifyAbstractStateContainerDataEqual(sc, sc2)
def test_NumericMetricStateContainer(self): dc = descriptorcontainers.NumericMetricDescriptorContainer( nsmapper=self.nsmapper, nodeName='MyDescriptor', handle='123', parentHandle='456') sc = statecontainers.NumericMetricStateContainer( nsmapper=self.nsmapper, descriptorContainer=dc, node=None) sc.mkMetricValue() self.assertTrue(isinstance(sc.metricValue, pmtypes.NumericMetricValue)) sc.metricValue.Value = 42.21 sc.metricValue.StartTime = 1234567.21 sc.metricValue.StopTime = sc.metricValue.StartTime + 10 sc.metricValue.DeterminationTime = sc.metricValue.StartTime + 20 sc.metricValue.Validity = 'Vld' sc.ActiveAveragingPeriod = 42 sc.PhysiologicalRange = [ pmtypes.Range(1, 2, 3, 4, 5), pmtypes.Range(10, 20, 30, 40, 50) ] node = sc.mkStateNode() #test creation from node sc2 = statecontainers.NumericMetricStateContainer( nsmapper=self.nsmapper, descriptorContainer=dc, node=node) # verify also that mkStateNode on receiving sc does not change anything for dummy in range(1): self.assertEqual(sc.metricValue.Value, sc2.metricValue.Value) self.assertEqual(sc.metricValue.StartTime, sc2.metricValue.StartTime) self.assertEqual(sc.metricValue.StopTime, sc2.metricValue.StopTime) self.assertEqual(sc.metricValue.DeterminationTime, sc2.metricValue.DeterminationTime) self.assertEqual(sc.metricValue.Validity, sc2.metricValue.Validity) self.assertEqual(sc.ActiveAveragingPeriod, sc2.ActiveAveragingPeriod) self.assertEqual(sc.PhysiologicalRange, sc2.PhysiologicalRange) self._verifyAbstractStateContainerDataEqual(sc, sc2) sc.mkStateNode() #test update from node sc.metricValue.Value += 1 sc.incrementState() sc.ActiveAveragingPeriod = 24 sc.PhysiologicalRange[1].Lower = 100 node = sc.mkStateNode() sc2.updateFromNode(node) self.assertEqual(sc.metricValue.Value, sc2.metricValue.Value) self.assertEqual(sc.ActiveAveragingPeriod, sc2.ActiveAveragingPeriod) self.assertEqual(sc.PhysiologicalRange, sc2.PhysiologicalRange) self._verifyAbstractStateContainerDataEqual(sc, sc2)