Robot Framework Integrated Development Environment (RIDE)
modifier.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from robotide.lib.robot.errors import DataError
17 from robotide.lib.robot.utils import (get_error_details, is_string,
18  split_args_from_name_or_path, type_name, Importer)
19 
20 from .visitor import SuiteVisitor
21 
22 
24 
25  def __init__(self, visitors, empty_suite_ok, logger):
26  self._log_error_log_error = logger.error
27  self._empty_suite_ok_empty_suite_ok = empty_suite_ok
28  self._visitors_visitors = list(self._yield_visitors_yield_visitors(visitors))
29 
30  def visit_suite(self, suite):
31  for visitor in self._visitors_visitors:
32  try:
33  suite.visit(visitor)
34  except:
35  message, details = get_error_details()
36  self._log_error_log_error("Executing model modifier '%s' failed: %s\n%s"
37  % (type_name(visitor), message, details))
38  if not (suite.test_count or self._empty_suite_ok_empty_suite_ok):
39  raise DataError("Suite '%s' contains no tests after model "
40  "modifiers." % suite.name)
41 
42  def _yield_visitors(self, visitors):
43  importer = Importer('model modifier')
44  for visitor in visitors:
45  try:
46  if not is_string(visitor):
47  yield visitor
48  else:
49  name, args = split_args_from_name_or_path(visitor)
50  yield importer.import_class_or_module(name, args)
51  except DataError as err:
52  self._log_error_log_error(err.message)
Used when variable does not exist.
Definition: errors.py:67
def visit_suite(self, suite)
Implements traversing through the suite and its direct children.
Definition: modifier.py:30
def __init__(self, visitors, empty_suite_ok, logger)
Definition: modifier.py:25
Interface to ease traversing through a test suite structure.
Definition: visitor.py:75
def get_error_details(exclude_robot_traces=EXCLUDE_ROBOT_TRACES)
Returns error message and details of the last occurred exception.
Definition: error.py:46
def split_args_from_name_or_path(name)
Definition: text.py:132