Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def test_LimitAlertConditionStateContainer_Final(self):
        def verifyEqual(origin, copied):
            self.assertEqual(copied.Limits, origin.Limits)
            self.assertEqual(copied.MonitoredAlertLimits,
                             origin.MonitoredAlertLimits)
            self.assertEqual(copied.AutoLimitActivationState,
                             origin.AutoLimitActivationState)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

        sc = statecontainers.LimitAlertConditionStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)
        self.assertEqual(sc.MonitoredAlertLimits,
                         pmtypes.AlertConditionMonitoredLimits.ALL_OFF)
        self.assertEqual(sc.AutoLimitActivationState, None)

        # test creation from node
        node = sc.mkStateNode()
        sc2 = statecontainers.LimitAlertConditionStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)

        # test update from node
        sc.Limits = pmtypes.Range(lower=5,
                                  upper=9,
                                  stepWidth=0.1,
                                  relativeAccuracy=0.01,
                                  absoluteAccuracy=0.001)
        sc.Rank = 3
        sc.DeterminationTime = 1234567
        sc.Presence = True
        sc.incrementState()
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        verifyEqual(sc, sc2)
    def test_LimitAlertConditionDescriptorContainer(self):
        dc = descriptorcontainers.LimitAlertConditionDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName=namespaces.domTag('MyDescriptor'),
            handle='123',
            parentHandle='456',
        )
        # create copy with default values
        node = dc.mkNode()
        dc2 = descriptorcontainers.LimitAlertConditionDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self._cmp_LimitAlertConditionDescriptorContainer(dc, dc2)

        # set values, test updateFromNode
        dc.MaxLimits = pmtypes.Range(lower=0,
                                     upper=100,
                                     stepWidth=1,
                                     relativeAccuracy=0.1,
                                     absoluteAccuracy=0.2)
        dc.AutoLimitSupported = True
        node = dc.mkNode()
        dc2.updateDescrFromNode(node)
        self._cmp_LimitAlertConditionDescriptorContainer(dc, dc2)

        # create copy with values set
        dc2 = descriptorcontainers.LimitAlertConditionDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self._cmp_LimitAlertConditionDescriptorContainer(dc, dc2)
Exemplo n.º 4
0
    def test_SetValueOperationStateContainer(self):
        sc = statecontainers.SetValueOperationStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)

        self.assertEqual(sc.AllowedRange, [])
        sc.AllowedRange.append(pmtypes.Range(1, 2, 3, 4, 5))
        node = sc.mkStateNode()
        sc2 = statecontainers.SetValueOperationStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        self.assertEqual(sc.AllowedRange, sc2.AllowedRange)

        sc.AllowedRange[0].Lower = 42
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        self.assertEqual(sc.AllowedRange, sc2.AllowedRange)

        sc.AllowedRange.append(pmtypes.Range(3, 4, 5, 6, 7))
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        self.assertEqual(len(sc2.AllowedRange), 2)
        self.assertEqual(sc.AllowedRange, sc2.AllowedRange)