Пример #1
0
    def wait_for_process(self,
                         handle=None,
                         timeout=None,
                         on_timeout='continue'):
        """Waits for the process to complete or to reach the given timeout.

        The process to wait for must have been started earlier with
        `Start Process`. If ``handle`` is not given, uses the current
        `active process`.

        ``timeout`` defines the maximum time to wait for the process. It can be
        given in
        [http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format|
        various time formats] supported by Robot Framework, for example, ``42``,
        ``42 s``, or ``1 minute 30 seconds``.

        ``on_timeout`` defines what to do if the timeout occurs. Possible values
        and corresponding actions are explained in the table below. Notice
        that reaching the timeout never fails the test.

        | = Value = |               = Action =               |
        | continue  | The process is left running (default). |
        | terminate | The process is gracefully terminated.  |
        | kill      | The process is forcefully stopped.     |

        See `Terminate Process` keyword for more details how processes are
        terminated and killed.

        If the process ends before the timeout or it is terminated or killed,
        this keyword returns a `result object` containing information about
        the execution. If the process is left running, Python ``None`` is
        returned instead.

        Examples:
        | # Process ends cleanly      |                  |                  |
        | ${result} =                 | Wait For Process | example          |
        | Process Should Be Stopped   | example          |                  |
        | Should Be Equal As Integers | ${result.rc}     | 0                |
        | # Process does not end      |                  |                  |
        | ${result} =                 | Wait For Process | timeout=42 secs  |
        | Process Should Be Running   |                  |                  |
        | Should Be Equal             | ${result}        | ${NONE}          |
        | # Kill non-ending process   |                  |                  |
        | ${result} =                 | Wait For Process | timeout=1min 30s | on_timeout=kill |
        | Process Should Be Stopped   |                  |                  |
        | Should Be Equal As Integers | ${result.rc}     | -9               |

        ``timeout`` and ``on_timeout`` are new in Robot Framework 2.8.2.
        """
        process = self._processes[handle]
        logger.info('Waiting for process to complete.')
        if timeout:
            timeout = timestr_to_secs(timeout)
            if not self._process_is_stopped(process, timeout):
                logger.info('Process did not complete in %s.' %
                            secs_to_timestr(timeout))
                return self._manage_process_timeout(handle, on_timeout.lower())
        return self._wait(process)
Пример #2
0
 def report(self, suite):
     suite.visit(self)
     stats = suite.statistics
     self._stream.write("%s\nRun suite '%s' with %d test%s in %s.\n\n"
                        % ('=' * self._width, suite.name,
                           stats.all.total, plural_or_not(stats.all.total),
                           secs_to_timestr(suite.elapsedtime/1000.0)))
     self._stream.highlight(suite.status + 'ED', suite.status)
     self._stream.write('\n%s\n' % stats.message)
Пример #3
0
 def report(self, suite):
     suite.visit(self)
     stats = suite.statistics
     self._stream.write("%s\nRun suite '%s' with %d test%s in %s.\n\n" %
                        ('=' * self._width, suite.name, stats.all.total,
                         plural_or_not(stats.all.total),
                         secs_to_timestr(suite.elapsedtime / 1000.0)))
     self._stream.highlight(suite.status + 'ED', suite.status)
     self._stream.write('\n%s\n' % stats.message)
Пример #4
0
 def _get_timeout(self, timeout):
     if timeout is None:
         return ""
     try:
         tout = secs_to_timestr(timestr_to_secs(timeout.value))
     except ValueError:
         tout = timeout.value
     if timeout.message:
         tout += " :: " + timeout.message
     return tout
Пример #5
0
 def _get_timeout(self, timeout):
     if timeout is None:
         return ''
     try:
         tout = secs_to_timestr(timestr_to_secs(timeout.value))
     except ValueError:
         tout = timeout.value
     if timeout.message:
         tout += ' :: ' + timeout.message
     return tout
Пример #6
0
    def wait_for_process(self, handle=None, timeout=None, on_timeout='continue'):
        """Waits for the process to complete or to reach the given timeout.

        The process to wait for must have been started earlier with
        `Start Process`. If ``handle`` is not given, uses the current
        `active process`.

        ``timeout`` defines the maximum time to wait for the process. It can be
        given in
        [http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format|
        various time formats] supported by Robot Framework, for example, ``42``,
        ``42 s``, or ``1 minute 30 seconds``.

        ``on_timeout`` defines what to do if the timeout occurs. Possible values
        and corresponding actions are explained in the table below. Notice
        that reaching the timeout never fails the test.

        | = Value = |               = Action =               |
        | continue  | The process is left running (default). |
        | terminate | The process is gracefully terminated.  |
        | kill      | The process is forcefully stopped.     |

        See `Terminate Process` keyword for more details how processes are
        terminated and killed.

        If the process ends before the timeout or it is terminated or killed,
        this keyword returns a `result object` containing information about
        the execution. If the process is left running, Python ``None`` is
        returned instead.

        Examples:
        | # Process ends cleanly      |                  |                  |
        | ${result} =                 | Wait For Process | example          |
        | Process Should Be Stopped   | example          |                  |
        | Should Be Equal As Integers | ${result.rc}     | 0                |
        | # Process does not end      |                  |                  |
        | ${result} =                 | Wait For Process | timeout=42 secs  |
        | Process Should Be Running   |                  |                  |
        | Should Be Equal             | ${result}        | ${NONE}          |
        | # Kill non-ending process   |                  |                  |
        | ${result} =                 | Wait For Process | timeout=1min 30s | on_timeout=kill |
        | Process Should Be Stopped   |                  |                  |
        | Should Be Equal As Integers | ${result.rc}     | -9               |

        ``timeout`` and ``on_timeout`` are new in Robot Framework 2.8.2.
        """
        process = self._processes[handle]
        logger.info('Waiting for process to complete.')
        if timeout:
            timeout = timestr_to_secs(timeout)
            if not self._process_is_stopped(process, timeout):
                logger.info('Process did not complete in %s.'
                            % secs_to_timestr(timeout))
                return self._manage_process_timeout(handle, on_timeout.lower())
        return self._wait(process)
Пример #7
0
 def replace_variables(self, variables):
     try:
         self.string = variables.replace_string(self.string)
         if not self:
             return
         self.secs = timestr_to_secs(self.string)
         self.string = secs_to_timestr(self.secs)
         self.message = variables.replace_string(self.message)
     except (DataError, ValueError) as err:
         self.secs = 0.000001  # to make timeout active
         self.error = (u'Setting %s timeout failed: %s' %
                       (self.type.lower(), err))
Пример #8
0
 def replace_variables(self, variables):
     try:
         self.string = variables.replace_string(self.string)
         if not self:
             return
         self.secs = timestr_to_secs(self.string)
         self.string = secs_to_timestr(self.secs)
         self.message = variables.replace_string(self.message)
     except (DataError, ValueError) as err:
         self.secs = 0.000001  # to make timeout active
         self.error = (u'Setting %s timeout failed: %s'
                       % (self.type.lower(), err))
Пример #9
0
 def _convert_to_compact(self, seconds, millis=True):
     return secs_to_timestr(seconds, compact=True)
Пример #10
0
 def _convert_to_verbose(self, seconds, millis=True):
     return secs_to_timestr(seconds)
Пример #11
0
 def _convert_to_compact(self, seconds, millis=True):
     return secs_to_timestr(seconds, compact=True)
Пример #12
0
 def _convert_to_verbose(self, seconds, millis=True):
     return secs_to_timestr(seconds)