Robot Framework
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 robot.model import BodyItem
17 from robot.utils import is_list_like, is_dict_like, is_string, safe_str
18 
19 
21 
22  def __init__(self, arguments):
23  self._arguments_arguments = arguments
24  self._version2_version2 = None
25  self._version3_version3 = None
26 
27  def get_arguments(self, version):
28  if version == 2:
29  if self._version2_version2 is None:
30  self._version2_version2 = self._get_version2_arguments_get_version2_arguments(*self._arguments_arguments)
31  return self._version2_version2
32  else:
33  if self._version3_version3 is None:
34  self._version3_version3 = self._get_version3_arguments_get_version3_arguments(*self._arguments_arguments)
35  return self._version3_version3
36 
37  def _get_version2_arguments(self, *arguments):
38  return arguments
39 
40  def _get_version3_arguments(self, *arguments):
41  return arguments
42 
43  @classmethod
44  def by_method_name(cls, name, arguments):
45  Arguments = {'start_suite': StartSuiteArguments,
46  'end_suite': EndSuiteArguments,
47  'start_test': StartTestArguments,
48  'end_test': EndTestArguments,
49  'start_keyword': StartKeywordArguments,
50  'end_keyword': EndKeywordArguments,
51  'log_message': MessageArguments,
52  'message': MessageArguments}.get(name, ListenerArguments)
53  return Arguments(arguments)
54 
55 
57 
58  def _get_version2_arguments(self, msg):
59  attributes = {'timestamp': msg.timestamp,
60  'message': msg.message,
61  'level': msg.level,
62  'html': 'yes' if msg.html else 'no'}
63  return attributes,
64 
65  def _get_version3_arguments(self, msg):
66  return msg,
67 
68 
70 
73  _attribute_names = None
74 
75  def _get_version2_arguments(self, item):
76  attributes = dict((name, self._get_attribute_value_get_attribute_value(item, name))
77  for name in self._attribute_names_attribute_names)
78  attributes.update(self._get_extra_attributes_get_extra_attributes(item))
79  return item.name or '', attributes
80 
81  def _get_attribute_value(self, item, name):
82  value = getattr(item, name)
83  return self._take_copy_of_mutable_value_take_copy_of_mutable_value(value)
84 
85  def _take_copy_of_mutable_value(self, value):
86  if is_dict_like(value):
87  return dict(value)
88  if is_list_like(value):
89  return list(value)
90  return value
91 
92  def _get_extra_attributes(self, item):
93  return {}
94 
95  def _get_version3_arguments(self, item):
96  return item.data, item.result
97 
98 
100 
103  _attribute_names = ('id', 'longname', 'doc', 'metadata', 'starttime')
104 
105  def _get_extra_attributes(self, suite):
106  return {'tests': [t.name for t in suite.tests],
107  'suites': [s.name for s in suite.suites],
108  'totaltests': suite.test_count,
109  'source': suite.source or ''}
110 
111 
113 
116  _attribute_names = ('id', 'longname', 'doc', 'metadata', 'starttime',
117  'endtime', 'elapsedtime', 'status', 'message')
118 
119  def _get_extra_attributes(self, suite):
120  attrs = StartSuiteArguments._get_extra_attributes(self, suite)
121  attrs['statistics'] = suite.stat_message
122  return attrs
123 
124 
126 
129  _attribute_names = ('id', 'longname', 'doc', 'tags', 'lineno', 'source', 'starttime')
130 
131  def _get_extra_attributes(self, test):
132  return {'template': test.template or '',
133  'originalname': test.data.name}
134 
135 
137 
140  _attribute_names = ('id', 'longname', 'doc', 'tags', 'lineno', 'source', 'starttime',
141  'endtime', 'elapsedtime', 'status', 'message')
142 
143 
145 
148  _attribute_names = ('doc', 'assign', 'tags', 'lineno', 'source', 'type', 'status',
149  'starttime')
150 
153  _type_attributes = {
154  BodyItem.FOR: ('variables', 'flavor', 'values'),
155  BodyItem.IF: ('condition',),
156  BodyItem.ELSE_IF: ('condition'),
157  BodyItem.EXCEPT: ('patterns', 'pattern_type', 'variable'),
158  BodyItem.WHILE: ('condition', 'limit'),
159  BodyItem.RETURN: ('values',),
160  BodyItem.ITERATION: ('variables',)}
161 
162  def _get_extra_attributes(self, kw):
163  args = [a if is_string(a) else safe_str(a) for a in kw.args]
164  attrs = {'kwname': kw.kwname or '', 'libname': kw.libname or '', 'args': args}
165  if kw.type in self._type_attributes_type_attributes:
166  attrs.update({name: self._get_attribute_value_get_attribute_value(kw, name)
167  for name in self._type_attributes_type_attributes[kw.type]
168  if hasattr(kw, name)})
169  return attrs
170 
171 
173 
176  _attribute_names = ('doc', 'assign', 'tags', 'lineno', 'source', 'type', 'status',
177  'starttime', 'endtime', 'elapsedtime')
def is_dict_like(item)
Definition: robottypes.py:72
def is_list_like(item)
Definition: robottypes.py:66
def safe_str(item)
Definition: unic.py:21