Robot Framework
dotted.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 import sys
17 
18 from robot.model import SuiteVisitor
19 from robot.utils import plural_or_not, secs_to_timestr
20 
21 from .highlighting import HighlightingStream
22 
23 
25 
26  def __init__(self, width=78, colors='AUTO', stdout=None, stderr=None):
27  self._width_width = width
28  self._stdout_stdout = HighlightingStream(stdout or sys.__stdout__, colors)
29  self._stderr_stderr = HighlightingStream(stderr or sys.__stderr__, colors)
30  self._markers_on_row_markers_on_row = 0
31 
32  def start_suite(self, suite):
33  if not suite.parent:
34  self._stdout_stdout.write("Running suite '%s' with %d %s%s.\n"
35  % (suite.name, suite.test_count,
36  'test' if not suite.rpa else 'task',
37  plural_or_not(suite.test_count)))
38  self._stdout_stdout.write('=' * self._width_width + '\n')
39 
40  def end_test(self, test):
41  if self._markers_on_row_markers_on_row == self._width_width:
42  self._stdout_stdout.write('\n')
43  self._markers_on_row_markers_on_row = 0
44  self._markers_on_row_markers_on_row += 1
45  if test.passed:
46  self._stdout_stdout.write('.')
47  elif test.skipped:
48  self._stdout_stdout.highlight('s', 'SKIP')
49  elif test.tags.robot('exit'):
50  self._stdout_stdout.write('x')
51  else:
52  self._stdout_stdout.highlight('F', 'FAIL')
53 
54  def end_suite(self, suite):
55  if not suite.parent:
56  self._stdout_stdout.write('\n')
57  StatusReporter(self._stdout_stdout, self._width_width).report(suite)
58  self._stdout_stdout.write('\n')
59 
60  def message(self, msg):
61  if msg.level in ('WARN', 'ERROR'):
62  self._stderr_stderr.error(msg.message, msg.level)
63 
64  def output_file(self, name, path):
65  self._stdout_stdout.write('%-8s %s\n' % (name+':', path))
66 
67 
69 
70  def __init__(self, stream, width):
71  self._stream_stream = stream
72  self._width_width = width
73 
74  def report(self, suite):
75  suite.visit(self)
76  stats = suite.statistics
77  self._stream_stream.write("%s\nRun suite '%s' with %d %s%s in %s.\n\n"
78  % ('=' * self._width_width, suite.name, stats.total,
79  'test' if not suite.rpa else 'task',
80  plural_or_not(stats.total),
81  secs_to_timestr(suite.elapsedtime/1000.0)))
82  self._stream_stream.highlight(suite.status + ('PED' if suite.status == 'SKIP' else 'ED'), suite.status)
83  self._stream_stream.write('\n%s\n' % stats.message)
84 
85  def visit_test(self, test):
86  if test.failed and not test.tags.robot('exit'):
87  self._stream_stream.write('-' * self._width_width + '\n')
88  self._stream_stream.highlight('FAIL')
89  self._stream_stream.write(': %s\n%s\n' % (test.longname,
90  test.message.strip()))
Interface to ease traversing through a test suite structure.
Definition: visitor.py:85
def __init__(self, width=78, colors='AUTO', stdout=None, stderr=None)
Definition: dotted.py:26
def output_file(self, name, path)
Definition: dotted.py:64
def __init__(self, stream, width)
Definition: dotted.py:70
def visit_test(self, test)
Implements traversing through tests.
Definition: dotted.py:85
def write(msg, level='INFO', html=False)
Writes the message to the log file using the given level.
Definition: logger.py:84
def error(msg, html=False)
Writes the message to the log file using the ERROR level.
Definition: logger.py:126
def plural_or_not(item)
Definition: misc.py:73
def secs_to_timestr(secs, compact=False)
Converts time in seconds to a string representation.
Definition: robottime.py:151