Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHORE: Warn user in case of no scheme or multiple schemes #59

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/cicd/ios/project/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@ def xcworkspace_path(self) -> t.Optional[Path]:

@cached_property
def schemes(self) -> t.List[str]:
return [
detected = [
p.with_suffix('').name
for p in self.workdir.glob('*.xcodeproj/xcshareddata/xcschemes/*.xcscheme')
]
if not detected:
logger.warning(
'Detect no shared scheme. Please mark your scheme as shared in Xcode'
)
if len(detected) > 1:
logger.warning(
f'Detect multiple schemes: {detected}. '
f'The first one will be chosen: {detected[0]}. '
f'To specify the scheme, use the `-scheme` option.'
)
return detected

@property
def scheme(self) -> t.Optional[str]:
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
@pytest.fixture
def bag():
return mock.MagicMock()


@pytest.fixture(autouse=True)
def change_workdir(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
3 changes: 1 addition & 2 deletions tests/ios/mixin/test_version_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def gen_pbxproj_content(version: str, build_number: int) -> str:


@pytest.fixture
def pbxproj_path(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def pbxproj_path(tmp_path):
path = tmp_path / 'EX.xcodeproj' / 'project.pbxproj'
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(gen_pbxproj_content(version='0.0.1', build_number=1))
Expand Down
63 changes: 43 additions & 20 deletions tests/ios/project/test_project_metadata.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
from pathlib import Path
from unittest import mock

import pytest

from cicd.ios.project.metadata import Metadata


@pytest.fixture
def bag(tmp_path: Path):
this = mock.MagicMock()
this.xcodeproj_path = tmp_path / 'EX.xcodeproj'
this.xcworkspace_path = tmp_path / 'EX.xcworkspace'
this.xcodeproj_path.write_text('')
this.xcworkspace_path.mkdir()
with mock.patch(
'cicd.ios.project.metadata.Metadata.workdir',
new_callable=mock.PropertyMock,
) as mock_workdir:
mock_workdir.return_value = tmp_path
yield this


def test_project_metadata_mixin(monkeypatch, bag):
metadata = Metadata()
assert metadata.project_name == 'EX'
assert metadata.xcodeproj_path == bag.xcodeproj_path
assert metadata.xcworkspace_path == bag.xcworkspace_path
def schemes():
return ['EX']


@pytest.fixture
def sut(tmp_path, schemes):
(tmp_path / 'EX.xcworkspace').mkdir()
(tmp_path / 'EX.xcodeproj').mkdir()
for scheme in schemes:
scheme_path = (
tmp_path
/ 'EX.xcodeproj'
/ 'xcshareddata'
/ 'xcschemes'
/ f'{scheme}.xcscheme'
)
scheme_path.parent.mkdir(parents=True, exist_ok=True)
scheme_path.touch()
return Metadata()


def test_project_metadata_mixin(sut: Metadata):
assert sut.project_name == 'EX'
assert sut.schemes == ['EX']
assert sut.scheme == 'EX'
assert sut.workdir == Path()
assert sut.xcodeproj_path == Path('EX.xcodeproj')
assert sut.pbxproj_path == Path('EX.xcodeproj/project.pbxproj')
assert sut.xcworkspace_path == Path('EX.xcworkspace')


@pytest.mark.parametrize('schemes', [[]])
def test_no_scheme_warning(sut: Metadata, caplog):
assert sut.schemes == []
assert sut.scheme is None
assert 'Detect no shared scheme' in caplog.text


@pytest.mark.parametrize('schemes', [['EX', 'EX2']])
def test_multiple_schemes_warning(sut: Metadata, caplog):
assert sut.scheme == 'EX'
assert sut.schemes == ['EX', 'EX2']
assert 'Detect multiple schemes' in caplog.text