Пример #1
0
def test_installed_no_minimum_version():
    "If Xcode is installed, but there's no minimum version, check is satisfied."
    sub = mock.MagicMock()
    sub.check_output.return_value = "Xcode 11.2.1\nBuild version 11B500\n"

    # Check passes without an error.
    ensure_xcode_is_installed(sub=sub)
def test_installed_extra_output(capsys, xcode):
    """If Xcode but outputs extra content, the check is still satisfied."""
    # This specific output was seen in the wild with Xcode 13.2.1; see #668
    command = mock.MagicMock()
    command.logger = Log()
    command.subprocess.check_output.return_value = "\n".join([
        "objc[86306]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x20d17ab90) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1084b82c8). One of the two will be used. Which one is undefined."  # noqa: E501
        "objc[86306]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x20d17abe0) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1084b8318). One of the two will be used. Which one is undefined.",  # noqa: E501
        "Xcode 13.2.1",
        "Build version 13C100",
    ])

    # Check passes without an error.
    ensure_xcode_is_installed(command,
                              xcode_location=xcode,
                              min_version=(11, 1))

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ["xcodebuild", "-version"],
        stderr=subprocess.STDOUT,
    )

    # No warning generated.
    out = capsys.readouterr().out
    assert "WARNING" not in out
Пример #3
0
def test_not_installed():
    "If Xcode is not installed, raise an error."
    sub = mock.MagicMock()
    sub.check_output.side_effect = subprocess.CalledProcessError(
        cmd=['xcodebuild', '-version'], returncode=1)

    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(sub=sub)
Пример #4
0
def test_installed_with_minimum_version_failure(min_version, version):
    "Check XCode fail to meet a minimum version requirement."
    sub = mock.MagicMock()
    sub.check_output.return_value = "Xcode {version}\nBuild version 11B500\n".format(
        version=version)

    # Check raises an error.
    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(min_version=min_version, sub=sub)
def test_not_installed(tmp_path):
    """If Xcode is not installed, raise an error."""
    command = mock.MagicMock()
    command.subprocess.check_output.side_effect = subprocess.CalledProcessError(
        cmd=["xcode-select", "-p"], returncode=2)

    # Test a location where Xcode *won't* be installed
    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(command)
Пример #6
0
    def verify_tools(self):
        if self.host_os != 'Darwin':
            raise BriefcaseCommandError("""
iOS applications require Xcode, which is only available on macOS.
""")

        # Require XCode 10.0.0. There's no particular reason for this
        # specific version, other than it's a nice round number that's
        # not *that* old at time of writing.
        ensure_xcode_is_installed(min_version=(10, 0, 0))
Пример #7
0
def test_unexpected_version_output(capsys):
    "If xcodebuild returns unexpected output, assume it's ok..."
    sub = mock.MagicMock()
    sub.check_output.return_value = "Wibble Wibble Wibble\n"

    # Check passes without an error...
    ensure_xcode_is_installed(min_version=(11, 2, 1), sub=sub)

    # ...but stdout contains a warning
    out = capsys.readouterr().out
    assert '************' in out
Пример #8
0
def test_installed_with_minimum_version_success(min_version, version, capsys):
    "Check XCode can meet a minimum version requirement."
    sub = mock.MagicMock()
    sub.check_output.return_value = "Xcode {version}\nBuild version 11B500\n".format(
        version=version)

    # Check passes without an error.
    ensure_xcode_is_installed(min_version=min_version, sub=sub)

    # Make sure the warning wasn't displayed.
    out = capsys.readouterr().out
    assert "WARNING" not in out
Пример #9
0
def test_installed_no_minimum_version(xcode):
    "If Xcode is installed, but there's no minimum version, check is satisfied."
    command = mock.MagicMock()
    command.subprocess.check_output.return_value = "Xcode 11.2.1\nBuild version 11B500\n"

    # Check passes without an error.
    ensure_xcode_is_installed(command, xcode_location=xcode)

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ['xcodebuild', '-version'],
        universal_newlines=True,
    )
Пример #10
0
def test_exists_but_not_installed(xcode):
    "If the Xcode folder exists, but xcodebuild breaks, raise an error."
    command = mock.MagicMock()
    command.subprocess.check_output.side_effect = subprocess.CalledProcessError(
        cmd=['xcodebuild', '-version'], returncode=1)

    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(command, xcode_location=xcode)

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ['xcodebuild', '-version'],
        universal_newlines=True,
    )
Пример #11
0
def test_not_installed(tmp_path):
    "If Xcode is not installed, raise an error."
    command = mock.MagicMock()
    command.subprocess.check_output.side_effect = subprocess.CalledProcessError(
        cmd=['xcodebuild', '-version'], returncode=1)

    # Test a location where Xcode *won't* be installed
    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(
            command,
            xcode_location=tmp_path / 'Xcode.app',
        )

    # xcode-select was not invoked
    command.subprocess.check_output.assert_not_called()
def test_installed_no_minimum_version(xcode):
    """If Xcode is installed, but there's no minimum version, check is
    satisfied."""
    command = mock.MagicMock()
    command.subprocess.check_output.return_value = (
        "Xcode 11.2.1\nBuild version 11B500\n")

    # Check passes without an error.
    ensure_xcode_is_installed(command, xcode_location=xcode)

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ["xcodebuild", "-version"],
        stderr=subprocess.STDOUT,
    )
def test_exists_but_corrupted(xcode):
    """If the Xcode folder exists, but xcodebuild breaks, raise an error."""
    command = mock.MagicMock()
    command.subprocess.check_output.side_effect = subprocess.CalledProcessError(
        cmd=["xcodebuild", "-version"], returncode=1)
    command.subprocess.check_output.side_effect.output = "Badness occurred."

    with pytest.raises(BriefcaseCommandError,
                       match=r"should return the current Xcode version"):
        ensure_xcode_is_installed(command, xcode_location=xcode)

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ["xcodebuild", "-version"],
        stderr=subprocess.STDOUT,
    )
def test_installed_with_minimum_version_failure(min_version, version, xcode):
    """Check XCode fail to meet a minimum version requirement."""
    command = mock.MagicMock()
    command.subprocess.check_output.return_value = (
        f"Xcode {version}\nBuild version 11B500\n")

    # Check raises an error.
    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(
            command,
            min_version=min_version,
            xcode_location=xcode,
        )

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ["xcodebuild", "-version"],
        stderr=subprocess.STDOUT,
    )
Пример #15
0
def test_exists_but_command_line_tools_selected(xcode):
    "If the Xcode folder exists, but cmd-line tools are selected, raise an error."
    command = mock.MagicMock()
    command.subprocess.check_output.side_effect = subprocess.CalledProcessError(
        cmd=['xcodebuild', '-version'], returncode=1)
    command.subprocess.check_output.side_effect.output = (
        "xcode-select: error: tool 'xcodebuild' requires Xcode, but "
        "active developer directory '/Library/Developer/CommandLineTools' "
        "is a command line tools instance\n")

    with pytest.raises(BriefcaseCommandError, match=r"xcode-select -switch"):
        ensure_xcode_is_installed(command, xcode_location=xcode)

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ['xcodebuild', '-version'],
        stderr=subprocess.STDOUT,
        universal_newlines=True,
    )
Пример #16
0
def test_installed_with_minimum_version_failure(min_version, version, xcode):
    "Check XCode fail to meet a minimum version requirement."
    command = mock.MagicMock()
    command.subprocess.check_output.return_value = "Xcode {version}\nBuild version 11B500\n".format(
        version=version)

    # Check raises an error.
    with pytest.raises(BriefcaseCommandError):
        ensure_xcode_is_installed(
            command,
            min_version=min_version,
            xcode_location=xcode,
        )

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ['xcodebuild', '-version'],
        universal_newlines=True,
    )
Пример #17
0
def test_unexpected_version_output(capsys, xcode):
    "If xcodebuild returns unexpected output, assume it's ok..."
    command = mock.MagicMock()
    command.subprocess.check_output.return_value = "Wibble Wibble Wibble\n"

    # Check passes without an error...
    ensure_xcode_is_installed(
        command,
        min_version=(11, 2, 1),
        xcode_location=xcode,
    )

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ['xcodebuild', '-version'],
        universal_newlines=True,
    )

    # ...but stdout contains a warning
    out = capsys.readouterr().out
    assert '************' in out
def test_installed_with_minimum_version_success(min_version, version, capsys,
                                                xcode):
    """Check XCode can meet a minimum version requirement."""
    def check_output_mock(cmd_list, *args, **kwargs):

        if cmd_list == ["xcode-select", "-p"]:
            return xcode + "\n"

        if cmd_list == ["xcodebuild", "-version"]:
            return f"Xcode {version}\nBuild version 11B500\n"

        return mock.DEFAULT

    command = mock.MagicMock()
    command.subprocess.check_output.side_effect = check_output_mock

    # Check passes without an error.
    ensure_xcode_is_installed(
        command,
        min_version=min_version,
    )

    # assert xcode-select and xcodebuild were invoked
    command.subprocess.check_output.assert_has_calls(
        [
            mock.call(
                ["xcode-select", "-p"],
                stderr=subprocess.STDOUT,
            ),
            mock.call(
                ["xcodebuild", "-version"],
                stderr=subprocess.STDOUT,
            ),
        ],
        any_order=False,
    )

    # Make sure the warning wasn't displayed.
    out = capsys.readouterr().out
    assert "WARNING" not in out
def test_unexpected_version_output(capsys, xcode):
    """If xcodebuild returns unexpected output, assume it's ok..."""
    command = mock.MagicMock()
    command.logger = Log()
    command.subprocess.check_output.return_value = "Wibble Wibble Wibble\n"

    # Check passes without an error...
    ensure_xcode_is_installed(
        command,
        min_version=(11, 2, 1),
        xcode_location=xcode,
    )

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ["xcodebuild", "-version"],
        stderr=subprocess.STDOUT,
    )

    # ...but stdout contains a warning
    out = capsys.readouterr().out
    assert "************" in out
Пример #20
0
def test_installed_with_minimum_version_success(min_version, version, capsys,
                                                xcode):
    "Check XCode can meet a minimum version requirement."
    command = mock.MagicMock()
    command.subprocess.check_output.return_value = "Xcode {version}\nBuild version 11B500\n".format(
        version=version)

    # Check passes without an error.
    ensure_xcode_is_installed(
        command,
        min_version=min_version,
        xcode_location=xcode,
    )

    # xcode-select was invoked
    command.subprocess.check_output.assert_called_once_with(
        ['xcodebuild', '-version'],
        universal_newlines=True,
    )

    # Make sure the warning wasn't displayed.
    out = capsys.readouterr().out
    assert "WARNING" not in out