예제 #1
0
    def setUp(self):
        """Create a Controller, and Motor objects from dummy configurations """
        unittest.TestCase.setUp(self)
        try:
            from mock import Mock
        except ImportError:
            self.skipTest("mock module is not available")
        pool = FakePool()
        dummy_mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01)
        self.dummy_mot = createPoolMotor(pool, dummy_mot_ctrl,
                                         dummyMotorConf01)
        self.dummy_mot2 = createPoolMotor(pool, dummy_mot_ctrl,
                                          dummyMotorConf02)
        dummy_mot_ctrl.add_element(self.dummy_mot)
        pool.add_element(dummy_mot_ctrl)
        pool.add_element(self.dummy_mot)
        pool.add_element(self.dummy_mot2)

        # {moveable: (position, dial_position,
        #             do_backlash, backlash, instability_time=None)}
        self.items = {self.dummy_mot: (0, 0, False, 0),
                      self.dummy_mot2: (0, 0, False, 0)}
        # Create mock and define its functions
        ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne',
                        'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne',
                        'PreReadAll', 'PreReadOne', 'ReadOne', 'ReadAll',
                        'PreStopAll', 'StopAll', 'PreStopOne', 'StopOne',
                        'PreAbortAll', 'AbortAll', 'PreAbortOne', 'AbortOne']
        self.mock_mot_ctrl = Mock(spec=ctrl_methods)
        self.mock_mot_ctrl.StateOne.return_value = (State.Moving, 'moving')

        dummy_mot_ctrl.ctrl = self.mock_mot_ctrl
        self.motionaction = PoolMotion(self.dummy_mot)
        self.motionaction.add_element(self.dummy_mot)
        self.motionaction.add_element(self.dummy_mot2)
예제 #2
0
 def __init__(self, **kwargs):
     kwargs['elem_type'] = ElementType.Motor
     PoolElement.__init__(self, **kwargs)
     on_change = self.on_change
     self._offset = Offset(self, initial_value=0, listeners=on_change)
     self._sign = Sign(self, initial_value=1, listeners=on_change)
     self._dial_position = DialPosition(self, listeners=on_change)
     self._position = Position(self, listeners=on_change)
     self._backlash = 0
     self._step_per_unit = 1.0
     self._limit_switches = LimitSwitches(self, name="Limit_switches",
                                          initial_value=3 * (False,),
                                          listeners=on_change)
     self._acceleration = None
     self._deceleration = None
     self._velocity = None
     self._base_rate = None
     self._instability_time = None
     self._in_start_move = False
     motion_name = "%s.Motion" % self._name
     self.set_action_cache(PoolMotion(self, motion_name))
예제 #3
0
 def _create_action_cache(self):
     motion_name = "%s.Motion" % self._name
     return PoolMotion(self, motion_name)
예제 #4
0
class PoolMotionTestCase(unittest.TestCase):
    """Unittest of PoolMotion class"""

    def setUp(self):
        """Create a Controller, and Motor objects from dummy configurations """
        unittest.TestCase.setUp(self)
        try:
            from mock import Mock
        except ImportError:
            self.skipTest("mock module is not available")
        pool = FakePool()
        dummy_mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01)
        self.dummy_mot = createPoolMotor(pool, dummy_mot_ctrl,
                                         dummyMotorConf01)
        self.dummy_mot2 = createPoolMotor(pool, dummy_mot_ctrl,
                                          dummyMotorConf02)
        dummy_mot_ctrl.add_element(self.dummy_mot)
        pool.add_element(dummy_mot_ctrl)
        pool.add_element(self.dummy_mot)
        pool.add_element(self.dummy_mot2)

        # {moveable: (position, dial_position,
        #             do_backlash, backlash, instability_time=None)}
        self.items = {self.dummy_mot: (0, 0, False, 0),
                      self.dummy_mot2: (0, 0, False, 0)}
        # Create mock and define its functions
        ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne',
                        'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne',
                        'PreReadAll', 'PreReadOne', 'ReadOne', 'ReadAll',
                        'PreStopAll', 'StopAll', 'PreStopOne', 'StopOne',
                        'PreAbortAll', 'AbortAll', 'PreAbortOne', 'AbortOne']
        self.mock_mot_ctrl = Mock(spec=ctrl_methods)
        self.mock_mot_ctrl.StateOne.return_value = (State.Moving, 'moving')

        dummy_mot_ctrl.ctrl = self.mock_mot_ctrl
        self.motionaction = PoolMotion(self.dummy_mot)
        self.motionaction.add_element(self.dummy_mot)
        self.motionaction.add_element(self.dummy_mot2)

    def stopMotion(self):
        """Method used to change the controller (mock) state"""
        self.dummy_mot.stop()

    def test_stop(self):
        """Verify motion stop call chain."""
        from mock import call
        args = ()
        kwargs = {'items': self.items}
        # starting action
        self.motionaction.start_action(*args, **kwargs)
        # stopping the motion
        # self.stopMotion()
        args = ()
        kwargs = {'items': self.items}
        self.motionaction.stop_action(*args, **kwargs)

        # verifying that the stop has called all the controller methods chain
        self.mock_mot_ctrl.assert_has_calls([call.PreStopAll(),
                                             call.PreStopOne(1,),
                                             call.StopOne(1,),
                                             call.PreStopOne(2,),
                                             call.StopOne(2,),
                                             call.StopAll()])

    def test_abort(self):
        """Verify motion abort call chain."""
        from mock import call
        args = ()
        kwargs = {'items': self.items}
        # starting action
        self.motionaction.start_action(*args, **kwargs)
        args = ()
        kwargs = {'items': self.items}
        self.motionaction.abort_action(*args, **kwargs)

        # verifying that the abort has called all the controller methods chain
        self.mock_mot_ctrl.assert_has_calls([call.PreAbortAll(),
                                             call.PreAbortOne(1,),
                                             call.AbortOne(1,),
                                             call.PreAbortOne(2,),
                                             call.AbortOne(2,),
                                             call.AbortAll()])

    def tearDown(self):
        self.motionaction = None
        self.mock_mot_ctrl = None
        self.cfg = None
        self.dummy_mot = None
        unittest.TestCase.tearDown(self)