Пример #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 createMotorElement(self, ctrl_obj, name, axis):
     e_cfg = createElemConf(self.pool, axis, name)
     elem_obj = createPoolMotor(self.pool, ctrl_obj, e_cfg)
     ctrl_obj.add_element(elem_obj)
     # MOT elements
     self.mots[name] = elem_obj
     self.pool.add_element(elem_obj)
     return elem_obj
Пример #3
0
 def createMotorElement(self, ctrl_obj, name, axis):
     e_cfg = createElemConf(self.pool, axis, name)
     elem_obj = createPoolMotor(self.pool, ctrl_obj, e_cfg)
     ctrl_obj.add_element(elem_obj)
     # MOT elements
     self.mots[name] = elem_obj
     self.pool.add_element(elem_obj)
     return elem_obj
Пример #4
0
def test_state(monkeypatch, mock_StateOne):
    """Test variants of StateOne return value:
    - state
    - state, status
    - state, status, limit_switches
    """
    pool = FakePool()
    # when SEP19 gets implemented it should be possible to mock directly
    # the imported class
    DummyMotorController = pool.ctrl_manager.getControllerClass(
        "DummyMotorController")
    monkeypatch.setattr(DummyMotorController, "StateOne", mock_StateOne)
    mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01)
    mot = createPoolMotor(pool, mot_ctrl, dummyMotorConf01)
    mot_ctrl.add_element(mot)
    pool.add_element(mot_ctrl)
    pool.add_element(mot)
    assert mot.state == State.On
    assert type(mot.status) == str
    assert mot.limit_switches.value == (False, ) * 3