Robot Framework Integrated Development Environment (RIDE)
jsmodelbuilders.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.output import LEVELS
17 
18 from .jsbuildingcontext import JsBuildingContext
19 from .jsexecutionresult import JsExecutionResult
20 
21 
23 
24  def __init__(self, log_path=None, split_log=False,
25  prune_input_to_save_memory=False):
26  self._context_context = JsBuildingContext(log_path, split_log,
27  prune_input_to_save_memory)
28 
29  def build_from(self, result_from_xml):
30  # Statistics must be build first because building suite may prune input.
31  return JsExecutionResult(
32  statistics=StatisticsBuilder().build(result_from_xml.statistics),
33  suite=SuiteBuilder(self._context_context).build(result_from_xml.suite),
34  errors=ErrorsBuilder(self._context_context).build(result_from_xml.errors),
35  strings=self._context_context.strings,
36  basemillis=self._context_context.basemillis,
37  split_results=self._context_context.split_results,
38  min_level=self._context_context.min_level
39  )
40 
41 
42 class _Builder():
43 
46  _statuses = {'FAIL': 0, 'PASS': 1, 'NOT_RUN': 2}
47 
48  def __init__(self, context):
49  self._context_context = context
50  self._string_string = self._context_context.string
51  self._html_html = self._context_context.html
52  self._timestamp_timestamp = self._context_context.timestamp
53 
54  def _get_status(self, item):
55  model = (self._statuses_statuses[item.status],
56  self._timestamp_timestamp(item.starttime),
57  item.elapsedtime)
58  msg = getattr(item, 'message', '')
59  if not msg:
60  return model
61  elif msg.startswith('*HTML*'):
62  msg = self._string_string(msg[6:].lstrip(), escape=False)
63  else:
64  msg = self._string_string(msg)
65  return model + (msg,)
66 
67  def _build_keywords(self, kws, split=False):
68  splitting = self._context_context.start_splitting_if_needed(split)
69  model = tuple(self._build_keyword(k) for k in kws)
70  return model if not splitting else self._context_context.end_splitting(model)
71 
72 
74 
75  def __init__(self, context):
76  _Builder.__init__(self, context)
77  self._build_suite_build_suite = self.buildbuild
78  self._build_test_build_test = TestBuilder(context).build
79  self._build_keyword_build_keyword = KeywordBuilder(context).build
80 
81  def build(self, suite):
82  with self._context_context.prune_input(suite.suites, suite.tests, suite.keywords):
83  stats = self._get_statistics_get_statistics(suite) # Must be done before pruning
84  return (self._string_string(suite.name, attr=True),
85  self._string_string(suite.source),
86  self._context_context.relative_source(suite.source),
87  self._html_html(suite.doc),
88  tuple(self._yield_metadata_yield_metadata(suite)),
89  self._get_status_get_status(suite),
90  tuple(self._build_suite_build_suite(s) for s in suite.suites),
91  tuple(self._build_test_build_test(t) for t in suite.tests),
92  tuple(self._build_keyword_build_keyword(k, split=True) for k in suite.keywords),
93  stats)
94 
95  def _yield_metadata(self, suite):
96  for name, value in suite.metadata.items():
97  yield self._string_string(name)
98  yield self._html_html(value)
99 
100  def _get_statistics(self, suite):
101  stats = suite.statistics # Access property only once
102  return (stats.all.total,
103  stats.all.passed,
104  stats.critical.total,
105  stats.critical.passed)
106 
107 
109 
110  def __init__(self, context):
111  _Builder.__init__(self, context)
112  self._build_keyword_build_keyword = KeywordBuilder(context).build
113 
114  def build(self, test):
115  with self._context_context.prune_input(test.keywords):
116  return (self._string_string(test.name, attr=True),
117  self._string_string(test.timeout),
118  int(test.critical),
119  self._html_html(test.doc),
120  tuple(self._string_string(t) for t in test.tags),
121  self._get_status_get_status(test),
122  self._build_keywords_build_keywords(test.keywords, split=True))
123 
124 
126 
129  _types = {'kw': 0, 'setup': 1, 'teardown': 2, 'for': 3, 'foritem': 4}
130 
131  def __init__(self, context):
132  _Builder.__init__(self, context)
133  self._build_keyword_build_keyword = self.buildbuild
134  self._build_message_build_message = MessageBuilder(context).build
135 
136  def build(self, kw, split=False):
137  with self._context_context.prune_input(kw.messages, kw.keywords):
138  return (self._types_types[kw.type],
139  self._string_string(kw.kwname, attr=True),
140  self._string_string(kw.libname, attr=True),
141  self._string_string(kw.timeout),
142  self._html_html(kw.doc),
143  self._string_string(', '.join(kw.args)),
144  self._string_string(', '.join(kw.assign)),
145  self._string_string(', '.join(kw.tags)),
146  self._get_status_get_status(kw),
147  self._build_keywords_build_keywords(kw.keywords, split),
148  tuple(self._build_message_build_message(m) for m in kw.messages))
149 
150 
152 
153  def build(self, msg):
154  if msg.level in ('WARN','ERROR'):
155  self._context_context.create_link_target(msg)
156  self._context_context.message_level(msg.level)
157  return self._build_build(msg)
158 
159  def _build(self, msg):
160  return (self._timestamp_timestamp(msg.timestamp),
161  LEVELS[msg.level],
162  self._string_string(msg.html_message, escape=False))
163 
164 
166 
167  def build(self, statistics):
168  return (self._build_stats_build_stats(statistics.total),
169  self._build_stats_build_stats(statistics.tags),
170  self._build_stats_build_stats(statistics.suite, exclude_empty=False))
171 
172  def _build_stats(self, stats, exclude_empty=True):
173  return tuple(stat.get_attributes(include_label=True,
174  include_elapsed=True,
175  exclude_empty=exclude_empty,
176  html_escape=True)
177  for stat in stats)
178 
179 
181 
182  def __init__(self, context):
183  _Builder.__init__(self, context)
184  self._build_message_build_message = ErrorMessageBuilder(context).build
185 
186  def build(self, errors):
187  with self._context_context.prune_input(errors.messages):
188  return tuple(self._build_message_build_message(msg) for msg in errors)
189 
190 
192 
193  def build(self, msg):
194  model = self._build_build(msg)
195  link = self._context_context.link(msg)
196  return model if link is None else model + (link,)
def __init__(self, log_path=None, split_log=False, prune_input_to_save_memory=False)