Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/allure_commons/_allure.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from functools import wraps | |
2 from typing import Any, Callable, TypeVar | |
3 | |
4 from allure_commons._core import plugin_manager | |
5 from allure_commons.types import LabelType, LinkType | |
6 from allure_commons.utils import uuid4 | |
7 from allure_commons.utils import func_parameters, represent | |
8 | |
9 _TFunc = TypeVar("_TFunc", bound=Callable[..., Any]) | |
10 | |
11 | |
12 def safely(result): | |
13 if result: | |
14 return result[0] | |
15 else: | |
16 def dummy(function): | |
17 return function | |
18 return dummy | |
19 | |
20 | |
21 def title(test_title): | |
22 return safely(plugin_manager.hook.decorate_as_title(test_title=test_title)) | |
23 | |
24 | |
25 def description(test_description): | |
26 return safely(plugin_manager.hook.decorate_as_description(test_description=test_description)) | |
27 | |
28 | |
29 def description_html(test_description_html): | |
30 return safely(plugin_manager.hook.decorate_as_description_html(test_description_html=test_description_html)) | |
31 | |
32 | |
33 def label(label_type, *labels): | |
34 return safely(plugin_manager.hook.decorate_as_label(label_type=label_type, labels=labels)) | |
35 | |
36 | |
37 def severity(severity_level): | |
38 return label(LabelType.SEVERITY, severity_level) | |
39 | |
40 | |
41 def epic(*epics): | |
42 return label(LabelType.EPIC, *epics) | |
43 | |
44 | |
45 def feature(*features): | |
46 return label(LabelType.FEATURE, *features) | |
47 | |
48 | |
49 def story(*stories): | |
50 return label(LabelType.STORY, *stories) | |
51 | |
52 | |
53 def suite(suite_name): | |
54 return label(LabelType.SUITE, suite_name) | |
55 | |
56 | |
57 def parent_suite(parent_suite_name): | |
58 return label(LabelType.PARENT_SUITE, parent_suite_name) | |
59 | |
60 | |
61 def sub_suite(sub_suite_name): | |
62 return label(LabelType.SUB_SUITE, sub_suite_name) | |
63 | |
64 | |
65 def tag(*tags): | |
66 return label(LabelType.TAG, *tags) | |
67 | |
68 | |
69 def id(id): | |
70 return label(LabelType.ID, id) | |
71 | |
72 | |
73 def link(url, link_type=LinkType.LINK, name=None): | |
74 return safely(plugin_manager.hook.decorate_as_link(url=url, link_type=link_type, name=name)) | |
75 | |
76 | |
77 def issue(url, name=None): | |
78 return link(url, link_type=LinkType.ISSUE, name=name) | |
79 | |
80 | |
81 def testcase(url, name=None): | |
82 return link(url, link_type=LinkType.TEST_CASE, name=name) | |
83 | |
84 | |
85 class Dynamic(object): | |
86 | |
87 @staticmethod | |
88 def title(test_title): | |
89 plugin_manager.hook.add_title(test_title=test_title) | |
90 | |
91 @staticmethod | |
92 def description(test_description): | |
93 plugin_manager.hook.add_description(test_description=test_description) | |
94 | |
95 @staticmethod | |
96 def description_html(test_description_html): | |
97 plugin_manager.hook.add_description_html(test_description_html=test_description_html) | |
98 | |
99 @staticmethod | |
100 def label(label_type, *labels): | |
101 plugin_manager.hook.add_label(label_type=label_type, labels=labels) | |
102 | |
103 @staticmethod | |
104 def severity(severity_level): | |
105 Dynamic.label(LabelType.SEVERITY, severity_level) | |
106 | |
107 @staticmethod | |
108 def feature(*features): | |
109 Dynamic.label(LabelType.FEATURE, *features) | |
110 | |
111 @staticmethod | |
112 def story(*stories): | |
113 Dynamic.label(LabelType.STORY, *stories) | |
114 | |
115 @staticmethod | |
116 def tag(*tags): | |
117 Dynamic.label(LabelType.TAG, *tags) | |
118 | |
119 @staticmethod | |
120 def link(url, link_type=LinkType.LINK, name=None): | |
121 plugin_manager.hook.add_link(url=url, link_type=link_type, name=name) | |
122 | |
123 @staticmethod | |
124 def issue(url, name=None): | |
125 Dynamic.link(url, link_type=LinkType.ISSUE, name=name) | |
126 | |
127 @staticmethod | |
128 def testcase(url, name=None): | |
129 Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name) | |
130 | |
131 @staticmethod | |
132 def suite(suite_name): | |
133 Dynamic.label(LabelType.SUITE, suite_name) | |
134 | |
135 @staticmethod | |
136 def parent_suite(parent_suite_name): | |
137 Dynamic.label(LabelType.PARENT_SUITE, parent_suite_name) | |
138 | |
139 @staticmethod | |
140 def sub_suite(sub_suite_name): | |
141 Dynamic.label(LabelType.SUB_SUITE, sub_suite_name) | |
142 | |
143 | |
144 def step(title): | |
145 if callable(title): | |
146 return StepContext(title.__name__, {})(title) | |
147 else: | |
148 return StepContext(title, {}) | |
149 | |
150 | |
151 class StepContext: | |
152 | |
153 def __init__(self, title, params): | |
154 self.title = title | |
155 self.params = params | |
156 self.uuid = uuid4() | |
157 | |
158 def __enter__(self): | |
159 plugin_manager.hook.start_step(uuid=self.uuid, title=self.title, params=self.params) | |
160 | |
161 def __exit__(self, exc_type, exc_val, exc_tb): | |
162 plugin_manager.hook.stop_step(uuid=self.uuid, title=self.title, exc_type=exc_type, exc_val=exc_val, | |
163 exc_tb=exc_tb) | |
164 | |
165 def __call__(self, func: _TFunc) -> _TFunc: | |
166 @wraps(func) | |
167 def impl(*a, **kw): | |
168 __tracebackhide__ = True | |
169 params = func_parameters(func, *a, **kw) | |
170 args = list(map(lambda x: represent(x), a)) | |
171 with StepContext(self.title.format(*args, **params), params): | |
172 return func(*a, **kw) | |
173 return impl | |
174 | |
175 | |
176 class Attach(object): | |
177 | |
178 def __call__(self, body, name=None, attachment_type=None, extension=None): | |
179 plugin_manager.hook.attach_data(body=body, name=name, attachment_type=attachment_type, extension=extension) | |
180 | |
181 def file(self, source, name=None, attachment_type=None, extension=None): | |
182 plugin_manager.hook.attach_file(source=source, name=name, attachment_type=attachment_type, extension=extension) | |
183 | |
184 | |
185 attach = Attach() | |
186 | |
187 | |
188 class fixture(object): | |
189 def __init__(self, fixture_function, parent_uuid=None, name=None): | |
190 self._fixture_function = fixture_function | |
191 self._parent_uuid = parent_uuid | |
192 self._name = name if name else fixture_function.__name__ | |
193 self._uuid = uuid4() | |
194 self.parameters = None | |
195 | |
196 def __call__(self, *args, **kwargs): | |
197 self.parameters = func_parameters(self._fixture_function, *args, **kwargs) | |
198 | |
199 with self: | |
200 return self._fixture_function(*args, **kwargs) | |
201 | |
202 def __enter__(self): | |
203 plugin_manager.hook.start_fixture(parent_uuid=self._parent_uuid, | |
204 uuid=self._uuid, | |
205 name=self._name, | |
206 parameters=self.parameters) | |
207 | |
208 def __exit__(self, exc_type, exc_val, exc_tb): | |
209 plugin_manager.hook.stop_fixture(parent_uuid=self._parent_uuid, | |
210 uuid=self._uuid, | |
211 name=self._name, | |
212 exc_type=exc_type, | |
213 exc_val=exc_val, | |
214 exc_tb=exc_tb) | |
215 | |
216 | |
217 class test(object): | |
218 def __init__(self, _test, context): | |
219 self._test = _test | |
220 self._uuid = uuid4() | |
221 self.context = context | |
222 self.parameters = None | |
223 | |
224 def __call__(self, *args, **kwargs): | |
225 self.parameters = func_parameters(self._test, *args, **kwargs) | |
226 | |
227 with self: | |
228 return self._test(*args, **kwargs) | |
229 | |
230 def __enter__(self): | |
231 plugin_manager.hook.start_test(parent_uuid=None, | |
232 uuid=self._uuid, | |
233 name=None, | |
234 parameters=self.parameters, | |
235 context=self.context) | |
236 | |
237 def __exit__(self, exc_type, exc_val, exc_tb): | |
238 plugin_manager.hook.stop_test(parent_uuid=None, | |
239 uuid=self._uuid, | |
240 name=None, | |
241 context=self.context, | |
242 exc_type=exc_type, | |
243 exc_val=exc_val, | |
244 exc_tb=exc_tb) |