Skip to content

Commit

Permalink
tests: add coverage for --no-root when using groups
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Mar 22, 2022
1 parent dec009d commit 4f908cb
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions tests/console/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

from poetry.core.masonry.utils.module import ModuleOrPackageNotFound


if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
Expand Down Expand Up @@ -61,25 +63,39 @@ def tester(


@pytest.mark.parametrize(
("options", "groups"),
("options", "groups", "with_root"),
[
("", {"default", "foo", "bar", "baz", "bim"}),
("--only default", {"default"}),
("--only foo", {"foo"}),
("--only foo,bar", {"foo", "bar"}),
("--only bam", {"bam"}),
("--with bam", {"default", "foo", "bar", "baz", "bim", "bam"}),
("--without foo,bar", {"default", "baz", "bim"}),
("--with foo,bar --without baz --without bim --only bam", {"bam"}),
case + (with_root,)
for case in [
("", {"default", "foo", "bar", "baz", "bim"}),
("--only default", {"default"}),
("--only foo", {"foo"}),
("--only foo,bar", {"foo", "bar"}),
("--only bam", {"bam"}),
("--with bam", {"default", "foo", "bar", "baz", "bim", "bam"}),
("--without foo,bar", {"default", "baz", "bim"}),
("--with foo,bar --without baz --without bim --only bam", {"bam"}),
]
for with_root in {True, False}
],
)
def test_group_options_are_passed_to_the_installer(
options: str, groups: set[str], tester: CommandTester, mocker: MockerFixture
options: str,
groups: set[str],
with_root: bool,
tester: CommandTester,
mocker: MockerFixture,
):
"""
Group options are passed properly to the installer.
"""
mocker.patch.object(tester.command.installer, "run", return_value=1)
mocker.patch.object(tester.command.installer, "run", return_value=0)
editable_builder_mock = mocker.patch(
"poetry.masonry.builders.EditableBuilder", side_effect=ModuleOrPackageNotFound()
)

if not with_root:
options = f"--no-root {options}"

tester.execute(options)

Expand All @@ -89,6 +105,12 @@ def test_group_options_are_passed_to_the_installer(
assert installer_groups <= package_groups
assert set(installer_groups) == groups

if with_root:
assert editable_builder_mock.call_count == 1
assert editable_builder_mock.call_args_list[0][0][0] == tester.command.poetry
else:
assert editable_builder_mock.call_count == 0


def test_sync_option_is_passed_to_the_installer(
tester: CommandTester, mocker: MockerFixture
Expand Down

0 comments on commit 4f908cb

Please sign in to comment.