1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
import subprocess
import pytest
from briefcase.exceptions import BriefcaseCommandError
from briefcase.integrations.xcode import XcodeCliTools
def test_not_installed(mock_tools):
"""If cmdline dev tools are not installed, raise an error."""
with pytest.raises(BriefcaseCommandError):
XcodeCliTools.ensure_command_line_tools_are_installed(mock_tools)
# xcode-select was invoked
mock_tools.subprocess.check_output.assert_called_once_with(
["xcode-select", "--install"], quiet=1
)
def test_installed(capsys, mock_tools):
"""If cmdline dev tools *are* installed, check passes without comment."""
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
cmd=["xcode-select", "--install"],
returncode=1,
)
# Check passes without an error...
XcodeCliTools.ensure_command_line_tools_are_installed(mock_tools)
# ... xcode-select was invoked
mock_tools.subprocess.check_output.assert_called_once_with(
["xcode-select", "--install"],
quiet=1,
)
# ...and the user is none the wiser
out = capsys.readouterr().out
assert len(out) == 0
def test_unsure_if_installed(capsys, mock_tools):
"""If xcode-select returns something odd, mention it but don't break."""
mock_tools.subprocess.check_output.side_effect = subprocess.CalledProcessError(
cmd=["xcode-select", "--install"],
returncode=69,
)
# Check passes without an error...
XcodeCliTools.ensure_command_line_tools_are_installed(mock_tools)
# ... xcode-select was invoked
mock_tools.subprocess.check_output.assert_called_once_with(
["xcode-select", "--install"], quiet=1
)
# ...but stdout contains a warning
out = capsys.readouterr().out
assert "************" in out
|