Esempio n. 1
0
def test_install_upgrade(mock_sys, mock_popen, mock_env_copy, mock_venv):
    """Test an upgrade attempt on a package."""
    env = mock_env_copy()
    assert package.install_package(TEST_NEW_REQ)
    assert mock_popen.call_count == 2
    assert mock_popen.mock_calls[0] == call(
        [
            mock_sys.executable,
            "-m",
            "pip",
            "install",
            "--quiet",
            TEST_NEW_REQ,
            "--upgrade",
        ],
        stdin=PIPE,
        stdout=PIPE,
        stderr=PIPE,
        env=env,
    )
    assert mock_popen.return_value.communicate.call_count == 1
Esempio n. 2
0
def test_install_constraint(mock_sys, mock_popen, mock_env_copy, mock_venv):
    """Test install with constraint file on not installed package."""
    env = mock_env_copy()
    constraints = "constraints_file.txt"
    assert package.install_package(TEST_NEW_REQ, False, constraints=constraints)
    assert mock_popen.call_count == 2
    assert mock_popen.mock_calls[0] == call(
        [
            mock_sys.executable,
            "-m",
            "pip",
            "install",
            "--quiet",
            TEST_NEW_REQ,
            "--constraint",
            constraints,
        ],
        stdin=PIPE,
        stdout=PIPE,
        stderr=PIPE,
        env=env,
    )
    assert mock_popen.return_value.communicate.call_count == 1
Esempio n. 3
0
def test_install_find_links(mock_sys, mock_popen, mock_env_copy, mock_venv):
    """Test install with find-links on not installed package."""
    env = mock_env_copy()
    link = "https://wheels-repository"
    assert package.install_package(TEST_NEW_REQ, False, find_links=link)
    assert mock_popen.call_count == 2
    assert mock_popen.mock_calls[0] == call(
        [
            mock_sys.executable,
            "-m",
            "pip",
            "install",
            "--quiet",
            TEST_NEW_REQ,
            "--find-links",
            link,
            "--prefer-binary",
        ],
        stdin=PIPE,
        stdout=PIPE,
        stderr=PIPE,
        env=env,
    )
    assert mock_popen.return_value.communicate.call_count == 1
Esempio n. 4
0
def test_install_target(mock_sys, mock_popen, mock_env_copy, mock_venv):
    """Test an install with a target."""
    target = "target_folder"
    env = mock_env_copy()
    env["PYTHONUSERBASE"] = os.path.abspath(target)
    mock_venv.return_value = False
    mock_sys.platform = "linux"
    args = [
        mock_sys.executable,
        "-m",
        "pip",
        "install",
        "--quiet",
        TEST_NEW_REQ,
        "--user",
        "--prefix=",
    ]

    assert package.install_package(TEST_NEW_REQ, False, target=target)
    assert mock_popen.call_count == 2
    assert mock_popen.mock_calls[0] == call(
        args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env
    )
    assert mock_popen.return_value.communicate.call_count == 1
Esempio n. 5
0
 def _install(req: str, kwargs: dict[str, Any]) -> bool:
     """Install requirement."""
     return pkg_util.install_package(req, **kwargs)
Esempio n. 6
0
def test_install_target_venv(mock_sys, mock_popen, mock_env_copy, mock_venv):
    """Test an install with a target in a virtual environment."""
    target = "target_folder"
    with pytest.raises(AssertionError):
        package.install_package(TEST_NEW_REQ, False, target=target)