Robot Framework Integrated Development Environment (RIDE)
model.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 
34 
35 from itertools import chain
36 
37 from robotide.lib.robot.model import TotalStatisticsBuilder, Criticality
38 from robotide.lib.robot import model, utils
39 
40 from .configurer import SuiteConfigurer
41 from .messagefilter import MessageFilter
42 from .keywordremover import KeywordRemover
43 from .suiteteardownfailed import (SuiteTeardownFailureHandler,
44  SuiteTeardownFailed)
45 
46 
47 # TODO: Should remove model.Message altogether and just implement the whole
48 # thing here. Additionally model.Keyword should not have `message_class` at
49 # all or it should be None.
50 
51 
56  __slots__ = []
57 
58 
59 
64  __slots__ = ['kwname', 'libname', 'status', 'starttime', 'endtime', 'message']
65  message_class = Message
66 
67  def __init__(self, kwname='', libname='', doc='', args=(), assign=(),
68  tags=(), timeout=None, type='kw', status='FAIL',
69  starttime=None, endtime=None):
70  model.Keyword.__init__(self, '', doc, args, assign, tags, timeout, type)
71  #: Name of the keyword without library or resource name.
72  self.kwnamekwname = kwname or ''
73  #: Name of the library or resource containing this keyword.
74  self.libnamelibname = libname or ''
75  #: Execution status as a string. Typically ``PASS`` or ``FAIL``, but
76  #: library keywords have status ``NOT_RUN`` in the dry-ryn mode.
77  #: See also :attr:`passed`.
78  self.statusstatus = status
79  #: Keyword execution start time in format ``%Y%m%d %H:%M:%S.%f``.
80  self.starttimestarttime = starttime
81  #: Keyword execution end time in format ``%Y%m%d %H:%M:%S.%f``.
82  self.endtimeendtime = endtime
83  #: Keyword status message. Used only if suite teardowns fails.
84  self.messagemessage = ''
85 
86  @property
87 
88  elapsedtime = property
89 
90  def elapsedtime(self):
91  return utils.get_elapsed_time(self.starttimestarttime, self.endtimeendtime)
92 
93  @property
94 
103  name = property
104 
105  def name(self):
106  if not self.libnamelibname:
107  return self.kwnamekwname
108  return '%s.%s' % (self.libnamelibname, self.kwnamekwname)
109 
110  @property
111 
112  passed = property
113 
114  def passed(self):
115  return self.statusstatus == 'PASS'
116 
117  @passed.setter
118 
119  def passed(self, passed):
120  self.statusstatus = 'PASS' if passed else 'FAIL'
121 
122 
123 
128  __slots__ = ['status', 'message', 'starttime', 'endtime']
129  keyword_class = Keyword
130 
131  def __init__(self, name='', doc='', tags=None, timeout=None, status='FAIL',
132  message='', starttime=None, endtime=None):
133  model.TestCase.__init__(self, name, doc, tags, timeout)
134  #: Status as a string ``PASS`` or ``FAIL``. See also :attr:`passed`.
135  self.statusstatus = status
136  #: Test message. Typically a failure message but can be set also when
137  #: test passes.
138  self.messagemessage = message
139  #: Test case execution start time in format ``%Y%m%d %H:%M:%S.%f``.
140  self.starttimestarttime = starttime
141  #: Test case execution end time in format ``%Y%m%d %H:%M:%S.%f``.
142  self.endtimeendtime = endtime
143 
144  @property
145 
146  elapsedtime = property
147 
148  def elapsedtime(self):
149  return utils.get_elapsed_time(self.starttimestarttime, self.endtimeendtime)
150 
151  @property
152 
153  passed = property
154 
155  def passed(self):
156  return self.statusstatus == 'PASS'
157 
158  @passed.setter
159 
160  def passed(self, passed):
161  self.statusstatus = 'PASS' if passed else 'FAIL'
162 
163  @property
164 
169  critical = property
170 
171  def critical(self):
172  if not self.parentparent:
173  return True
174  return self.parentparent.criticality.test_is_critical(self)
175 
176 
177 
182  __slots__ = ['message', 'starttime', 'endtime', '_criticality']
183  test_class = TestCase
184  keyword_class = Keyword
185 
186  def __init__(self, name='', doc='', metadata=None, source=None,
187  message='', starttime=None, endtime=None, rpa=False):
188  model.TestSuite.__init__(self, name, doc, metadata, source, rpa)
189  #: Possible suite setup or teardown error message.
190  self.messagemessage = message
191  #: Suite execution start time in format ``%Y%m%d %H:%M:%S.%f``.
192  self.starttimestarttime = starttime
193  #: Suite execution end time in format ``%Y%m%d %H:%M:%S.%f``.
194  self.endtimeendtime = endtime
195  self._criticality_criticality = None
196 
197  @property
198 
199  passed = property
200 
201  def passed(self):
202  return not self.statisticsstatisticsstatistics.critical.failed
203 
204  @property
205 
206  status = property
207 
208  def status(self):
209  return 'PASS' if self.passedpassedpassed else 'FAIL'
210 
211  @property
212 
222  statistics = property
223 
224  def statistics(self):
225  return TotalStatisticsBuilder(self, self.rparpa).stats
226 
227  @property
228 
229  full_message = property
230 
231  def full_message(self):
232  if not self.messagemessage:
233  return self.stat_messagestat_messagestat_message
234  return '%s\n\n%s' % (self.messagemessage, self.stat_messagestat_messagestat_message)
235 
236  @property
237 
238  stat_message = property
239 
240  def stat_message(self):
241  return self.statisticsstatisticsstatistics.message
242 
243  @property
244 
245  elapsedtime = property
246 
247  def elapsedtime(self):
248  if self.starttimestarttime and self.endtimeendtime:
249  return utils.get_elapsed_time(self.starttimestarttime, self.endtimeendtime)
250  return sum(child.elapsedtime for child in
251  chain(self.suitessuitessuites, self.teststeststests, self.keywordskeywordskeywords))
252 
253  @property
254 
260  criticality = property
261 
262  def criticality(self):
263  if self.parentparent:
264  return self.parentparent.criticality
265  if self._criticality_criticality is None:
266  self.set_criticalityset_criticality()
267  return self._criticality_criticality
268 
269 
282  def set_criticality(self, critical_tags=None, non_critical_tags=None):
283  if self.parentparent is not None:
284  raise ValueError('Criticality can only be set to the root suite.')
285  self._criticality_criticality = Criticality(critical_tags, non_critical_tags)
286 
287 
295  def remove_keywords(self, how):
296  self.visitvisit(KeywordRemover(how))
297 
298 
299  def filter_messages(self, log_level='TRACE'):
300  self.visitvisit(MessageFilter(log_level))
301 
302 
316  def configure(self, **options):
317  model.TestSuite.configure(self) # Parent validates call is allowed.
318  self.visitvisit(SuiteConfigurer(**options))
319 
320 
323 
324 
325  def suite_teardown_failed(self, message):
326  self.visitvisit(SuiteTeardownFailed(message))
def visit(self, visitor)
:mod:Visitor interface <robot.model.visitor> entry-point.
Definition: testsuite.py:178
def suites(self, suites)
Child suites as a :class:~.TestSuites object.
Definition: testsuite.py:85
def keywords(self, keywords)
Suite setup and teardown as a :class:~.Keywords object.
Definition: testsuite.py:95
def tests(self, tests)
Tests as a :class:~.TestCases object.
Definition: testsuite.py:90
Represents results of a single keyword.
Definition: model.py:63
name
Keyword name in format libname.kwname.
Definition: model.py:103
elapsedtime
Total execution time in milliseconds.
Definition: model.py:88
def __init__(self, kwname='', libname='', doc='', args=(), assign=(), tags=(), timeout=None, type='kw', status='FAIL', starttime=None, endtime=None)
Definition: model.py:69
passed
True or False depending on the :attr:status.
Definition: model.py:112
Represents a single log message.
Definition: model.py:55
Represents results of a single test case.
Definition: model.py:127
def __init__(self, name='', doc='', tags=None, timeout=None, status='FAIL', message='', starttime=None, endtime=None)
Definition: model.py:132
elapsedtime
Total execution time in milliseconds.
Definition: model.py:146
critical
True/False depending on is the test considered critical.
Definition: model.py:169
passed
True/False depending on the :attr:status.
Definition: model.py:153
Represents results of a single test suite.
Definition: model.py:181
status
'PASS' if no critical test has failed, 'FAIL' otherwise.
Definition: model.py:206
stat_message
String representation of the :attr:statistics.
Definition: model.py:238
full_message
Combination of :attr:message and :attr:stat_message.
Definition: model.py:229
elapsedtime
Total execution time in milliseconds.
Definition: model.py:245
def __init__(self, name='', doc='', metadata=None, source=None, message='', starttime=None, endtime=None, rpa=False)
Definition: model.py:187
def set_criticality(self, critical_tags=None, non_critical_tags=None)
Sets which tags are considered critical and which non-critical.
Definition: model.py:282
def filter_messages(self, log_level='TRACE')
Remove log messages below the specified log_level.
Definition: model.py:299
criticality
Used by tests to determine are they considered critical or not.
Definition: model.py:260
passed
True if no critical test has failed, False otherwise.
Definition: model.py:199
def configure(self, **options)
A shortcut to configure a suite using one method call.
Definition: model.py:316
statistics
Suite statistics as a :class:~robot.model.totalstatistics.TotalStatistics object.
Definition: model.py:222
def remove_keywords(self, how)
Remove keywords based on the given condition.
Definition: model.py:295
def handle_suite_teardown_failures(self)
Internal usage only.
Definition: model.py:321
def suite_teardown_failed(self, message)
Internal usage only.
Definition: model.py:325