Skip to content

Commit daca0ae

Browse files
committed
Update types
1 parent 68666dc commit daca0ae

File tree

7 files changed

+63
-63
lines changed

7 files changed

+63
-63
lines changed

robotframework_reportportal/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import binascii
1818
import fnmatch
1919
import re
20-
from typing import Iterable, Optional, Tuple
20+
from collections.abc import Iterable
21+
from typing import Optional
2122

2223

2324
def translate_glob_to_regex(pattern: Optional[str]) -> Optional[re.Pattern]:
@@ -48,7 +49,7 @@ def match_pattern(pattern: Optional[re.Pattern], line: Optional[str]) -> bool:
4849
return pattern.fullmatch(line) is not None
4950

5051

51-
def replace_patterns(text: str, patterns: Iterable[Tuple[re.Pattern, str]]) -> str:
52+
def replace_patterns(text: str, patterns: Iterable[tuple[re.Pattern, str]]) -> str:
5253
"""Replace given patterns in the text."""
5354
result = text
5455
for p, repl in patterns:

robotframework_reportportal/listener.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import warnings
2222
from functools import wraps
2323
from mimetypes import guess_type
24-
from typing import Any, Dict, List, Optional, Union
24+
from typing import Any, Optional, Union
2525
from warnings import warn
2626

2727
from reportportal_client.helpers import LifoQueue, guess_content_type_from_bytes, is_binary
@@ -94,7 +94,7 @@ def wrap(*args, **kwargs):
9494
return wrap
9595

9696

97-
def process_keyword_names_and_tags(matcher_list: List[KeywordMatch], pattern_str: str) -> None:
97+
def process_keyword_names_and_tags(matcher_list: list[KeywordMatch], pattern_str: str) -> None:
9898
"""Pick name or pattern string, parse it and add to the matcher list.
9999
100100
:param matcher_list: List of keyword matchers to add to
@@ -115,8 +115,8 @@ class listener:
115115
_items: LifoQueue[Union[Keyword, Launch, Suite, Test]]
116116
_service: Optional[RobotService]
117117
_variables: Optional[Variables]
118-
_remove_keyword_filters: List[KeywordMatch] = []
119-
_flatten_keyword_filters: List[KeywordMatch] = []
118+
_remove_keyword_filters: list[KeywordMatch] = []
119+
_flatten_keyword_filters: list[KeywordMatch] = []
120120
_remove_all_keyword_content: bool = False
121121
_remove_data_passed_tests: bool = False
122122
ROBOT_LISTENER_API_VERSION = 2
@@ -127,7 +127,7 @@ def __init__(self) -> None:
127127
self._service = None
128128
self._variables = None
129129

130-
def _build_msg_struct(self, message: Dict[str, Any]) -> LogMessage:
130+
def _build_msg_struct(self, message: dict[str, Any]) -> LogMessage:
131131
"""Check if the given message comes from our custom logger or not.
132132
133133
:param message: Message passed by the Robot Framework
@@ -271,7 +271,7 @@ def _log_message(self, message: LogMessage) -> None:
271271
self.__post_log_message(message)
272272

273273
@check_rp_enabled
274-
def log_message(self, message: Dict) -> None:
274+
def log_message(self, message: dict) -> None:
275275
"""Send log message to the Report Portal.
276276
277277
:param message: Message passed by the Robot Framework
@@ -280,7 +280,7 @@ def log_message(self, message: Dict) -> None:
280280
self._log_message(msg)
281281

282282
@check_rp_enabled
283-
def log_message_with_image(self, msg: Dict, image: str):
283+
def log_message_with_image(self, msg: dict, image: str):
284284
"""Send log message to the ReportPortal.
285285
286286
:param msg: Message passed by the Robot Framework
@@ -363,7 +363,7 @@ def _process_keyword_flatten(self):
363363
continue
364364
process_keyword_names_and_tags(self._flatten_keyword_filters, pattern_str)
365365

366-
def start_launch(self, attributes: Dict[str, Any], ts: Optional[Any] = None) -> None:
366+
def start_launch(self, attributes: dict[str, Any], ts: Optional[Any] = None) -> None:
367367
"""Start a new launch at the ReportPortal.
368368
369369
:param attributes: Dictionary passed by the Robot Framework
@@ -385,7 +385,7 @@ def start_launch(self, attributes: Dict[str, Any], ts: Optional[Any] = None) ->
385385
rerun_of=self.variables.rerun_of,
386386
)
387387

388-
def finish_launch(self, attributes: Dict[str, Any], ts: Optional[Any] = None) -> None:
388+
def finish_launch(self, attributes: dict[str, Any], ts: Optional[Any] = None) -> None:
389389
"""Finish started launch at the ReportPortal.
390390
391391
:param attributes: Dictionary passed by the Robot Framework
@@ -396,7 +396,7 @@ def finish_launch(self, attributes: Dict[str, Any], ts: Optional[Any] = None) ->
396396
self.service.finish_launch(launch=launch, ts=ts)
397397

398398
@check_rp_enabled
399-
def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> None:
399+
def start_suite(self, name: str, attributes: dict, ts: Optional[Any] = None) -> None:
400400
"""Start a new test suite at the ReportPortal.
401401
402402
:param name: Test suite name
@@ -425,7 +425,7 @@ def _log_keyword_content_removed(self, item_id: str, timestamp: str) -> None:
425425
self._log_data_removed(item_id, timestamp, REMOVED_KEYWORD_CONTENT_LOG)
426426

427427
@check_rp_enabled
428-
def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
428+
def end_suite(self, _: Optional[str], attributes: dict, ts: Optional[Any] = None) -> None:
429429
"""Finish started test suite at the ReportPortal.
430430
431431
:param _: Test suite name
@@ -444,7 +444,7 @@ def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None
444444
self.finish_launch(attributes, ts)
445445

446446
@check_rp_enabled
447-
def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> None:
447+
def start_test(self, name: str, attributes: dict, ts: Optional[Any] = None) -> None:
448448
"""Start a new test case at the ReportPortal.
449449
450450
:param name: Test case name
@@ -461,7 +461,7 @@ def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> N
461461
self._add_current_item(test)
462462

463463
@check_rp_enabled
464-
def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
464+
def end_test(self, _: Optional[str], attributes: dict, ts: Optional[Any] = None) -> None:
465465
"""Finish started test case at the ReportPortal.
466466
467467
:param _: Test case name
@@ -500,7 +500,7 @@ def _log_keyword_content_flattened(self, item_id: str, timestamp: str) -> None:
500500
self._log_data_removed(item_id, timestamp, FLATTENED_KEYWORD_CONTENT_LOG)
501501

502502
@check_rp_enabled
503-
def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> None:
503+
def start_keyword(self, name: str, attributes: dict, ts: Optional[Any] = None) -> None:
504504
"""Start a new keyword(test step) at the ReportPortal.
505505
506506
:param name: Keyword name
@@ -547,7 +547,7 @@ def _do_end_keyword(self, keyword: Keyword, ts: Optional[str] = None) -> None:
547547
self.service.finish_keyword(keyword=keyword, ts=ts)
548548

549549
@check_rp_enabled
550-
def end_keyword(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
550+
def end_keyword(self, _: Optional[str], attributes: dict, ts: Optional[Any] = None) -> None:
551551
"""Finish started keyword at the ReportPortal.
552552
553553
:param _: Keyword name

robotframework_reportportal/logger.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def log_free_memory(self):
3535
},
3636
)
3737
"""
38-
from typing import Dict, Optional
38+
from typing import Optional
3939

4040
from robot.api import logger
4141

@@ -46,7 +46,7 @@ def write(
4646
msg: str,
4747
level: str = "INFO",
4848
html: bool = False,
49-
attachment: Optional[Dict[str, str]] = None,
49+
attachment: Optional[dict[str, str]] = None,
5050
launch_log: bool = False,
5151
) -> None:
5252
"""Write the message to the log file using the given level.
@@ -73,12 +73,12 @@ def write(
7373
logger.write(log_message, level, html)
7474

7575

76-
def trace(msg: str, html: bool = False, attachment: Optional[Dict[str, str]] = None, launch_log: bool = False) -> None:
76+
def trace(msg: str, html: bool = False, attachment: Optional[dict[str, str]] = None, launch_log: bool = False) -> None:
7777
"""Write the message to the log file using the ``TRACE`` level."""
7878
write(msg, "TRACE", html, attachment, launch_log)
7979

8080

81-
def debug(msg: str, html: bool = False, attachment: Optional[Dict[str, str]] = None, launch_log: bool = False) -> None:
81+
def debug(msg: str, html: bool = False, attachment: Optional[dict[str, str]] = None, launch_log: bool = False) -> None:
8282
"""Write the message to the log file using the ``DEBUG`` level."""
8383
write(msg, "DEBUG", html, attachment, launch_log)
8484

@@ -87,7 +87,7 @@ def info(
8787
msg: str,
8888
html: bool = False,
8989
also_console: bool = False,
90-
attachment: Optional[Dict[str, str]] = None,
90+
attachment: Optional[dict[str, str]] = None,
9191
launch_log: bool = False,
9292
):
9393
"""Write the message to the log file using the ``INFO`` level.
@@ -99,12 +99,12 @@ def info(
9999
console(msg)
100100

101101

102-
def warn(msg: str, html: bool = False, attachment: Optional[Dict[str, str]] = None, launch_log: bool = False) -> None:
102+
def warn(msg: str, html: bool = False, attachment: Optional[dict[str, str]] = None, launch_log: bool = False) -> None:
103103
"""Write the message to the log file using the ``WARN`` level."""
104104
write(msg, "WARN", html, attachment, launch_log)
105105

106106

107-
def error(msg: str, html: bool = False, attachment: Optional[Dict[str, str]] = None, launch_log: bool = False) -> None:
107+
def error(msg: str, html: bool = False, attachment: Optional[dict[str, str]] = None, launch_log: bool = False) -> None:
108108
"""Write the message to the log file using the ``ERROR`` level."""
109109
write(msg, "ERROR", html, attachment, launch_log)
110110

robotframework_reportportal/model.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import os
1818
import re
1919
from abc import ABC, abstractmethod
20-
from typing import Any, Callable, Dict, List, Optional, Union
20+
from collections.abc import Callable
21+
from typing import Any, Optional, Union
2122

2223
from reportportal_client.helpers import gen_attributes
2324

@@ -36,7 +37,7 @@ class Entity:
3637
remove_origin: Optional[Any]
3738
rp_item_id: Optional[str]
3839
parent: Optional["Entity"]
39-
skipped_keywords: List["Keyword"]
40+
skipped_keywords: list["Keyword"]
4041
posted: bool
4142

4243
def __init__(self, entity_type: str, parent: Optional["Entity"]):
@@ -64,7 +65,7 @@ def rp_parent_item_id(self):
6465
class LogMessage(str):
6566
"""Class represents Robot Framework messages."""
6667

67-
attachment: Optional[Dict[str, str]]
68+
attachment: Optional[dict[str, str]]
6869
launch_log: bool
6970
item_id: Optional[str]
7071
level: str
@@ -84,9 +85,9 @@ def __init__(self, message: str):
8485
class Keyword(Entity):
8586
"""Class represents Robot Framework keyword."""
8687

87-
robot_attributes: Dict[str, Any]
88-
args: List[str]
89-
assign: List[str]
88+
robot_attributes: dict[str, Any]
89+
args: list[str]
90+
assign: list[str]
9091
doc: str
9192
end_time: str
9293
keyword_name: str
@@ -95,11 +96,11 @@ class Keyword(Entity):
9596
name: str
9697
start_time: str
9798
status: str
98-
tags: List[str]
99+
tags: list[str]
99100
type: str = "KEYWORD"
100-
skipped_logs: List[LogMessage]
101+
skipped_logs: list[LogMessage]
101102

102-
def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Entity):
103+
def __init__(self, name: str, robot_attributes: dict[str, Any], parent: Entity):
103104
"""Initialize required attributes.
104105
105106
:param name: Name of the keyword
@@ -142,7 +143,7 @@ def get_type(self) -> str:
142143
else:
143144
return "STEP"
144145

145-
def update(self, attributes: Dict[str, Any]) -> "Keyword":
146+
def update(self, attributes: dict[str, Any]) -> "Keyword":
146147
"""Update keyword attributes on keyword finish.
147148
148149
:param attributes: Suite attributes passed through the listener
@@ -155,22 +156,22 @@ def update(self, attributes: Dict[str, Any]) -> "Keyword":
155156
class Suite(Entity):
156157
"""Class represents Robot Framework test suite."""
157158

158-
robot_attributes: Union[List[str], Dict[str, Any]]
159+
robot_attributes: Union[list[str], dict[str, Any]]
159160
doc: str
160161
end_time: str
161162
longname: str
162163
message: str
163-
metadata: Dict[str, str]
164+
metadata: dict[str, str]
164165
name: str
165166
robot_id: str
166167
start_time: Optional[str]
167168
statistics: str
168169
status: str
169-
suites: List[str]
170-
tests: List[str]
170+
suites: list[str]
171+
tests: list[str]
171172
total_tests: int
172173

173-
def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Optional[Entity] = None):
174+
def __init__(self, name: str, robot_attributes: dict[str, Any], parent: Optional[Entity] = None):
174175
"""Initialize required attributes.
175176
176177
:param name: Suite name
@@ -194,7 +195,7 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Optional
194195
self.total_tests = robot_attributes["totaltests"]
195196

196197
@property
197-
def attributes(self) -> Optional[List[Dict[str, str]]]:
198+
def attributes(self) -> Optional[list[dict[str, str]]]:
198199
"""Get Suite attributes."""
199200
if self.metadata is None or not self.metadata:
200201
return None
@@ -206,7 +207,7 @@ def source(self) -> str:
206207
if self.robot_attributes.get("source") is not None:
207208
return os.path.relpath(self.robot_attributes["source"], os.getcwd())
208209

209-
def update(self, attributes: Dict[str, Any]) -> "Suite":
210+
def update(self, attributes: dict[str, Any]) -> "Suite":
210211
"""Update suite attributes on suite finish.
211212
212213
:param attributes: Suite attributes passed through the listener
@@ -221,10 +222,10 @@ def update(self, attributes: Dict[str, Any]) -> "Suite":
221222
class Launch(Suite):
222223
"""Class represents Robot Framework test suite."""
223224

224-
launch_attributes: Optional[List[Dict[str, str]]]
225+
launch_attributes: Optional[list[dict[str, str]]]
225226
type: str = "LAUNCH"
226227

227-
def __init__(self, name: str, robot_attributes: Dict[str, Any], launch_attributes: Optional[List[str]]):
228+
def __init__(self, name: str, robot_attributes: dict[str, Any], launch_attributes: Optional[list[str]]):
228229
"""Initialize required attributes.
229230
230231
:param name: Launch name
@@ -236,7 +237,7 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], launch_attribute
236237
self.type = "LAUNCH"
237238

238239
@property
239-
def attributes(self) -> Optional[List[Dict[str, str]]]:
240+
def attributes(self) -> Optional[list[dict[str, str]]]:
240241
"""Get Launch attributes."""
241242
return self.launch_attributes
242243

@@ -245,9 +246,9 @@ class Test(Entity):
245246
"""Class represents Robot Framework test case."""
246247

247248
_critical: str
248-
_tags: List[str]
249-
robot_attributes: Dict[str, Any]
250-
test_attributes: Optional[List[Dict[str, str]]]
249+
_tags: list[str]
250+
robot_attributes: dict[str, Any]
251+
test_attributes: Optional[list[dict[str, str]]]
251252
doc: str
252253
end_time: str
253254
longname: str
@@ -258,7 +259,7 @@ class Test(Entity):
258259
status: str
259260
template: str
260261

261-
def __init__(self, name: str, robot_attributes: Dict[str, Any], test_attributes: List[str], parent: Entity):
262+
def __init__(self, name: str, robot_attributes: dict[str, Any], test_attributes: list[str], parent: Entity):
262263
"""Initialize required attributes.
263264
264265
:param name: Name of the test
@@ -287,12 +288,12 @@ def critical(self) -> bool:
287288
return self._critical in ("yes", True)
288289

289290
@property
290-
def tags(self) -> List[str]:
291+
def tags(self) -> list[str]:
291292
"""Get list of test tags excluding test_case_id."""
292293
return [tag for tag in self._tags if not tag.startswith(TEST_CASE_ID_SIGN)]
293294

294295
@property
295-
def attributes(self) -> Optional[List[Dict[str, str]]]:
296+
def attributes(self) -> Optional[list[dict[str, str]]]:
296297
"""Get Test attributes."""
297298
return self.test_attributes + gen_attributes(self.tags)
298299

@@ -323,7 +324,7 @@ def test_case_id(self) -> Optional[str]:
323324
# generate it if not
324325
return "{0}:{1}".format(self.source, self.name)
325326

326-
def update(self, attributes: Dict[str, Any]) -> "Test":
327+
def update(self, attributes: dict[str, Any]) -> "Test":
327328
"""Update test attributes on test finish.
328329
329330
:param attributes: Suite attributes passed through the listener

0 commit comments

Comments
 (0)