Skip to content

Commit

Permalink
Use timedelta
Browse files Browse the repository at this point in the history
  • Loading branch information
priitlatt committed Oct 29, 2024
1 parent b55a0fa commit 16858d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/codemagic/models/xctests/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import re
from abc import ABC
from abc import abstractmethod
from collections import defaultdict
from datetime import datetime
from typing import Dict
from datetime import timedelta
from typing import Iterator
from typing import List
from typing import Optional
Expand Down Expand Up @@ -244,21 +243,21 @@ def _get_test_case_skipped(cls, xc_test_case: XcTestNode) -> Optional[Skipped]:

@classmethod
def parse_xcresult_test_node_duration_value(cls, xc_duration: str) -> float:
counters: Dict[str, float] = defaultdict(float)
duration = timedelta()

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

return counters["minutes"] * 60.0 + counters["seconds"]
return duration.total_seconds()

@classmethod
def _get_test_node_duration(cls, xc_test_case: XcTestNode) -> float:
Expand Down
2 changes: 2 additions & 0 deletions tests/models/xctests/converter/test_xcode_16_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def test_converter(mock_datetime, expected_properties):
("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),
Expand Down

0 comments on commit 16858d0

Please sign in to comment.