Skip to content

Commit

Permalink
go with test suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed May 18, 2023
1 parent d048899 commit c38114b
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 358 deletions.
8 changes: 4 additions & 4 deletions tests/console/commands/env/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def venv_name(app: PoetryTestApplication) -> str:
return EnvManager.generate_env_name(
app.poetry.package.name,
str(app.poetry.file.path.parent),
str(app.poetry.file.parent),
)


Expand Down Expand Up @@ -58,7 +58,7 @@ def venvs_in_cache_dirs(
@pytest.fixture
def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None)
venv_dir = app.poetry.file.path.parent.joinpath(".venv")
venv_dir = app.poetry.file.parent.joinpath(".venv")
venv_dir.mkdir(exist_ok=True)
app.poetry.config.merge({"virtualenvs": {"in-project": True}})

Expand All @@ -71,7 +71,7 @@ def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]:
@pytest.fixture
def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None)
venv_dir = app.poetry.file.path.parent.joinpath(".venv")
venv_dir = app.poetry.file.parent.joinpath(".venv")
venv_dir.mkdir(exist_ok=True)
app.poetry.config.merge({"virtualenvs": {"in-project": None}})

Expand All @@ -84,7 +84,7 @@ def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]:
@pytest.fixture
def venvs_in_project_dir_false(app: PoetryTestApplication) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None)
venv_dir = app.poetry.file.path.parent.joinpath(".venv")
venv_dir = app.poetry.file.parent.joinpath(".venv")
venv_dir.mkdir(exist_ok=True)
app.poetry.config.merge({"virtualenvs": {"in-project": False}})

Expand Down
34 changes: 0 additions & 34 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from poetry.console.commands.installer_command import InstallerCommand
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories.legacy_repository import LegacyRepository
from tests.helpers import TestLocker
from tests.helpers import get_dependency
from tests.helpers import get_package

Expand Down Expand Up @@ -1507,36 +1506,3 @@ def test_add_extras_only_accepts_one_package(
str(e.value)
== "You can only specify one package when using the --extras option"
)


@pytest.mark.parametrize("command", ["foo", "foo --lock"])
@pytest.mark.parametrize(
("locked", "expected_docker"), [(True, "4.3.1"), (False, "4.3.2")]
)
def test_add_does_not_update_locked_dependencies(
repo: TestRepository,
poetry_with_up_to_date_lockfile: Poetry,
tester: CommandTester,
command_tester_factory: CommandTesterFactory,
command: str,
locked: bool,
expected_docker: str,
) -> None:
assert isinstance(poetry_with_up_to_date_lockfile.locker, TestLocker)
poetry_with_up_to_date_lockfile.locker.locked(locked)
tester = command_tester_factory("add", poetry=poetry_with_up_to_date_lockfile)
docker_locked = get_package("docker", "4.3.1")
docker_new = get_package("docker", "4.3.2")
docker_dep = get_dependency("docker", ">=4.0.0")
foo = get_package("foo", "0.1.0")
foo.add_dependency(docker_dep)
for package in docker_locked, docker_new, foo:
repo.add_package(package)

tester.execute(command)

lock_data = poetry_with_up_to_date_lockfile.locker.lock_data
docker_locked_after_command = next(
p for p in lock_data["package"] if p["name"] == "docker"
)
assert docker_locked_after_command["version"] == expected_docker
25 changes: 22 additions & 3 deletions tests/console/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,9 @@ def test_install_logs_output_decorated(

@pytest.mark.parametrize("options", ["", "--without dev"])
@pytest.mark.parametrize(
"project",
["missing_directory_dependency_from_group", "missing_file_dependency_from_group"],
"project", ["missing_directory_dependency", "missing_file_dependency"]
)
def test_install__dependency_does_not_exist(
def test_install_path_dependency_does_not_exist(
command_tester_factory: CommandTesterFactory,
project_factory: ProjectFactory,
fixture_dir: FixtureDirGetter,
Expand All @@ -438,3 +437,23 @@ def test_install__dependency_does_not_exist(
else:
with pytest.raises(ValueError, match="does not exist"):
tester.execute(options)


@pytest.mark.parametrize("options", ["", "--no-directory"])
def test_install_missing_directory_dependency_with_no_directory(
command_tester_factory: CommandTesterFactory,
project_factory: ProjectFactory,
fixture_dir: FixtureDirGetter,
options: str,
) -> None:
poetry = _project_factory(
"missing_directory_dependency", project_factory, fixture_dir
)
assert isinstance(poetry.locker, TestLocker)
poetry.locker.locked(True)
tester = command_tester_factory("install", poetry=poetry)
if options:
tester.execute(options)
else:
with pytest.raises(ValueError, match="does not exist"):
tester.execute(options)
2 changes: 1 addition & 1 deletion tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_lock_no_update_path_dependencies(
@pytest.mark.parametrize(
"project", ["missing_directory_dependency", "missing_file_dependency"]
)
def test_lock_path_dependency_does_not_exist_and_was_removed_from_pyproject(
def test_lock_path_dependency_does_not_exist(
command_tester_factory: CommandTesterFactory,
project_factory: ProjectFactory,
fixture_dir: FixtureDirGetter,
Expand Down
55 changes: 5 additions & 50 deletions tests/console/commands/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from poetry.core.packages.package import Package

from poetry.factory import Factory
from tests.helpers import TestLocker
from tests.helpers import get_package


Expand All @@ -34,16 +33,12 @@ def poetry_with_up_to_date_lockfile(
) -> Poetry:
source = fixture_dir("up_to_date_lock")

poetry = project_factory(
return project_factory(
name="foobar",
pyproject_content=(source / "pyproject.toml").read_text(encoding="utf-8"),
poetry_lock_content=(source / "poetry.lock").read_text(encoding="utf-8"),
)

assert isinstance(poetry.locker, TestLocker)
poetry.locker.locked(True)
return poetry


@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
Expand All @@ -54,6 +49,7 @@ def test_remove_without_specific_group_removes_from_all_groups(
tester: CommandTester,
app: PoetryTestApplication,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
) -> None:
"""
Expand Down Expand Up @@ -112,6 +108,7 @@ def test_remove_without_specific_group_removes_from_specific_groups(
tester: CommandTester,
app: PoetryTestApplication,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
) -> None:
"""
Expand Down Expand Up @@ -169,6 +166,7 @@ def test_remove_does_not_live_empty_groups(
tester: CommandTester,
app: PoetryTestApplication,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
) -> None:
"""
Expand Down Expand Up @@ -215,6 +213,7 @@ def test_remove_canonicalized_named_removes_dependency_correctly(
tester: CommandTester,
app: PoetryTestApplication,
repo: TestRepository,
command_tester_factory: CommandTesterFactory,
installed: Repository,
) -> None:
"""
Expand Down Expand Up @@ -309,47 +308,3 @@ def test_remove_with_dry_run_keep_files_intact(
assert (
poetry_with_up_to_date_lockfile._locker.lock_data == original_lockfile_content
)


def test_remove_performs_uninstall_op(
poetry_with_up_to_date_lockfile: Poetry,
command_tester_factory: CommandTesterFactory,
installed: Repository,
) -> None:
installed.add_package(get_package("docker", "4.3.1"))
tester = command_tester_factory("remove", poetry=poetry_with_up_to_date_lockfile)

tester.execute("docker")

expected = """\
Updating dependencies
Resolving dependencies...
Package operations: 0 installs, 0 updates, 1 removal
• Removing docker (4.3.1)
Writing lock file
"""

assert tester.io.fetch_output() == expected


def test_remove_with_lock_does_not_perform_uninstall_op(
poetry_with_up_to_date_lockfile: Poetry,
command_tester_factory: CommandTesterFactory,
installed: Repository,
) -> None:
installed.add_package(get_package("docker", "4.3.1"))
tester = command_tester_factory("remove", poetry=poetry_with_up_to_date_lockfile)

tester.execute("docker --lock")

expected = """\
Updating dependencies
Resolving dependencies...
Writing lock file
"""

assert tester.io.fetch_output() == expected
98 changes: 3 additions & 95 deletions tests/fixtures/missing_directory_dependency/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/fixtures/missing_directory_dependency/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ packages = []

[tool.poetry.dependencies]
python = "*"

[tool.poetry.dev-dependencies]
missing = { path = "./missing" }
19 changes: 19 additions & 0 deletions tests/fixtures/missing_file_dependency/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/fixtures/missing_file_dependency/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tool.poetry]
name = "project-with-missing-directory-dependency"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"
packages = []

[tool.poetry.dependencies]
python = "*"

[tool.poetry.dev-dependencies]
missing = { file = "missing-0.1.0-py2.py3-none-any.whl" }
Loading

0 comments on commit c38114b

Please sign in to comment.