Robot Framework Integrated Development Environment (RIDE)
merger.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.model import SuiteVisitor
18 from robotide.lib.robot.utils import html_escape
19 
20 
22 
23  def __init__(self, result):
24  self.resultresult = result
25  self.currentcurrent = None
26 
27  def merge(self, merged):
28  self.resultresult.set_execution_mode(merged)
29  merged.suite.visit(self)
30  self.resultresult.errors.add(merged.errors)
31 
32  def start_suite(self, suite):
33  try:
34  self.currentcurrent = self._find_suite_find_suite(self.currentcurrent, suite.name)
35  except IndexError:
36  suite.message = self._create_add_message_create_add_message(suite, test=False)
37  self.currentcurrent.suites.append(suite)
38  return False
39 
40  def _find_suite(self, parent, name):
41  if not parent:
42  suite = self._find_root_find_root(name)
43  else:
44  suite = self._find_find(parent.suites, name)
45  suite.starttime = suite.endtime = None
46  return suite
47 
48  def _find_root(self, name):
49  root = self.resultresult.suite
50  if root.name != name:
51  raise DataError("Cannot merge outputs containing different root "
52  "suites. Original suite is '%s' and merged is "
53  "'%s'." % (root.name, name))
54  return root
55 
56  def _find(self, items, name):
57  for item in items:
58  if item.name == name:
59  return item
60  raise IndexError
61 
62  def end_suite(self, suite):
63  self.currentcurrent = self.currentcurrent.parent
64 
65  def visit_test(self, test):
66  try:
67  old = self._find_find(self.currentcurrent.tests, test.name)
68  except IndexError:
69  test.message = self._create_add_message_create_add_message(test)
70  self.currentcurrent.tests.append(test)
71  else:
72  test.message = self._create_merge_message_create_merge_message(test, old)
73  index = self.currentcurrent.tests.index(old)
74  self.currentcurrent.tests[index] = test
75 
76  def _create_add_message(self, item, test=True):
77  prefix = ('*HTML* %s added from merged output.'
78  % ('Test' if test else 'Suite'))
79  if not item.message:
80  return prefix
81  return ''.join([prefix, '<hr>', self._html_escape_html_escape(item.message)])
82 
83  def _html_escape(self, message):
84  if message.startswith('*HTML*'):
85  return message[6:].lstrip()
86  else:
87  return html_escape(message)
88 
89  def _create_merge_message(self, new, old):
90  return ''.join([
91  '*HTML* Re-executed test has been merged.<hr>',
92  'New status: %s<br>' % self._format_status_format_status(new.status),
93  'New message: %s<hr>' % self._html_escape_html_escape(new.message),
94  'Old status: %s<br>' % self._format_status_format_status(old.status),
95  'Old message: %s' % self._html_escape_html_escape(old.message)
96  ])
97 
98  def _format_status(self, status):
99  return '<span class="%s">%s</span>' % (status.lower(), status)
Used when variable does not exist.
Definition: errors.py:67
Interface to ease traversing through a test suite structure.
Definition: visitor.py:75
def _find_suite(self, parent, name)
Definition: merger.py:40
def _create_merge_message(self, new, old)
Definition: merger.py:89
def end_suite(self, suite)
Called when suite ends.
Definition: merger.py:62
def start_suite(self, suite)
Called when suite starts.
Definition: merger.py:32
def _html_escape(self, message)
Definition: merger.py:83
def _create_add_message(self, item, test=True)
Definition: merger.py:76
def _format_status(self, status)
Definition: merger.py:98
def _find(self, items, name)
Definition: merger.py:56
def visit_test(self, test)
Implements traversing through the test and its keywords.
Definition: merger.py:65
def html_escape(text, linkify=True)
Definition: markuputils.py:40