Skip to content

Commit 6c737fa

Browse files
committed
Remove stub file
1 parent 78354ee commit 6c737fa

File tree

2 files changed

+109
-194
lines changed

2 files changed

+109
-194
lines changed

reportportal_client/client.py

Lines changed: 109 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import logging
1717
import warnings
1818
from os import getenv
19+
from typing import Union, Tuple, List, Dict, Any, Optional
1920

2021
import requests
2122
from requests.adapters import HTTPAdapter, Retry, DEFAULT_RETRIES
2223

24+
from core.rp_issues import Issue
2325
from ._local import set_current
2426
from .core.rp_requests import (
2527
HttpRequest,
@@ -38,7 +40,7 @@
3840
logger.addHandler(logging.NullHandler())
3941

4042

41-
class RPClient(object):
43+
class RPClient:
4244
"""Report portal client.
4345
4446
The class is supposed to use by Report Portal agents: both custom and
@@ -49,20 +51,44 @@ class RPClient(object):
4951
thread to avoid request/response messing and other issues.
5052
"""
5153

52-
def __init__(self,
53-
endpoint,
54-
project,
55-
api_key=None,
56-
log_batch_size=20,
57-
is_skipped_an_issue=True,
58-
verify_ssl=True,
59-
retries=None,
60-
max_pool_size=50,
61-
launch_id=None,
62-
http_timeout=(10, 10),
63-
log_batch_payload_size=MAX_LOG_BATCH_PAYLOAD_SIZE,
64-
mode='DEFAULT',
65-
**kwargs):
54+
_log_manager: LogManager = ...
55+
api_v1: str = ...
56+
api_v2: str = ...
57+
base_url_v1: str = ...
58+
base_url_v2: str = ...
59+
endpoint: str = ...
60+
is_skipped_an_issue: bool = ...
61+
launch_id: str = ...
62+
log_batch_size: int = ...
63+
log_batch_payload_size: int = ...
64+
project: str = ...
65+
api_key: str = ...
66+
verify_ssl: Union[bool, str] = ...
67+
retries: int = ...
68+
max_pool_size: int = ...
69+
http_timeout: Union[float, Tuple[float, float]] = ...
70+
session: requests.Session = ...
71+
step_reporter: StepReporter = ...
72+
mode: str = ...
73+
_skip_analytics: str = ...
74+
_item_stack: List[str] = ...
75+
76+
def __init__(
77+
self,
78+
endpoint: str,
79+
project: str,
80+
api_key: str = None,
81+
log_batch_size: int = 20,
82+
is_skipped_an_issue: bool = True,
83+
verify_ssl: bool = True,
84+
retries: int = None,
85+
max_pool_size: int = 50,
86+
launch_id: str = None,
87+
http_timeout: Union[float, Tuple[float, float]] = (10, 10),
88+
log_batch_payload_size: int = MAX_LOG_BATCH_PAYLOAD_SIZE,
89+
mode: str = 'DEFAULT',
90+
**kwargs: Any
91+
) -> None:
6692
"""Initialize required attributes.
6793
6894
:param endpoint: Endpoint of the report portal service
@@ -110,28 +136,28 @@ def __init__(self,
110136
if not self.api_key:
111137
if 'token' in kwargs:
112138
warnings.warn(
113-
message="Argument `token` is deprecated since 5.3.5 and "
114-
"will be subject for removing in the next major "
115-
"version. Use `api_key` argument instead.",
139+
message='Argument `token` is deprecated since 5.3.5 and '
140+
'will be subject for removing in the next major '
141+
'version. Use `api_key` argument instead.',
116142
category=DeprecationWarning,
117143
stacklevel=2
118144
)
119145
self.api_key = kwargs['token']
120146

121147
if not self.api_key:
122148
warnings.warn(
123-
message="Argument `api_key` is `None` or empty string, "
124-
"that's not supposed to happen because Report "
125-
"Portal is usually requires an authorization key. "
126-
"Please check your code.",
149+
message='Argument `api_key` is `None` or empty string, '
150+
'that is not supposed to happen because Report '
151+
'Portal is usually requires an authorization key. '
152+
'Please check your code.',
127153
category=RuntimeWarning,
128154
stacklevel=2
129155
)
130156

131157
self.__init_session()
132158
self.__init_log_manager()
133159

134-
def __init_session(self):
160+
def __init_session(self) -> None:
135161
retry_strategy = Retry(
136162
total=self.retries,
137163
backoff_factor=0.1,
@@ -148,18 +174,18 @@ def __init_session(self):
148174
self.api_key)
149175
self.session = session
150176

151-
def __init_log_manager(self):
177+
def __init_log_manager(self) -> None:
152178
self._log_manager = LogManager(
153179
self.endpoint, self.session, self.api_v2, self.launch_id,
154180
self.project, max_entry_number=self.log_batch_size,
155181
max_payload_size=self.log_batch_payload_size,
156182
verify_ssl=self.verify_ssl)
157183

158184
def finish_launch(self,
159-
end_time,
160-
status=None,
161-
attributes=None,
162-
**kwargs):
185+
end_time: str,
186+
status: str = None,
187+
attributes: Optional[Union[List, Dict]] = None,
188+
**kwargs: Any) -> Optional[str]:
163189
"""Finish launch.
164190
165191
:param end_time: Launch end time
@@ -169,7 +195,7 @@ def finish_launch(self,
169195
:param attributes: Launch attributes
170196
"""
171197
if self.launch_id is NOT_FOUND or not self.launch_id:
172-
logger.warning("Attempt to finish non-existent launch")
198+
logger.warning('Attempt to finish non-existent launch')
173199
return
174200
url = uri_join(self.base_url_v2, 'launch', self.launch_id, 'finish')
175201
request_payload = LaunchFinishRequest(
@@ -188,14 +214,14 @@ def finish_launch(self,
188214
return response.message
189215

190216
def finish_test_item(self,
191-
item_id,
192-
end_time,
193-
status=None,
194-
issue=None,
195-
attributes=None,
196-
description=None,
197-
retry=False,
198-
**kwargs):
217+
item_id: str,
218+
end_time: str,
219+
status: str = None,
220+
issue: Optional[Issue] = None,
221+
attributes: Optional[Union[List, Dict]] = None,
222+
description: str = None,
223+
retry: bool = False,
224+
**kwargs: Any) -> Optional[str]:
199225
"""Finish suite/case/step/nested step item.
200226
201227
:param item_id: ID of the test item
@@ -212,7 +238,7 @@ def finish_test_item(self,
212238
"True" or "False"
213239
"""
214240
if item_id is NOT_FOUND or not item_id:
215-
logger.warning("Attempt to finish non-existent item")
241+
logger.warning('Attempt to finish non-existent item')
216242
return
217243
url = uri_join(self.base_url_v2, 'item', item_id)
218244
request_payload = ItemFinishRequest(
@@ -234,7 +260,7 @@ def finish_test_item(self,
234260
logger.debug('response message: %s', response.message)
235261
return response.message
236262

237-
def get_item_id_by_uuid(self, uuid):
263+
def get_item_id_by_uuid(self, uuid: str) -> Optional[str]:
238264
"""Get test item ID by the given UUID.
239265
240266
:param uuid: UUID returned on the item start
@@ -245,7 +271,7 @@ def get_item_id_by_uuid(self, uuid):
245271
verify_ssl=self.verify_ssl).make()
246272
return response.id if response else None
247273

248-
def get_launch_info(self):
274+
def get_launch_info(self) -> Optional[Dict]:
249275
"""Get the current launch information.
250276
251277
:return dict: Launch information in dictionary
@@ -268,15 +294,15 @@ def get_launch_info(self):
268294
launch_info = {}
269295
return launch_info
270296

271-
def get_launch_ui_id(self):
297+
def get_launch_ui_id(self) -> Optional[Dict]:
272298
"""Get UI ID of the current launch.
273299
274300
:return: UI ID of the given launch. None if UI ID has not been found.
275301
"""
276302
launch_info = self.get_launch_info()
277303
return launch_info.get('id') if launch_info else None
278304

279-
def get_launch_ui_url(self):
305+
def get_launch_ui_url(self) -> Optional[str]:
280306
"""Get UI URL of the current launch.
281307
282308
:return: launch URL or all launches URL.
@@ -289,7 +315,7 @@ def get_launch_ui_url(self):
289315
if not mode:
290316
mode = self.mode
291317

292-
launch_type = "launches" if mode.upper() == 'DEFAULT' else 'userdebug'
318+
launch_type = 'launches' if mode.upper() == 'DEFAULT' else 'userdebug'
293319

294320
path = 'ui/#{project_name}/{launch_type}/all/{launch_id}'.format(
295321
project_name=self.project.lower(), launch_type=launch_type,
@@ -298,7 +324,7 @@ def get_launch_ui_url(self):
298324
logger.debug('get_launch_ui_url - ID: %s', self.launch_id)
299325
return url
300326

301-
def get_project_settings(self):
327+
def get_project_settings(self) -> Optional[Dict]:
302328
"""Get project settings.
303329
304330
:return: HTTP response in dictionary
@@ -308,7 +334,8 @@ def get_project_settings(self):
308334
verify_ssl=self.verify_ssl).make()
309335
return response.json if response else None
310336

311-
def log(self, time, message, level=None, attachment=None, item_id=None):
337+
def log(self, time: str, message: str, level: Optional[Union[int, str]] = None,
338+
attachment: Optional[Dict] = None, item_id: Optional[str] = None) -> None:
312339
"""Send log message to the Report Portal.
313340
314341
:param time: Time in UTC
@@ -319,18 +346,18 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
319346
"""
320347
self._log_manager.log(time, message, level, attachment, item_id)
321348

322-
def start(self):
349+
def start(self) -> None:
323350
"""Start the client."""
324351
self._log_manager.start()
325352

326353
def start_launch(self,
327-
name,
328-
start_time,
329-
description=None,
330-
attributes=None,
331-
rerun=False,
332-
rerun_of=None,
333-
**kwargs):
354+
name: str,
355+
start_time: str,
356+
description: Optional[str] = None,
357+
attributes: Optional[Union[List, Dict]] = None,
358+
rerun: bool = False,
359+
rerun_of: Optional[str] = None,
360+
**kwargs) -> Optional[str]:
334361
"""Start a new launch with the given parameters.
335362
336363
:param name: Launch name
@@ -346,12 +373,16 @@ def start_launch(self,
346373
# We are moving 'mode' param to the constructor, next code for the
347374
# transition period only.
348375
my_kwargs = dict(kwargs)
349-
if 'mode' in my_kwargs.keys():
350-
mode = my_kwargs['mode']
376+
mode = my_kwargs.get('mode')
377+
if 'mode' in my_kwargs:
378+
warnings.warn(
379+
message='Argument `mode` is deprecated since 5.2.5 and will be subject for removing in the '
380+
'next major version. Use `mode` argument in the class constructor instead.',
381+
category=DeprecationWarning,
382+
stacklevel=2
383+
)
351384
del my_kwargs['mode']
352-
if not mode:
353-
mode = self.mode
354-
else:
385+
if not mode:
355386
mode = self.mode
356387

357388
request_payload = LaunchStartRequest(
@@ -386,18 +417,18 @@ def start_launch(self,
386417
return self.launch_id
387418

388419
def start_test_item(self,
389-
name,
390-
start_time,
391-
item_type,
392-
description=None,
393-
attributes=None,
394-
parameters=None,
395-
parent_item_id=None,
396-
has_stats=True,
397-
code_ref=None,
398-
retry=False,
399-
test_case_id=None,
400-
**kwargs):
420+
name: str,
421+
start_time: str,
422+
item_type: str,
423+
description: Optional[str] = None,
424+
attributes: Optional[List[Dict]] = None,
425+
parameters: Optional[Dict] = None,
426+
parent_item_id: Optional[str] = None,
427+
has_stats: bool = True,
428+
code_ref: Optional[str] = None,
429+
retry: bool = False,
430+
test_case_id: Optional[str] = None,
431+
**_: Any) -> Optional[str]:
401432
"""Start case/step/nested step item.
402433
403434
:param name: Name of the test item
@@ -419,8 +450,7 @@ def start_test_item(self,
419450
:param test_case_id: A unique ID of the current step
420451
"""
421452
if parent_item_id is NOT_FOUND:
422-
logger.warning("Attempt to start item for non-existent parent "
423-
"item")
453+
logger.warning('Attempt to start item for non-existent parent item.')
424454
return
425455
if parent_item_id:
426456
url = uri_join(self.base_url_v2, 'item', parent_item_id)
@@ -455,11 +485,12 @@ def start_test_item(self,
455485
str(response.json))
456486
return item_id
457487

458-
def terminate(self, *args, **kwargs):
488+
def terminate(self, *_: Any, **__: Any) -> None:
459489
"""Call this to terminate the client."""
460490
self._log_manager.stop()
461491

462-
def update_test_item(self, item_uuid, attributes=None, description=None):
492+
def update_test_item(self, item_uuid: str, attributes: Optional[Union[List, Dict]] = None,
493+
description: Optional[str] = None) -> Optional[str]:
463494
"""Update existing test item at the Report Portal.
464495
465496
:param str item_uuid: Test item UUID returned on the item start
@@ -480,11 +511,11 @@ def update_test_item(self, item_uuid, attributes=None, description=None):
480511
logger.debug('update_test_item - Item: %s', item_id)
481512
return response.message
482513

483-
def current_item(self):
514+
def current_item(self) -> Optional[str]:
484515
"""Retrieve the last item reported by the client."""
485516
return self._item_stack[-1] if len(self._item_stack) > 0 else None
486517

487-
def clone(self):
518+
def clone(self) -> 'RPClient':
488519
"""Clone the client object, set current Item ID as cloned item ID.
489520
490521
:returns: Cloned client object
@@ -509,7 +540,7 @@ def clone(self):
509540
cloned._item_stack.append(current_item)
510541
return cloned
511542

512-
def __getstate__(self):
543+
def __getstate__(self) -> Dict[str, Any]:
513544
"""Control object pickling and return object fields as Dictionary.
514545
515546
:returns: object state dictionary
@@ -522,7 +553,7 @@ def __getstate__(self):
522553
del state['_log_manager']
523554
return state
524555

525-
def __setstate__(self, state):
556+
def __setstate__(self, state: Dict[str, Any]) -> None:
526557
"""Control object pickling, receives object state as Dictionary.
527558
528559
:param dict state: object state dictionary

0 commit comments

Comments
 (0)