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