mirror of
https://github.com/enpaul/tox-poetry-installer.git
synced 2025-09-18 03:13:25 +00:00
Consolidate all package handling logic into hook module
This creates a large module to sort through, but the hope is that it avoids the need to constantly hop around without rhyme or reason to find the piece of logic you're looking for. The module structure is mapped to functionality rather than an arbitrary concept of reducing line number.
This commit is contained in:
@@ -10,7 +10,7 @@ import pytest
|
||||
import tox.tox_env.python.virtual_env.runner
|
||||
from poetry.installation.operations.operation import Operation
|
||||
|
||||
from tox_poetry_installer import utilities
|
||||
import tox_poetry_installer.hooks._tox_on_install_helpers
|
||||
|
||||
|
||||
TEST_PROJECT_PATH = Path(__file__).parent.resolve() / "test-project"
|
||||
@@ -47,7 +47,11 @@ class MockExecutor:
|
||||
|
||||
@pytest.fixture
|
||||
def mock_venv(monkeypatch):
|
||||
monkeypatch.setattr(utilities, "convert_virtualenv", lambda venv: venv)
|
||||
monkeypatch.setattr(
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers,
|
||||
"convert_virtualenv",
|
||||
lambda venv: venv,
|
||||
)
|
||||
monkeypatch.setattr(poetry.installation.executor, "Executor", MockExecutor)
|
||||
monkeypatch.setattr(
|
||||
tox.tox_env.python.virtual_env.runner, "VirtualEnvRunner", MockVirtualEnv
|
||||
|
@@ -6,23 +6,24 @@ import pytest
|
||||
import tox.tox_env.python.virtual_env.runner
|
||||
from poetry.factory import Factory
|
||||
|
||||
import tox_poetry_installer.hooks._tox_on_install_helpers
|
||||
from .fixtures import mock_poetry_factory
|
||||
from .fixtures import mock_venv
|
||||
from tox_poetry_installer import installer
|
||||
from tox_poetry_installer import utilities
|
||||
|
||||
|
||||
def test_deduplication(mock_venv, mock_poetry_factory):
|
||||
"""Test that the installer does not install duplicate dependencies"""
|
||||
poetry = Factory().create_poetry(None)
|
||||
packages: utilities.PackageMap = {
|
||||
packages: tox_poetry_installer.hooks._tox_on_install_helpers.PackageMap = {
|
||||
item.name: item for item in poetry.locker.locked_repository().packages
|
||||
}
|
||||
|
||||
venv = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
to_install = [packages["toml"], packages["toml"]]
|
||||
|
||||
installer.install(poetry, venv, to_install)
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv, to_install
|
||||
)
|
||||
|
||||
assert len(set(to_install)) == len(venv.installed) # pylint: disable=no-member
|
||||
|
||||
@@ -30,7 +31,7 @@ def test_deduplication(mock_venv, mock_poetry_factory):
|
||||
def test_parallelization(mock_venv, mock_poetry_factory):
|
||||
"""Test that behavior is consistent between parallel and non-parallel usage"""
|
||||
poetry = Factory().create_poetry(None)
|
||||
packages: utilities.PackageMap = {
|
||||
packages: tox_poetry_installer.hooks._tox_on_install_helpers.PackageMap = {
|
||||
item.name: item for item in poetry.locker.locked_repository().packages
|
||||
}
|
||||
|
||||
@@ -45,12 +46,16 @@ def test_parallelization(mock_venv, mock_poetry_factory):
|
||||
|
||||
venv_sequential = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
start_sequential = time.time()
|
||||
installer.install(poetry, venv_sequential, to_install, 0)
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv_sequential, to_install, 0
|
||||
)
|
||||
sequential = time.time() - start_sequential
|
||||
|
||||
venv_parallel = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
start_parallel = time.time()
|
||||
installer.install(poetry, venv_parallel, to_install, 5)
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv_parallel, to_install, 5
|
||||
)
|
||||
parallel = time.time() - start_parallel
|
||||
|
||||
# The mock delay during package install is static (one second) so these values should all
|
||||
@@ -72,7 +77,7 @@ def test_propagates_exceptions_during_installation(
|
||||
from tox_poetry_installer import _poetry # pylint: disable=import-outside-toplevel
|
||||
|
||||
poetry = Factory().create_poetry(None)
|
||||
packages: utilities.PackageMap = {
|
||||
packages: tox_poetry_installer.hooks._tox_on_install_helpers.PackageMap = {
|
||||
item.name: item for item in poetry.locker.locked_repository().packages
|
||||
}
|
||||
to_install = [packages["toml"]]
|
||||
@@ -85,6 +90,8 @@ def test_propagates_exceptions_during_installation(
|
||||
**{"return_value.execute.side_effect": fake_exception},
|
||||
):
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
installer.install(poetry, venv, to_install, num_threads)
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv, to_install, num_threads
|
||||
)
|
||||
|
||||
assert exc_info.value is fake_exception
|
||||
|
@@ -4,19 +4,21 @@ import poetry.utils.env
|
||||
import pytest
|
||||
from poetry.puzzle.provider import Provider
|
||||
|
||||
import tox_poetry_installer.hooks._tox_on_install_helpers
|
||||
from .fixtures import mock_poetry_factory
|
||||
from .fixtures import mock_venv
|
||||
from tox_poetry_installer import constants
|
||||
from tox_poetry_installer import exceptions
|
||||
from tox_poetry_installer import utilities
|
||||
|
||||
|
||||
def test_allow_missing():
|
||||
"""Test that the ``allow_missing`` parameter works as expected"""
|
||||
with pytest.raises(exceptions.LockedDepNotFoundError):
|
||||
utilities.identify_transients("luke-skywalker", {}, None)
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
||||
"luke-skywalker", {}, None
|
||||
)
|
||||
|
||||
assert not utilities.identify_transients(
|
||||
assert not tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
||||
"darth-vader", {}, None, allow_missing=["darth-vader"]
|
||||
)
|
||||
|
||||
@@ -36,7 +38,9 @@ def test_exclude_pep508():
|
||||
"=>foo",
|
||||
]:
|
||||
with pytest.raises(exceptions.LockedDepVersionConflictError):
|
||||
utilities.identify_transients(version, {}, None)
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
||||
version, {}, None
|
||||
)
|
||||
|
||||
|
||||
def test_functional(mock_poetry_factory, mock_venv):
|
||||
@@ -46,7 +50,9 @@ def test_functional(mock_poetry_factory, mock_venv):
|
||||
is always the last in the returned list.
|
||||
"""
|
||||
pypoetry = poetry.factory.Factory().create_poetry(None)
|
||||
packages = utilities.build_package_map(pypoetry)
|
||||
packages = tox_poetry_installer.hooks._tox_on_install_helpers.build_package_map(
|
||||
pypoetry
|
||||
)
|
||||
venv = poetry.utils.env.VirtualEnv() # pylint: disable=no-value-for-parameter
|
||||
|
||||
requests_requires = [
|
||||
@@ -57,12 +63,18 @@ def test_functional(mock_poetry_factory, mock_venv):
|
||||
packages["requests"][0],
|
||||
]
|
||||
|
||||
transients = utilities.identify_transients("requests", packages, venv)
|
||||
transients = tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
||||
"requests", packages, venv
|
||||
)
|
||||
|
||||
assert all((item in requests_requires) for item in transients)
|
||||
assert all((item in transients) for item in requests_requires)
|
||||
|
||||
for package in [packages["requests"][0], packages["tox"][0], packages["flask"][0]]:
|
||||
transients = utilities.identify_transients(package.name, packages, venv)
|
||||
transients = (
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.identify_transients(
|
||||
package.name, packages, venv
|
||||
)
|
||||
)
|
||||
assert transients[-1] == package
|
||||
assert len(transients) == len(set(transients))
|
||||
|
Reference in New Issue
Block a user