Skip to content

Commit

Permalink
Do not cache is legacy check return value
Browse files Browse the repository at this point in the history
  • Loading branch information
priitlatt committed Oct 16, 2024
1 parent 05dcd15 commit d944e9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/codemagic/models/xctests/xcresulttool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ def __init__(self, message: str, stderr: str):
class XcResultTool(RunningCliAppMixin, StringConverterMixin):
@classmethod
@lru_cache(1)
def _get_selected_xcode(cls):
return Xcode.get_selected()

@classmethod
def is_legacy(cls) -> bool:
"""
With Xcode 16.0 `xcresulttool get` API was changed. Check if activated
xcresulttool is from Xcode 16.0+ (not legacy) or otherwise (is legacy).
"""
xcode = Xcode.get_selected()
xcode = cls._get_selected_xcode()
return Version("16") > xcode.version

@classmethod
Expand Down
9 changes: 4 additions & 5 deletions tests/models/xctests/test_xcresulttool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
from codemagic.models.xctests import XcResultTool
from codemagic.models.xctests.xcresulttool import Xcode
from packaging.version import Version


Expand All @@ -12,8 +11,8 @@
)
def test_is_legacy(xcode_version: str):
mock_xcode = mock.MagicMock(version=Version(xcode_version))
with mock.patch.object(Xcode, "get_selected", new=mock.MagicMock(return_value=mock_xcode)):
assert XcResultTool.is_legacy()
with mock.patch.object(XcResultTool, "_get_selected_xcode", new=mock.MagicMock(return_value=mock_xcode)):
assert XcResultTool.is_legacy() is True


@pytest.mark.parametrize(
Expand All @@ -22,5 +21,5 @@ def test_is_legacy(xcode_version: str):
)
def test_is_not_legacy(xcode_version: str):
mock_xcode = mock.MagicMock(version=Version(xcode_version))
with mock.patch.object(Xcode, "get_selected", new=mock.MagicMock(return_value=mock_xcode)):
assert not XcResultTool.is_legacy()
with mock.patch.object(XcResultTool, "_get_selected_xcode", new=mock.MagicMock(return_value=mock_xcode)):
assert XcResultTool.is_legacy() is False

0 comments on commit d944e9f

Please sign in to comment.