2021-04-17 02:33:08 +00:00
|
|
|
# pylint: disable=missing-module-docstring, missing-function-docstring, unused-argument, too-few-public-methods
|
2021-04-16 23:39:10 +00:00
|
|
|
import time
|
|
|
|
from pathlib import Path
|
2023-05-04 11:05:02 +00:00
|
|
|
from typing import List
|
2021-04-16 23:39:10 +00:00
|
|
|
|
|
|
|
import poetry.factory
|
2023-05-04 11:05:02 +00:00
|
|
|
import poetry.installation.executor
|
2021-04-16 23:39:10 +00:00
|
|
|
import poetry.utils.env
|
|
|
|
import pytest
|
2023-01-10 02:34:35 +00:00
|
|
|
import tox.tox_env.python.virtual_env.runner
|
2023-05-04 11:05:02 +00:00
|
|
|
from poetry.installation.operations.operation import Operation
|
2021-04-16 23:39:10 +00:00
|
|
|
|
|
|
|
from tox_poetry_installer import utilities
|
|
|
|
|
|
|
|
|
|
|
|
TEST_PROJECT_PATH = Path(__file__).parent.resolve() / "test-project"
|
|
|
|
|
|
|
|
FAKE_VENV_PATH = Path("nowhere")
|
|
|
|
|
|
|
|
|
|
|
|
class MockVirtualEnv:
|
2021-04-17 02:33:08 +00:00
|
|
|
"""Mock class for the :class:`poetry.utils.env.VirtualEnv` and :class:`tox.venv.VirtualEnv`"""
|
|
|
|
|
2021-04-16 23:39:10 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2023-01-10 02:34:35 +00:00
|
|
|
self.env_dir = FAKE_VENV_PATH
|
2021-04-16 23:39:10 +00:00
|
|
|
self.installed = []
|
|
|
|
|
2021-04-17 02:33:08 +00:00
|
|
|
@staticmethod
|
|
|
|
def is_valid_for_marker(*args, **kwargs):
|
2021-04-16 23:39:10 +00:00
|
|
|
return True
|
|
|
|
|
2022-04-07 04:15:34 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_version_info():
|
|
|
|
return (1, 2, 3)
|
|
|
|
|
2021-04-16 23:39:10 +00:00
|
|
|
|
2023-05-04 11:05:02 +00:00
|
|
|
class MockExecutor:
|
|
|
|
"""Mock class for the :class:`poetry.installation.executor.Executor`"""
|
2021-04-17 02:33:08 +00:00
|
|
|
|
2021-04-16 23:39:10 +00:00
|
|
|
def __init__(self, env: MockVirtualEnv, **kwargs):
|
|
|
|
self.env = env
|
|
|
|
|
2023-05-04 11:05:02 +00:00
|
|
|
def execute(self, operations: List[Operation]):
|
|
|
|
self.env.installed.extend([operation.package for operation in operations])
|
2021-04-16 23:39:10 +00:00
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_venv(monkeypatch):
|
|
|
|
monkeypatch.setattr(utilities, "convert_virtualenv", lambda venv: venv)
|
2023-05-04 11:05:02 +00:00
|
|
|
monkeypatch.setattr(poetry.installation.executor, "Executor", MockExecutor)
|
2023-01-10 02:34:35 +00:00
|
|
|
monkeypatch.setattr(
|
|
|
|
tox.tox_env.python.virtual_env.runner, "VirtualEnvRunner", MockVirtualEnv
|
|
|
|
)
|
2021-04-16 23:39:10 +00:00
|
|
|
monkeypatch.setattr(poetry.utils.env, "VirtualEnv", MockVirtualEnv)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def mock_poetry_factory(monkeypatch):
|
|
|
|
pypoetry = poetry.factory.Factory().create_poetry(cwd=TEST_PROJECT_PATH)
|
|
|
|
|
|
|
|
def mock_factory(*args, **kwargs):
|
|
|
|
return pypoetry
|
|
|
|
|
|
|
|
monkeypatch.setattr(poetry.factory.Factory, "create_poetry", mock_factory)
|