18 from robot.utils import ET, ETSource, get_error_message
20 from .executionresult
import Result, CombinedResult
21 from .flattenkeywordmatcher
import (FlattenByNameMatcher, FlattenByTypeMatcher,
23 from .merger
import Merger
24 from .xmlelementhandlers
import XmlElementHandler
47 raise DataError(
'One or more data source needed.')
48 if options.pop(
'merge',
False):
57 merger =
Merger(result, rpa=result.rpa)
69 ets = ETSource(source)
70 result =
Result(source, rpa=options.pop(
'rpa',
None))
73 except IOError
as err:
77 raise DataError(f
"Reading XML source '{ets}' failed: {error}")
98 def __init__(self, source, include_keywords=True, flattened_keywords=None):
100 if isinstance(source, ETSource)
else ETSource(source)
107 with self.
_source_source
as source:
108 self.
_parse_parse(source, handler.start, handler.end)
109 result.handle_suite_teardown_failures()
115 context = ET.iterparse(source, events=(
'start',
'end'))
120 for event, elem
in context:
129 for event, elem
in context:
132 omit = elem.tag
in (
'kw',
'for',
'if')
and elem.get(
'type') !=
'TEARDOWN'
133 start = event ==
'start'
140 if omit
and not start:
145 name_match, by_name = self.
_get_matcher_get_matcher(FlattenByNameMatcher, flattened)
146 type_match, by_type = self.
_get_matcher_get_matcher(FlattenByTypeMatcher, flattened)
147 tags_match, by_tags = self.
_get_matcher_get_matcher(FlattenByTagMatcher, flattened)
150 containers = {
'kw',
'for',
'while',
'iter',
'if',
'try'}
153 for event, elem
in context:
155 start = event ==
'start'
158 if tag
in containers:
162 elif by_name
and name_match(elem.get(
'name',
''), elem.get(
'library')):
165 elif by_type
and type_match(tag):
170 if tag
in containers:
172 if started == 0
and not seen_doc:
173 doc = ET.Element(
'doc')
174 doc.text =
'_*Content flattened.*_'
177 elif by_tags
and inside_kw
and started < 0
and tag ==
'tag':
178 tags.append(elem.text
or '')
182 elif started == 0
and tag ==
'doc':
184 elem.text = f
"{elem.text or ''}\n\n_*Content flattened.*_".strip()
185 if started <= 0
or tag ==
'msg':
189 if started >= 0
and end
and tag
in containers:
193 matcher = matcher_class(flattened)
194 return matcher.match, bool(matcher)
201 suite.teardown =
None
Interface to ease traversing through a test suite structure.
Combined results of multiple test executions.
Builds :class:~.executionresult.Result objects based on output files.
def _parse(self, source, start, end)
def _omit_keywords(self, context)
def __init__(self, source, include_keywords=True, flattened_keywords=None)
:param source: Path to the XML output file to build :class:~.executionresult.Result objects from.
def _get_matcher(self, matcher_class, flattened)
def _flatten_keywords(self, context, flattened)
def visit_test(self, test)
Implements traversing through tests.
def start_suite(self, suite)
Called when a suite starts.
def _merge_results(original, merged, options)
def _single_result(source, options)
def _combine_results(sources, options)
def ExecutionResult(*sources, **options)
Factory method to constructs :class:~.executionresult.Result objects.
def get_error_message()
Returns error message of the last occurred exception.