Robot Framework Integrated Development Environment (RIDE)
listenerarguments.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.utils import is_list_like, is_dict_like, is_string, unic
17 
18 
20 
21  def __init__(self, arguments):
22  self._arguments_arguments = arguments
23  self._version2_version2 = None
24  self._version3_version3 = None
25 
26  def get_arguments(self, version):
27  if version == 2:
28  if self._version2_version2 is None:
29  self._version2_version2 = self._get_version2_arguments_get_version2_arguments(*self._arguments_arguments)
30  return self._version2_version2
31  else:
32  if self._version3_version3 is None:
33  self._version3_version3 = self._get_version3_arguments_get_version3_arguments(*self._arguments_arguments)
34  return self._version3_version3
35 
36  def _get_version2_arguments(self, *arguments):
37  return arguments
38 
39  def _get_version3_arguments(self, *arguments):
40  return arguments
41 
42  @classmethod
43  def by_method_name(cls, name, arguments):
44  Arguments = {'start_suite': StartSuiteArguments,
45  'end_suite': EndSuiteArguments,
46  'start_test': StartTestArguments,
47  'end_test': EndTestArguments,
48  'start_keyword': StartKeywordArguments,
49  'end_keyword': EndKeywordArguments,
50  'log_message': MessageArguments,
51  'message': MessageArguments}.get(name, ListenerArguments)
52  return Arguments(arguments)
53 
54 
56 
57  def _get_version2_arguments(self, msg):
58  attributes = {'timestamp': msg.timestamp,
59  'message': msg.message,
60  'level': msg.level,
61  'html': 'yes' if msg.html else 'no'}
62  return attributes,
63 
64  def _get_version3_arguments(self, msg):
65  return msg,
66 
67 
69 
72  _attribute_names = None
73 
74  def _get_version2_arguments(self, item):
75  attributes = dict((name, self._get_attribute_value_get_attribute_value(item, name))
76  for name in self._attribute_names_attribute_names)
77  attributes.update(self._get_extra_attributes_get_extra_attributes(item))
78  return item.name, attributes
79 
80  def _get_attribute_value(self, item, name):
81  value = getattr(item, name)
82  return self._take_copy_of_mutable_value_take_copy_of_mutable_value(value)
83 
84  def _take_copy_of_mutable_value(self, value):
85  if is_dict_like(value):
86  return dict(value)
87  if is_list_like(value):
88  return list(value)
89  return value
90 
91  def _get_extra_attributes(self, item):
92  return {}
93 
94  def _get_version3_arguments(self, item):
95  return item.data, item.result
96 
97 
99 
102  _attribute_names = ('id', 'longname', 'doc', 'metadata', 'starttime')
103 
104  def _get_extra_attributes(self, suite):
105  return {'tests': [t.name for t in suite.tests],
106  'suites': [s.name for s in suite.suites],
107  'totaltests': suite.test_count,
108  'source': suite.source or ''}
109 
110 
112 
115  _attribute_names = ('id', 'longname', 'doc', 'metadata', 'starttime',
116  'endtime', 'elapsedtime', 'status', 'message')
117 
118  def _get_extra_attributes(self, suite):
119  attrs = StartSuiteArguments._get_extra_attributes(self, suite)
120  attrs['statistics'] = suite.stat_message
121  return attrs
122 
123 
125 
128  _attribute_names = ('id', 'longname', 'doc', 'tags', 'starttime')
129 
130  def _get_extra_attributes(self, test):
131  return {'critical': 'yes' if test.critical else 'no',
132  'template': test.template or ''}
133 
134 
136 
139  _attribute_names = ('id', 'longname', 'doc', 'tags', 'starttime',
140  'endtime', 'elapsedtime', 'status', 'message')
141 
142 
144 
147  _attribute_names = ('kwname', 'libname', 'doc', 'assign', 'tags',
148  'starttime')
149 
152  _types = {'kw': 'Keyword', 'setup': 'Setup', 'teardown': 'Teardown',
153  'for': 'For', 'foritem': 'For Item'}
154 
155  def _get_extra_attributes(self, kw):
156  args = [a if is_string(a) else unic(a) for a in kw.args]
157  return {'args': args, 'type': self._types_types[kw.type]}
158 
159 
161 
164  _attribute_names = ('kwname', 'libname', 'doc', 'args', 'assign', 'tags',
165  'starttime', 'endtime', 'elapsedtime', 'status')