Always use uv from virtual environment at runtime (#128371)

pull/128532/head
Steven B. 2024-10-16 18:42:25 +01:00 committed by GitHub
parent a0637a6ff8
commit 59e5eb9a1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 8 deletions

View File

@ -104,6 +104,8 @@ def install_package(
_LOGGER.info("Attempting install of %s", package)
env = os.environ.copy()
args = [
sys.executable,
"-m",
"uv",
"pip",
"install",

View File

@ -84,14 +84,18 @@ def mock_async_subprocess() -> Generator[MagicMock]:
return async_popen
@pytest.mark.usefixtures("mock_sys", "mock_venv")
def test_install(mock_popen: MagicMock, mock_env_copy: MagicMock) -> None:
@pytest.mark.usefixtures("mock_venv")
def test_install(
mock_popen: MagicMock, mock_env_copy: MagicMock, mock_sys: MagicMock
) -> None:
"""Test an install attempt on a package that doesn't exist."""
env = mock_env_copy()
assert package.install_package(TEST_NEW_REQ, False)
assert mock_popen.call_count == 2
assert mock_popen.mock_calls[0] == call(
[
mock_sys.executable,
"-m",
"uv",
"pip",
"install",
@ -109,8 +113,10 @@ def test_install(mock_popen: MagicMock, mock_env_copy: MagicMock) -> None:
assert mock_popen.return_value.communicate.call_count == 1
@pytest.mark.usefixtures("mock_sys", "mock_venv")
def test_install_with_timeout(mock_popen: MagicMock, mock_env_copy: MagicMock) -> None:
@pytest.mark.usefixtures("mock_venv")
def test_install_with_timeout(
mock_popen: MagicMock, mock_env_copy: MagicMock, mock_sys: MagicMock
) -> None:
"""Test an install attempt on a package that doesn't exist with a timeout set."""
env = mock_env_copy()
assert package.install_package(TEST_NEW_REQ, False, timeout=10)
@ -118,6 +124,8 @@ def test_install_with_timeout(mock_popen: MagicMock, mock_env_copy: MagicMock) -
env["HTTP_TIMEOUT"] = "10"
assert mock_popen.mock_calls[0] == call(
[
mock_sys.executable,
"-m",
"uv",
"pip",
"install",
@ -135,14 +143,16 @@ def test_install_with_timeout(mock_popen: MagicMock, mock_env_copy: MagicMock) -
assert mock_popen.return_value.communicate.call_count == 1
@pytest.mark.usefixtures("mock_sys", "mock_venv")
def test_install_upgrade(mock_popen, mock_env_copy) -> None:
@pytest.mark.usefixtures("mock_venv")
def test_install_upgrade(mock_popen, mock_env_copy, mock_sys) -> None:
"""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",
"uv",
"pip",
"install",
@ -183,6 +193,8 @@ def test_install_target(
mock_venv.return_value = is_venv
mock_sys.platform = "linux"
args = [
mock_sys.executable,
"-m",
"uv",
"pip",
"install",
@ -226,6 +238,8 @@ def test_install_pip_compatibility_no_workaround(
mock_venv.return_value = in_venv
mock_sys.platform = "linux"
args = [
mock_sys.executable,
"-m",
"uv",
"pip",
"install",
@ -257,6 +271,8 @@ def test_install_pip_compatibility_use_workaround(
mock_sys.executable = python
site_dir = "/site_dir"
args = [
mock_sys.executable,
"-m",
"uv",
"pip",
"install",
@ -292,8 +308,8 @@ def test_install_error(caplog: pytest.LogCaptureFixture, mock_popen) -> None:
assert record.levelname == "ERROR"
@pytest.mark.usefixtures("mock_sys", "mock_venv")
def test_install_constraint(mock_popen, mock_env_copy) -> None:
@pytest.mark.usefixtures("mock_venv")
def test_install_constraint(mock_popen, mock_env_copy, mock_sys) -> None:
"""Test install with constraint file on not installed package."""
env = mock_env_copy()
constraints = "constraints_file.txt"
@ -301,6 +317,8 @@ def test_install_constraint(mock_popen, mock_env_copy) -> None:
assert mock_popen.call_count == 2
assert mock_popen.mock_calls[0] == call(
[
mock_sys.executable,
"-m",
"uv",
"pip",
"install",