Ejemplo n.º 1
0
def test_timeout(qtbot, taurus_test_ds):
    """Check that the timeout property works"""
    w = TaurusCommandButton(command='Sleep')
    qtbot.addWidget(w)

    try:
        w.setModel(taurus_test_ds)

        # set the parameter for the sleep command to 0.2 seconds
        w.setParameters([.2])

        # Create a callback to check the result of the execution
        def _check_result(res):
            return res == .2

        # Check that the button emits commandExecuted when timeout > exec time
        w.setTimeout(10)
        assert w.getTimeout() == 10
        with qtbot.waitSignal(w.commandExecuted,
                              check_params_cb=_check_result):
            qtbot.mouseClick(w, Qt.Qt.LeftButton)

        # Check that, if timeout < exec time, commandExecuted is NOT emited
        # and CommunicationFailed is raised
        w.setTimeout(.1)
        assert w.getTimeout() == .1
        with pytest.raises(CommunicationFailed):
            with qtbot.assertNotEmitted(w.commandExecuted):
                # call _onClicked instead of emulating a click to bypass
                # the @ProtectTaurusMessageBox protection of onClicked()
                w._onClicked()
    finally:
        # just in case this helps avoiding problems at exit
        w.setModel(None)
Ejemplo n.º 2
0
 def populateButtons(self):
     """
     Create taurus commandbuttons for everything in modelcommand
     """
     for modelcommand in self._modelcommands:
         button = TaurusCommandButton(self.frame)
         button.setCommand(modelcommand['command'])
         if 'model' in modelcommand:
             button.setModel(modelcommand['model'])
         else:
             button.setUseParentModel(True)
         if 'customtext' in modelcommand:
             button.setCustomText(modelcommand['customtext'])
         if 'dangermessage' in modelcommand:
             button.setDangerMessage(modelcommand['dangermessage'])
         if 'parameters' in modelcommand:
             button.setParameters(modelcommand['parameters'])
         if 'timeout' in modelcommand:
             button.setTimeout(modelcommand['timeout'])
         self.connect(button,
                      Qt.SIGNAL('commandExecuted'),
                      self.onCommandExectued)
         # Make button expand vertically
         button.setSizePolicy(QtGui.QSizePolicy.Minimum,
                              QtGui.QSizePolicy.Expanding)
         self.frame.layout().addWidget(button)
         self._buttons.append(button)