Robot Framework
totalstatistics.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.utils import test_or_task
17 
18 from .stats import TotalStat
19 from .visitor import SuiteVisitor
20 
21 
22 
24 
25  def __init__(self, rpa=False):
26  #: Instance of :class:`~robot.model.stats.TotalStat` for all the tests.
27  self._stat_stat = TotalStat(test_or_task('All {Test}s', rpa))
28  self._rpa_rpa = rpa
29 
30  def visit(self, visitor):
31  visitor.visit_total_statistics(self._stat_stat)
32 
33  def __iter__(self):
34  yield self._stat_stat
35 
36  @property
37  total = property
38 
39  def total(self):
40  return self._stat_stat.total
41 
42  @property
43  passed = property
44 
45  def passed(self):
46  return self._stat_stat.passed
47 
48  @property
49  skipped = property
50 
51  def skipped(self):
52  return self._stat_stat.skipped
53 
54  @property
55  failed = property
56 
57  def failed(self):
58  return self._stat_stat.failed
59 
60  def add_test(self, test):
61  self._stat_stat.add_test(test)
62 
63  @property
64 
69  message = property
70 
71  def message(self):
72  # TODO: should this message be highlighted in console
73  test_or_task = 'test' if not self._rpa_rpa else 'task'
74  total, end, passed, failed, skipped = self._get_counts_get_counts()
75  template = '%d %s%s, %d passed, %d failed'
76  if skipped:
77  return ((template + ', %d skipped')
78  % (total, test_or_task, end, passed, failed, skipped))
79  return template % (total, test_or_task, end, passed, failed)
80 
81  def _get_counts(self):
82  ending = 's' if self.totaltotaltotal != 1 else ''
83  return self.totaltotaltotal, ending, self.passedpassedpassed, self.failedfailedfailed, self.skippedskippedskipped
84 
85 
87 
88  def __init__(self, suite=None, rpa=False):
89  self.statsstats = TotalStatistics(rpa)
90  if suite:
91  suite.visit(self)
92 
93  def add_test(self, test):
94  self.statsstats.add_test(test)
95 
96  def visit_test(self, test):
97  self.add_testadd_test(test)
98 
99  def visit_keyword(self, kw):
100  pass
Stores statistic values for a test run.
Definition: stats.py:104
def visit_test(self, test)
Implements traversing through tests.
def visit_keyword(self, kw)
Implements traversing through keywords.
Container for total statistics.
message
String representation of the statistics.
Interface to ease traversing through a test suite structure.
Definition: visitor.py:85
def test_or_task(str text, bool rpa)
Replace 'test' with 'task' in the given text depending on rpa.
Definition: misc.py:105