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
|
|
|
|
|
|
|
|
import poetry.factory
|
|
|
|
import poetry.installation.pip_installer
|
|
|
|
import poetry.utils.env
|
|
|
|
import pytest
|
|
|
|
import tox
|
2022-07-02 02:08:11 +00:00
|
|
|
from poetry.core.packages.package import Package as PoetryPackage
|
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`"""
|
|
|
|
|
|
|
|
class MockTestenvConfig: # pylint: disable=missing-class-docstring
|
2021-04-16 23:39:10 +00:00
|
|
|
envdir = FAKE_VENV_PATH
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.envconfig = self.MockTestenvConfig()
|
|
|
|
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
|
|
|
|
|
|
|
class MockPipInstaller:
|
2021-04-17 02:33:08 +00:00
|
|
|
"""Mock class for the :class:`poetry.installation.pip_installer.PipInstaller`"""
|
|
|
|
|
2021-04-16 23:39:10 +00:00
|
|
|
def __init__(self, env: MockVirtualEnv, **kwargs):
|
|
|
|
self.env = env
|
|
|
|
|
|
|
|
def install(self, package: PoetryPackage):
|
|
|
|
self.env.installed.append(package)
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_venv(monkeypatch):
|
|
|
|
monkeypatch.setattr(utilities, "convert_virtualenv", lambda venv: venv)
|
|
|
|
monkeypatch.setattr(
|
|
|
|
poetry.installation.pip_installer, "PipInstaller", MockPipInstaller
|
|
|
|
)
|
|
|
|
monkeypatch.setattr(tox.venv, "VirtualEnv", MockVirtualEnv)
|
|
|
|
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)
|