Esempio n. 1
0
    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)
Esempio n. 2
0
    def test_AbstractDeviceComponentStateContainer_Final(self):
        def verifyEqual(origin, copied):
            self.assertEqual(copied.ActivationState, origin.ActivationState)
            self.assertEqual(copied.OperatingHours, origin.OperatingHours)
            self.assertEqual(copied.OperatingCycles, origin.OperatingCycles)
            self.assertEqual(copied.PhysicalConnector,
                             origin.PhysicalConnector)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

        sc = statecontainers.AbstractDeviceComponentStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)
        self.assertEqual(sc.ActivationState, None)
        self.assertEqual(sc.OperatingHours, None)
        self.assertEqual(sc.OperatingCycles, None)
        self.assertEqual(sc.PhysicalConnector, None)

        sc.ActivationState = 'On'
        sc.OperatingHours = 2.3
        sc.OperatingHours = 4
        sc.PhysicalConnector = pmtypes.PhysicalConnectorInfo(
            [pmtypes.LocalizedText('ABC')], 1)

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

        sc.ActivationState = 'Off'
        sc.OperatingHours += 1
        sc.OperatingHours += 1
        sc.PhysicalConnector = pmtypes.PhysicalConnectorInfo(
            [pmtypes.LocalizedText('DEF')], 2)
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        verifyEqual(sc, sc2)