mirror of
https://github.com/enpaul/tox-poetry-installer.git
synced 2025-09-19 03:21:58 +00:00
Standardize import structure
Standardize on "import module" format rather than "from module import foo" format Remove _poetry stub module since we directly depend on the poetry package now Fix conflicts between modules and parameters both named 'poetry' Fixes #92
This commit is contained in:
@@ -5,10 +5,10 @@ from typing import List
|
||||
|
||||
import poetry.factory
|
||||
import poetry.installation.executor
|
||||
import poetry.installation.operations.operation
|
||||
import poetry.utils.env
|
||||
import pytest
|
||||
import tox.tox_env.python.virtual_env.runner
|
||||
from poetry.installation.operations.operation import Operation
|
||||
|
||||
import tox_poetry_installer.hooks._tox_on_install_helpers
|
||||
|
||||
@@ -40,7 +40,9 @@ class MockExecutor:
|
||||
def __init__(self, env: MockVirtualEnv, **kwargs):
|
||||
self.env = env
|
||||
|
||||
def execute(self, operations: List[Operation]):
|
||||
def execute(
|
||||
self, operations: List[poetry.installation.operations.operation.Operation]
|
||||
):
|
||||
self.env.installed.extend([operation.package for operation in operations])
|
||||
time.sleep(1)
|
||||
|
||||
@@ -61,9 +63,9 @@ def mock_venv(monkeypatch):
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mock_poetry_factory(monkeypatch):
|
||||
pypoetry = poetry.factory.Factory().create_poetry(cwd=TEST_PROJECT_PATH)
|
||||
project = poetry.factory.Factory().create_poetry(cwd=TEST_PROJECT_PATH)
|
||||
|
||||
def mock_factory(*args, **kwargs):
|
||||
return pypoetry
|
||||
return project
|
||||
|
||||
monkeypatch.setattr(poetry.factory.Factory, "create_poetry", mock_factory)
|
||||
|
@@ -2,9 +2,10 @@
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
import poetry.factory
|
||||
import poetry.installation.executor
|
||||
import pytest
|
||||
import tox.tox_env.python.virtual_env.runner
|
||||
from poetry.factory import Factory
|
||||
|
||||
import tox_poetry_installer.hooks._tox_on_install_helpers
|
||||
|
||||
@@ -14,16 +15,16 @@ from .fixtures import mock_venv
|
||||
|
||||
def test_deduplication(mock_venv, mock_poetry_factory):
|
||||
"""Test that the installer does not install duplicate dependencies"""
|
||||
poetry = Factory().create_poetry(None)
|
||||
project = poetry.factory.Factory().create_poetry(None)
|
||||
packages: tox_poetry_installer.hooks._tox_on_install_helpers.PackageMap = {
|
||||
item.name: item for item in poetry.locker.locked_repository().packages
|
||||
item.name: item for item in project.locker.locked_repository().packages
|
||||
}
|
||||
|
||||
venv = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
to_install = [packages["toml"], packages["toml"]]
|
||||
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv, to_install
|
||||
project, venv, to_install
|
||||
)
|
||||
|
||||
assert len(set(to_install)) == len(venv.installed) # pylint: disable=no-member
|
||||
@@ -31,9 +32,9 @@ 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)
|
||||
project = poetry.factory.Factory().create_poetry(None)
|
||||
packages: tox_poetry_installer.hooks._tox_on_install_helpers.PackageMap = {
|
||||
item.name: item for item in poetry.locker.locked_repository().packages
|
||||
item.name: item for item in project.locker.locked_repository().packages
|
||||
}
|
||||
|
||||
to_install = [
|
||||
@@ -48,14 +49,14 @@ def test_parallelization(mock_venv, mock_poetry_factory):
|
||||
venv_sequential = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
start_sequential = time.time()
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv_sequential, to_install, 0
|
||||
project, venv_sequential, to_install, 0
|
||||
)
|
||||
sequential = time.time() - start_sequential
|
||||
|
||||
venv_parallel = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
start_parallel = time.time()
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv_parallel, to_install, 5
|
||||
project, venv_parallel, to_install, 5
|
||||
)
|
||||
parallel = time.time() - start_parallel
|
||||
|
||||
@@ -75,24 +76,22 @@ def test_propagates_exceptions_during_installation(
|
||||
|
||||
Regression test for https://github.com/enpaul/tox-poetry-installer/issues/86
|
||||
"""
|
||||
from tox_poetry_installer import _poetry # pylint: disable=import-outside-toplevel
|
||||
|
||||
poetry = Factory().create_poetry(None)
|
||||
project = poetry.factory.Factory().create_poetry(None)
|
||||
packages: tox_poetry_installer.hooks._tox_on_install_helpers.PackageMap = {
|
||||
item.name: item for item in poetry.locker.locked_repository().packages
|
||||
item.name: item for item in project.locker.locked_repository().packages
|
||||
}
|
||||
to_install = [packages["toml"]]
|
||||
venv = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
|
||||
fake_exception = ValueError("my testing exception")
|
||||
|
||||
with mock.patch.object(
|
||||
_poetry,
|
||||
poetry.installation.executor,
|
||||
"Executor",
|
||||
**{"return_value.execute.side_effect": fake_exception},
|
||||
):
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
tox_poetry_installer.hooks._tox_on_install_helpers.install_package(
|
||||
poetry, venv, to_install, num_threads
|
||||
project, venv, to_install, num_threads
|
||||
)
|
||||
|
||||
assert exc_info.value is fake_exception
|
||||
|
@@ -48,9 +48,9 @@ def test_functional(mock_poetry_factory, mock_venv):
|
||||
Trivially test that it resolves dependencies properly and that the parent package
|
||||
is always the last in the returned list.
|
||||
"""
|
||||
pypoetry = poetry.factory.Factory().create_poetry(None)
|
||||
project = poetry.factory.Factory().create_poetry(None)
|
||||
packages = tox_poetry_installer.hooks._tox_on_install_helpers.build_package_map(
|
||||
pypoetry
|
||||
project
|
||||
)
|
||||
venv = poetry.utils.env.VirtualEnv() # pylint: disable=no-value-for-parameter
|
||||
|
||||
|
Reference in New Issue
Block a user