예제 #1
0
 def _run(self, context):
     errors = []
     items, iteration_steps = self._get_items_and_iteration_steps(context)
     for i in iteration_steps:
         values = items[i:i+len(self.vars)]
         exception = self._run_one_round(context, self.vars, values)
         if exception:
             if isinstance(exception, ExitForLoop):
                 if exception.earlier_failures:
                     errors.extend(exception.earlier_failures.get_errors())
                 break
             if isinstance(exception, ContinueForLoop):
                 if exception.earlier_failures:
                     errors.extend(exception.earlier_failures.get_errors())
                 continue
             if isinstance(exception, ExecutionPassed):
                 exception.set_earlier_failures(errors)
                 raise exception
             errors.extend(exception.get_errors())
             if not exception.can_continue(context.in_teardown,
                                           self._templated,
                                           context.dry_run):
                 break
     if errors:
         raise ExecutionFailures(errors)
예제 #2
0
 def _run_loop(self, data, result):
     errors = []
     executed = False
     for values in self._get_values_for_rounds(data):
         executed = True
         try:
             self._run_one_round(data, result, values)
         except BreakLoop as exception:
             if exception.earlier_failures:
                 errors.extend(exception.earlier_failures.get_errors())
             break
         except ContinueLoop as exception:
             if exception.earlier_failures:
                 errors.extend(exception.earlier_failures.get_errors())
             continue
         except ExecutionPassed as exception:
             exception.set_earlier_failures(errors)
             raise exception
         except ExecutionFailed as exception:
             errors.extend(exception.get_errors())
             if not exception.can_continue(self._context,
                                           self._templated):
                 break
     if errors:
         raise ExecutionFailures(errors)
     return executed
    def wait_until(self, *threads):
        """
                        指定一個或多個Thread,
                        等待指定的Thread皆結束工作後,
                        才繼續做接下來的動作。

        Examples:
        | ${thread1} | Run Async | My Keyword 1 | arg1 |
        | Wait Until | ${thread1} |

        Examples:
        | ${thread1} | Run Async | My Keyword 1 | arg1 |
        | ${thread2} | Run Async | My Keyword 2 | arg2 |
        | ${thread3} | Run Async | My Keyword 3 | arg3 |
        | Wait Until | ${thread1} | ${thread2} | ${thread3} |
        """
        for thread in threads:
            thread.join()
            time.sleep(1)

        if _errors:
            raise ExecutionFailures(_errors)

        _errors[:] = []
        self._threads[:] = []
예제 #4
0
class Keywords(object):
    def __init__(self, steps, template=None):
        self._keywords = []
        self._templated = bool(template)
        if self._templated:
            steps = [s.apply_template(template) for s in steps]
        for s in steps:
            self._add_step(s, template)

    def _add_step(self, step, template):
        if step.is_comment():
            return
        if step.is_for_loop():
            keyword = ForLoop(step, template)
        else:
            keyword = Keyword(step.keyword, step.args, step.assign)
        self.add_keyword(keyword)

    def add_keyword(self, keyword):
        self._keywords.append(keyword)

    def run(self, context):
        errors = []
        for kw in self._keywords:
            try:
                kw.run(context)
            except ExecutionFailed, err:
                errors.extend(err.get_errors())
                if not err.can_continue(context.teardown, self._templated,
                                        context.dry_run):
                    break
        if errors:
            raise ExecutionFailures(errors)
예제 #5
0
 def run_steps_parallel(self, steps):
     errors = []
     threads = []
     bucket = Queue()
     namedQueue[current_thread().name] = bucket
     try:
         for step in steps:
             threads.append(MyThread(bucket=bucket, target=self.run_step, args=(step,)))
         map(lambda x: x.start(), threads)
         map(lambda x: x.join(), threads)
         if current_thread().name == 'MainThread':
             root = ParallelLogNode('MainThread')
             post_order(root, root.children, self._context.output)
             root.children = []
             if not bucket.empty():
                 raise bucket.get_nowait()
         else:
             if not bucket.empty():
                 error = bucket.get_nowait()
                 namedQueue[current_thread().parent].put(error)
                 raise error
     except ExecutionPassed as exception:
         exception.set_earlier_failures(errors)
         raise exception
     except ExecutionFailed as exception:
         errors.extend(exception.get_errors())
     if errors:
         raise ExecutionFailures(errors)
예제 #6
0
 def run(self, body):
     errors = []
     for step in body:
         try:
             step.run(self._context, self._run, self._templated)
         except ExecutionPassed as exception:
             exception.set_earlier_failures(errors)
             raise exception
         except ExecutionFailed as exception:
             errors.extend(exception.get_errors())
             self._run = exception.can_continue(self._context,
                                                self._templated)
     if errors:
         raise ExecutionFailures(errors)
예제 #7
0
 def _run(self, context):
     errors = []
     items, iteration_steps = self._get_items_and_iteration_steps(context)
     for i in iteration_steps:
         values = items[i:i + len(self.vars)]
         err = self._run_one_round(context, self.vars, values)
         if err:
             if err.exit_for_loop:
                 break
             errors.extend(err.get_errors())
             if not err.can_continue(context.teardown, self._templated,
                                     context.dry_run):
                 break
     if errors:
         raise ExecutionFailures(errors)
예제 #8
0
 def run(self, context):
     errors = []
     for kw in self._keywords:
         try:
             kw.run(context)
         except ExecutionPassed as exception:
             exception.set_earlier_failures(errors)
             raise exception
         except ExecutionFailed as exception:
             errors.extend(exception.get_errors())
             if not exception.can_continue(
                     context.in_teardown, self._templated, context.dry_run):
                 break
     if errors:
         raise ExecutionFailures(errors)
예제 #9
0
 def run_steps(self, steps):
     errors = []
     for step in steps:
         try:
             self.run_step(step)
         except ExecutionPassed as exception:
             exception.set_earlier_failures(errors)
             raise exception
         except ExecutionFailed as exception:
             errors.extend(exception.get_errors())
             if not exception.can_continue(self._context.in_teardown,
                                           self._templated,
                                           self._context.dry_run):
                 break
     if errors:
         raise ExecutionFailures(errors)
def run_steps(self, steps):
    DebugLibrary.most_recent_step_runner = self
    errors = []
    self.steps = []
    self.og_steps = steps
    for step in steps:
        self.steps.append(step)
    while len(self.steps) > 0:
        self.cur_step = self.steps.pop(0)
        try:
            self.run_step(self.cur_step)
        except ExecutionPassed as exception:
            exception.set_earlier_failures(errors)
            raise exception
        except ExecutionFailed as exception:
            errors.extend(exception.get_errors())
            if not exception.can_continue(self._context.in_teardown,
                                          self._templated,
                                          self._context.dry_run):
                break
    if errors:
        raise ExecutionFailures(errors)
예제 #11
0
 def _run_loop(self, data, result):
     errors = []
     for values in self._get_values_for_rounds(data):
         try:
             self._run_one_round(values, data, result)
         except ExitForLoop as exception:
             if exception.earlier_failures:
                 errors.extend(exception.earlier_failures.get_errors())
             break
         except ContinueForLoop as exception:
             if exception.earlier_failures:
                 errors.extend(exception.earlier_failures.get_errors())
             continue
         except ExecutionPassed as exception:
             exception.set_earlier_failures(errors)
             raise exception
         except ExecutionFailed as exception:
             errors.extend(exception.get_errors())
             if not exception.can_continue(self._context.in_teardown,
                                           self._templated,
                                           self._context.dry_run):
                 break
     if errors:
         raise ExecutionFailures(errors)
def run_steps(self, steps):
    from robot.api import logger
    logger.error('run_steps')
    logger.error(steps)
    debugLibrary = BuiltIn().get_library_instance('DebugLibrary')

    debugLibrary.most_recent_step_runner = self

    errors = []
    self.steps = []
    self.og_steps = steps
    from robot.api import logger
    logger.error('run steps before trigger check {}'.format(debugLibrary.debug_trigger))
    if debugLibrary.debug_trigger:
        logger.error('run steps debug trigger')
        new_kwd = Keyword(name='Debug')
        self.steps.append(new_kwd)
        debugLibrary.debug_trigger = False

    for step in steps:
        self.steps.append(step)
    while len(self.steps) > 0:
        self.cur_step = self.steps.pop(0)
        try:
            self.run_step(self.cur_step)
        except ExecutionPassed as exception:
            exception.set_earlier_failures(errors)
            raise exception
        except ExecutionFailed as exception:
            errors.extend(exception.get_errors())
            if not exception.can_continue(self._context.in_teardown,
                                          self._templated,
                                          self._context.dry_run):
                break
    if errors:
        raise ExecutionFailures(errors)
예제 #13
0
 def run(self, data):
     run = self._run
     executed_once = False
     result = WhileResult(data.condition, data.limit)
     with StatusReporter(data, result, self._context, run) as status:
         if self._context.dry_run or not run:
             try:
                 self._run_iteration(data, result, run)
             except (BreakLoop, ContinueLoop):
                 pass
             return
         if data.error:
             raise DataError(data.error)
         limit = WhileLimit.create(data.limit, self._context.variables)
         errors = []
         while self._should_run(data.condition, self._context.variables) \
                 and limit.is_valid:
             executed_once = True
             try:
                 with limit:
                     self._run_iteration(data, result, run)
             except BreakLoop:
                 break
             except ContinueLoop:
                 continue
             except ExecutionFailed as err:
                 errors.extend(err.get_errors())
                 if not err.can_continue(self._context, self._templated):
                     break
         if not executed_once:
             status.pass_status = result.NOT_RUN
             self._run_iteration(data, result, run=False)
         if errors:
             raise ExecutionFailures(errors)
         if not limit.is_valid:
             raise DataError(limit.reason)
예제 #14
0
    def run(self, context):
        errors = []
        for kw in self._keywords:
            try:
                kw.run(context)
            except ExecutionPassed, exception:
                exception.set_earlier_failures(errors)
                raise exception
            except ExecutionFailed, exception:
                errors.extend(exception.get_errors())
                if not exception.can_continue(
                        context.in_teardown, self._templated, context.dry_run):
                    break
        if errors:
            raise ExecutionFailures(errors)

    def __nonzero__(self):
        return bool(self._keywords)

    def __iter__(self):
        return iter(self._keywords)


class _BaseKeyword:
    def __init__(self, name='', args=None, doc='', timeout='', type='kw'):
        self.name = name
        self.args = args or []
        self.doc = doc
        self.timeout = timeout
        self.type = type