Robot Framework
jsexecutionresult.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 time
17 
18 from .stringcache import StringIndex
19 
20 
22 
23  def __init__(self, suite, statistics, errors, strings, basemillis=None,
24  split_results=None, min_level=None, expand_keywords=None):
25  self.suitesuite = suite
26  self.stringsstrings = strings
27  self.min_levelmin_level = min_level
28  self.datadata = self._get_data_get_data(statistics, errors, basemillis or 0, expand_keywords)
29  self.split_resultssplit_results = split_results or []
30 
31  def _get_data(self, statistics, errors, basemillis, expand_keywords):
32  return {'stats': statistics,
33  'errors': errors,
34  'baseMillis': basemillis,
35  'generated': int(time.time() * 1000) - basemillis,
36  'expand_keywords': expand_keywords}
37 
39  self.datadata.pop('errors')
40  remover = _KeywordRemover()
41  self.suitesuite = remover.remove_keywords(self.suitesuite)
42  self.suitesuite, self.stringsstrings = remover.remove_unused_strings(self.suitesuite, self.stringsstrings)
43 
44 
46 
47  def remove_keywords(self, suite):
48  return self._remove_keywords_from_suite_remove_keywords_from_suite(suite)
49 
50  def _remove_keywords_from_suite(self, suite):
51  return suite[:6] + (self._remove_keywords_from_suites_remove_keywords_from_suites(suite[6]),
52  self._remove_keywords_from_tests_remove_keywords_from_tests(suite[7]),
53  (), suite[9])
54 
55  def _remove_keywords_from_suites(self, suites):
56  return tuple(self._remove_keywords_from_suite_remove_keywords_from_suite(s) for s in suites)
57 
58  def _remove_keywords_from_tests(self, tests):
59  return tuple(self._remove_keywords_from_test_remove_keywords_from_test(t) for t in tests)
60 
61  def _remove_keywords_from_test(self, test):
62  return test[:-1] + ((),)
63 
64  def remove_unused_strings(self, model, strings):
65  used = set(self._get_used_indices_get_used_indices(model))
66  remap = {}
67  strings = tuple(self._get_used_strings_get_used_strings(strings, used, remap))
68  model = tuple(self._remap_string_indices_remap_string_indices(model, remap))
69  return model, strings
70 
71  def _get_used_indices(self, model):
72  for item in model:
73  if isinstance(item, StringIndex):
74  yield item
75  elif isinstance(item, tuple):
76  for i in self._get_used_indices_get_used_indices(item):
77  yield i
78 
79  def _get_used_strings(self, strings, used_indices, remap):
80  offset = 0
81  for index, string in enumerate(strings):
82  if index in used_indices:
83  remap[index] = index - offset
84  yield string
85  else:
86  offset += 1
87 
88  def _remap_string_indices(self, model, remap):
89  for item in model:
90  if isinstance(item, StringIndex):
91  yield remap[item]
92  elif isinstance(item, tuple):
93  yield tuple(self._remap_string_indices_remap_string_indices(item, remap))
94  else:
95  yield item
def __init__(self, suite, statistics, errors, strings, basemillis=None, split_results=None, min_level=None, expand_keywords=None)
def _get_data(self, statistics, errors, basemillis, expand_keywords)
def _get_used_strings(self, strings, used_indices, remap)