示例#1
0
def test_verify_linux_docker(tmp_path):
    "If Docker is enabled on Linux, the Docker alias is set"
    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.host_os = "Linux"
    command.use_docker = True
    command.verbosity = 0
    # Mock the existence of Docker.
    command.subprocess = MagicMock()
    command.subprocess.check_output.return_value = "Docker version 19.03.8, build afacb8b\n"

    # Verify the tools
    command.verify_tools()

    # The Docker wrapper is set.
    assert command.Docker == Docker
示例#2
0
def test_install_app_dependencies_no_docker(first_app_config, tmp_path):
    "If docker is *not* in use, calls are made on raw subprocess"
    first_app_config.requires = ['foo==1.2.3', 'bar>=4.5']

    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.use_docker = False
    command.subprocess = MagicMock()
    docker = MagicMock()
    command.Docker = MagicMock()
    command.Docker.return_value = docker

    command._path_index = {
        first_app_config: {
            'app_packages_path': 'path/to/app_packages'
        }
    }

    command.install_app_dependencies(first_app_config)

    # A docker context was not created, nor was it prepared
    assert command.Docker.call_count == 0
    assert docker.prepare.call_count == 0

    # The no-op prepare call was made.
    command.subprocess.prepare.assert_called_with()

    # pip was invoked natively
    command.subprocess.run.assert_called_with([
        sys.executable,
        '-m',
        'pip',
        'install',
        '--upgrade',
        '--no-user',
        '--target={tmp_path}/linux/First App/path/to/app_packages'.format(
            tmp_path=tmp_path),
        'foo==1.2.3',
        'bar>=4.5',
    ],
                                              check=True)
示例#3
0
def test_install_app_dependencies(first_app_config, tmp_path):
    "If Docker is in use, a docker context is used to invoke pip"
    first_app_config.requires = ['foo==1.2.3', 'bar>=4.5']

    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.use_docker = True
    command.subprocess = MagicMock()
    docker = MagicMock()
    command.Docker = MagicMock()
    command.Docker.return_value = docker

    command._path_index = {
        first_app_config: {
            'app_packages_path': 'path/to/app_packages'
        }
    }

    command.install_app_dependencies(first_app_config)

    # A docker context was created
    command.Docker.assert_called_with(command, first_app_config)

    # The docker container was prepared
    docker.prepare.assert_called_with()

    # pip was invoked inside docker.
    docker.run.assert_called_with([
        sys.executable,
        '-m',
        'pip',
        'install',
        '--upgrade',
        '--no-user',
        '--target={tmp_path}/linux/First App/path/to/app_packages'.format(
            tmp_path=tmp_path),
        'foo==1.2.3',
        'bar>=4.5',
    ],
                                  check=True)
示例#4
0
def test_install_app_dependencies_no_docker(first_app_config, tmp_path):
    """If docker is *not* in use, calls are made on raw subprocess."""
    first_app_config.requires = ["foo==1.2.3", "bar>=4.5"]

    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.use_docker = False
    command.subprocess = MagicMock()
    docker = MagicMock()
    command.Docker = MagicMock()
    command.Docker.return_value = docker

    command._path_index = {
        first_app_config: {"app_packages_path": "path/to/app_packages"}
    }

    command.install_app_dependencies(first_app_config)

    # A docker context was not created, nor was it prepared
    assert command.Docker.call_count == 0
    assert docker.prepare.call_count == 0

    # The no-op prepare call was made.
    command.subprocess.prepare.assert_called_with()

    # pip was invoked natively
    command.subprocess.run.assert_called_with(
        [
            sys.executable,
            "-m",
            "pip",
            "install",
            "--upgrade",
            "--no-user",
            f"--target={tmp_path}/linux/appimage/First App/path/to/app_packages",
            "foo==1.2.3",
            "bar>=4.5",
        ],
        check=True,
    )
示例#5
0
def test_install_app_dependencies(first_app_config, tmp_path):
    """If Docker is in use, a docker context is used to invoke pip."""
    first_app_config.requires = ["foo==1.2.3", "bar>=4.5"]

    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.use_docker = True
    command.subprocess = MagicMock()
    docker = MagicMock()
    command.Docker = MagicMock()
    command.Docker.return_value = docker

    command._path_index = {
        first_app_config: {"app_packages_path": "path/to/app_packages"}
    }

    command.install_app_dependencies(first_app_config)

    # A docker context was created
    command.Docker.assert_called_with(command, first_app_config)

    # The docker container was prepared
    docker.prepare.assert_called_with()

    # pip was invoked inside docker.
    docker.run.assert_called_with(
        [
            sys.executable,
            "-m",
            "pip",
            "install",
            "--upgrade",
            "--no-user",
            f"--target={tmp_path}/linux/appimage/First App/path/to/app_packages",
            "foo==1.2.3",
            "bar>=4.5",
        ],
        check=True,
    )