Robot Framework
logreportwriters.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 os.path import basename, splitext
17 
18 from robot.htmldata import HtmlFileWriter, ModelWriter, LOG, REPORT
19 from robot.utils import file_writer, is_string
20 
21 from .jswriter import JsResultWriter, SplitLogWriter
22 
23 
25  usage = None
26 
27  def __init__(self, js_model):
28  self._js_model_js_model = js_model
29 
30  def _write_file(self, path, config, template):
31  outfile = file_writer(path, usage=self.usageusage) \
32  if is_string(path) else path # unit test hook
33  with outfile:
34  model_writer = RobotModelWriter(outfile, self._js_model_js_model, config)
35  writer = HtmlFileWriter(outfile, model_writer)
36  writer.write(template)
37 
38 
40  usage = 'log'
41 
42  def write(self, path, config):
43  self._write_file_write_file(path, config, LOG)
44  if self._js_model_js_model.split_results:
45  self._write_split_logs_write_split_logs(splitext(path)[0])
46 
47  def _write_split_logs(self, base):
48  for index, (keywords, strings) in enumerate(self._js_model_js_model.split_results,
49  start=1):
50  self._write_split_log_write_split_log(index, keywords, strings, '%s-%d.js' % (base, index))
51 
52  def _write_split_log(self, index, keywords, strings, path):
53  with file_writer(path, usage=self.usageusageusage) as outfile:
54  writer = SplitLogWriter(outfile)
55  writer.write(keywords, strings, index, basename(path))
56 
57 
59  usage = 'report'
60 
61  def write(self, path, config):
62  self._write_file_write_file(path, config, REPORT)
63 
64 
66 
67  def __init__(self, output, model, config):
68  self._output_output = output
69  self._model_model = model
70  self._config_config = config
71 
72  def write(self, line):
73  JsResultWriter(self._output_output).write(self._model_model, self._config_config)
def _write_split_log(self, index, keywords, strings, path)
def _write_file(self, path, config, template)
def file_writer(path=None, encoding='UTF-8', newline=None, usage=None)
Definition: robotio.py:25