Skip to content

Commit

Permalink
Fix XCResult testcase duration parsing (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
priitlatt authored Oct 29, 2024
1 parent 153ca7d commit 77f1cc9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.54.1
-------------

**Bugfixes**
- Fix testcase duration parsing from `XCResult` bundle when using Xcode 16.0+. [PR #433](https://github.com/codemagic-ci-cd/cli-tools/pull/433)

Version 0.54.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "codemagic-cli-tools"
version = "0.54.0"
version = "0.54.1"
description = "CLI tools used in Codemagic builds"
readme = "README.md"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion src/codemagic/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "codemagic-cli-tools"
__description__ = "CLI tools used in Codemagic builds"
__version__ = "0.54.0.dev"
__version__ = "0.54.1.dev"
__url__ = "https://github.com/codemagic-ci-cd/cli-tools"
__licence__ = "GNU General Public License v3.0"
24 changes: 20 additions & 4 deletions src/codemagic/models/xctests/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from abc import ABC
from abc import abstractmethod
from datetime import datetime
from datetime import timedelta
from typing import Iterator
from typing import List
from typing import Optional
Expand Down Expand Up @@ -240,15 +241,30 @@ def _get_test_case_skipped(cls, xc_test_case: XcTestNode) -> Optional[Skipped]:

return Skipped(message="\n".join(skipped_messages))

@classmethod
def parse_xcresult_test_node_duration_value(cls, xc_duration: str) -> float:
duration = timedelta()

try:
for part in xc_duration.split():
part_value = float(part[:-1].replace(",", "."))
if part.endswith("s"):
duration += timedelta(seconds=part_value)
elif part.endswith("m"):
duration += timedelta(minutes=part_value)
else:
raise ValueError("Unknown duration unit")
except ValueError as ve:
raise ValueError("Invalid duration", xc_duration) from ve

return duration.total_seconds()

@classmethod
def _get_test_node_duration(cls, xc_test_case: XcTestNode) -> float:
if not xc_test_case.duration:
return 0.0

duration = xc_test_case.duration.replace(",", ".")
if duration.endswith("s"):
duration = duration[:-1]
return float(duration)
return cls.parse_xcresult_test_node_duration_value(xc_test_case.duration)

@classmethod
def _get_test_case(cls, xc_test_case: XcTestNode, xc_test_suite: XcTestNode) -> TestCase:
Expand Down
2 changes: 1 addition & 1 deletion src/codemagic/models/xctests/xcresult/xcode_16_xcresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def from_dict(cls, d: Dict[str, Any]) -> XcTestInsight:
class XcTests(XcModel):
"""
Model definitions for `xcresulttool get test-results tests` output.
Check schema with `xcrun xcresulttool help get test-results tests.
Check schema with `xcrun xcresulttool help get test-results tests`.
"""

devices: List[XcDevice]
Expand Down
23 changes: 23 additions & 0 deletions tests/models/xctests/converter/test_xcode_16_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,26 @@ def test_converter(mock_datetime, expected_properties):
time=3.0,
error=Error(message="banaanUITests.swift:40: failed - Bad UI", type="Failure"),
)


@pytest.mark.parametrize(
("duration", "expected_value"),
(
("0,00045s", 0.00045),
("0,002s", 0.002),
("0,0052s", 0.0052),
("0,26s", 0.26),
("0,2s", 0.2),
("2s", 2.0),
("3s", 3.0),
("1m 3,01s", 63.01),
("1m 3.01s", 63.01),
("1m 4s", 64.0),
("2m 26s", 146.0),
("5m 3s", 303.0),
("6m", 360.0),
),
)
def test_parse_xcresult_test_node_duration_value(duration, expected_value):
value = Xcode16XcResultConverter.parse_xcresult_test_node_duration_value(duration)
assert value == pytest.approx(expected_value)

0 comments on commit 77f1cc9

Please sign in to comment.