Robot Framework
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 robot.errors import DataError
17 from robot.utils import (get_error_details, Importer, is_string,
18  split_args_from_name_or_path, type_name)
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, logger))
29 
30  def visit_suite(self, suite):
31  for visitor in self._visitors_visitors:
32  try:
33  suite.visit(visitor)
34  except Exception:
35  message, details = get_error_details()
36  self._log_error_log_error(f"Executing model modifier '{type_name(visitor)}' "
37  f"failed: {message}\n{details}")
38  if not (suite.test_count or self._empty_suite_ok_empty_suite_ok):
39  raise DataError(f"Suite '{suite.name}' contains no tests after "
40  f"model modifiers.")
41 
42  def _yield_visitors(self, visitors, logger):
43  importer = Importer('model modifier', logger=logger)
44  for visitor in visitors:
45  if is_string(visitor):
46  name, args = split_args_from_name_or_path(visitor)
47  try:
48  yield importer.import_class_or_module(name, args)
49  except DataError as err:
50  logger.error(err.message)
51  else:
52  yield visitor
def __init__(self, visitors, empty_suite_ok, logger)
Definition: modifier.py:25
def _yield_visitors(self, visitors, logger)
Definition: modifier.py:42
def visit_suite(self, suite)
Implements traversing through suites.
Definition: modifier.py:30
Interface to ease traversing through a test suite structure.
Definition: visitor.py:85
def get_error_details(full_traceback=True, exclude_robot_traces=EXCLUDE_ROBOT_TRACES)
Returns error message and details of the last occurred exception.
Definition: error.py:39
def split_args_from_name_or_path(name)
Split arguments embedded to name or path like Example:arg1:arg2.
Definition: text.py:141