示例#1
0
def test_dockerize(first_app_config, tmp_path):
    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.Docker = Docker
    command.use_docker = True

    # Before dockerization, subprocess is native
    assert type(command.subprocess) == Subprocess

    with command.dockerize(first_app_config):
        # During dockerization, subprocess is a container
        assert type(command.subprocess) == Docker

    # After dockerization, subprocess is native
    assert type(command.subprocess) == Subprocess
示例#2
0
def test_dockerize_nodocker(first_app_config, tmp_path):
    """If docker is not in use, dockerize() is a no-op."""
    command = LinuxAppImageCreateCommand(base_path=tmp_path)
    command.Docker = Docker
    command.use_docker = False

    # Before dockerization, subprocess is native
    assert type(command.subprocess) == Subprocess

    with command.dockerize(first_app_config):
        # During dockerization, subprocess is *still* native
        assert type(command.subprocess) == Subprocess

    # After dockerization, subprocess is native
    assert type(command.subprocess) == Subprocess
示例#3
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)
示例#4
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)
示例#5
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,
    )
示例#6
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,
    )