Skip to content

Commit

Permalink
atomic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Jul 13, 2024
1 parent 13b875b commit cd92c39
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 39 deletions.
2 changes: 0 additions & 2 deletions src/poetry/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json
import logging
import shutil
import site
import sys

from functools import cached_property
Expand Down Expand Up @@ -65,7 +64,6 @@ def add_project_plugin_path(directory: Path) -> None:
plugin_path = pyproject_toml.parent / ProjectPluginCache.PATH
if plugin_path.exists():
EnvManager.get_system_env(naive=True).sys_path.insert(0, str(plugin_path))
site.addsitedir(str(plugin_path))

@classmethod
def ensure_project_plugins(cls, poetry: Poetry, io: IO) -> None:
Expand Down
4 changes: 0 additions & 4 deletions tests/console/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ def test_application_project_plugins(
project_plugin_path = project_path / ProjectPluginCache.PATH
if with_project_plugins:
project_plugin_path.mkdir(parents=True)
stub = "my_application_plugin"
dist_info = "my_application_plugin-2.0.dist-info"
for folder in (dist_info, stub):
shutil.copytree(orig_dir / folder, project_plugin_path / folder)

with set_project_context(project_path, in_place=True):
app = Application()
Expand Down
21 changes: 0 additions & 21 deletions tests/fixtures/project_plugins/my_application_plugin/plugins.py

This file was deleted.

36 changes: 24 additions & 12 deletions tests/plugins/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import shutil

from importlib import metadata
from importlib.metadata import PackageNotFoundError
from pathlib import Path
from typing import TYPE_CHECKING
from typing import ClassVar
Expand All @@ -30,9 +28,10 @@
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories import Repository
from poetry.repositories import RepositoryPool
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils.env import Env
from poetry.utils.env import EnvManager
from poetry.utils.env import VirtualEnv
from poetry.utils.env import MockEnv
from tests.helpers import mock_metadata_entry_points


Expand Down Expand Up @@ -86,9 +85,10 @@ def pool(repo: Repository) -> RepositoryPool:


@pytest.fixture
def system_env(tmp_venv: VirtualEnv, mocker: MockerFixture) -> Env:
mocker.patch.object(EnvManager, "get_system_env", return_value=tmp_venv)
return tmp_venv
def system_env(tmp_path: Path, mocker: MockerFixture) -> Env:
env = MockEnv(path=tmp_path, sys_path=[str(tmp_path / "purelib")])
mocker.patch.object(EnvManager, "get_system_env", return_value=env)
return env


@pytest.fixture
Expand Down Expand Up @@ -168,18 +168,30 @@ def test_load_plugins_with_invalid_plugin(


def test_add_project_plugin_path(
poetry_with_plugins: Poetry, io: BufferedIO, fixture_dir: FixtureDirGetter
poetry_with_plugins: Poetry,
io: BufferedIO,
system_env: Env,
fixture_dir: FixtureDirGetter,
) -> None:
dist_info = "my_application_plugin-2.0.dist-info"
dist_info_1 = "my_application_plugin-1.0.dist-info"
dist_info_2 = "my_application_plugin-2.0.dist-info"
cache = ProjectPluginCache(poetry_with_plugins, io)
shutil.copytree(fixture_dir("project_plugins") / dist_info, cache._path / dist_info)
shutil.copytree(
fixture_dir("project_plugins") / dist_info_1, cache._path / dist_info_1
)
shutil.copytree(
fixture_dir("project_plugins") / dist_info_2, system_env.purelib / dist_info_2
)

with pytest.raises(PackageNotFoundError):
metadata.version("my-application-plugin")
assert {
f"{p.name} {p.version}" for p in InstalledRepository.load(system_env).packages
} == {"my-application-plugin 2.0"}

PluginManager.add_project_plugin_path(poetry_with_plugins.pyproject_path.parent)

assert metadata.version("my-application-plugin") == "2.0"
assert {
f"{p.name} {p.version}" for p in InstalledRepository.load(system_env).packages
} == {"my-application-plugin 1.0"}


def test_ensure_plugins_no_plugins_no_output(poetry: Poetry, io: BufferedIO) -> None:
Expand Down

0 comments on commit cd92c39

Please sign in to comment.