Skip to content

Commit d990560

Browse files
committed
Refactor helpers.common_helpers.gen_attributes function
1 parent 902a97b commit d990560

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- `helpers.common_helpers.gen_attributes` function now accepts refactored, by @HardNorth
46

57
## [5.6.1]
68
### Added

reportportal_client/helpers/common_helpers.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
ATTRIBUTE_LENGTH_LIMIT: int = 128
4040
TRUNCATE_REPLACEMENT: str = "..."
4141
BYTES_TO_READ_FOR_DETECTION = 128
42+
ATTRIBUTE_DELIMITER = ":"
4243

4344
CONTENT_TYPE_TO_EXTENSIONS = MappingProxyType(
4445
{
@@ -167,20 +168,18 @@ def gen_attributes(rp_attributes: Iterable[str]) -> List[Dict[str, str]]:
167168
:return: Correctly created list of dictionaries
168169
to be passed to RP
169170
"""
170-
attrs = []
171-
for rp_attr in rp_attributes:
172-
try:
173-
key, value = rp_attr.split(":")
174-
attr_dict = {"key": key, "value": value}
175-
except ValueError as exc:
176-
logger.debug(str(exc))
177-
attr_dict = {"value": rp_attr}
178-
179-
if all(attr_dict.values()):
180-
attrs.append(attr_dict)
171+
attributes = []
172+
for attr in rp_attributes:
173+
if not attr:
181174
continue
182-
logger.debug(f'Failed to process "{rp_attr}" attribute, attribute value should not be empty.')
183-
return attrs
175+
value = attr
176+
if ATTRIBUTE_DELIMITER in attr:
177+
key, value = attr.split(ATTRIBUTE_DELIMITER, 1)
178+
attribute = {"key": key, "value": value}
179+
else:
180+
attribute = {"value": value}
181+
attributes.append(attribute)
182+
return attributes
184183

185184

186185
def get_launch_sys_attrs() -> Dict[str, str]:

tests/helpers/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_gen_attributes():
3636
"""Test functionality of the gen_attributes function."""
3737
expected_out = [{"value": "Tag"}, {"key": "Key", "value": "Value"}]
3838
out = gen_attributes(["Tag", "Key:Value", ""])
39-
assert expected_out == out
39+
assert out == expected_out
4040

4141

4242
@mock.patch("reportportal_client.helpers.common_helpers.system", mock.Mock(return_value="linux"))

0 commit comments

Comments
 (0)