Repository: kedro-org/kedro
File: tests/framework/cli/test_cli_hooks.py (Python)

Code before:
                    f"After command `{' '.join(command_args)}` run for project {project_metadata} "
                    f"(exit: {exit_code})"
                )

        return FakeCLIHooks()


@pytest.fixture
def fake_plugin_distribution(mocker):
    fake_entrypoint = FakeEntryPoint()
    fake_distribution = FakeDistribution(
        entry_points=(fake_entrypoint,),
        metadata={"name": fake_entrypoint.name},
        version="0.1",
    )
    mocker.patch(
        "importlib.metadata.distributions",
        return_value=[fake_distribution],
    )
    return fake_distribution


class TestKedroCLIHooks:
    @pytest.mark.parametrize(
        "command, exit_code",
        [("-V", 0), ("info", 0), ("pipeline list", 2), ("starter", (0, 2))],
    )
    def test_kedro_cli_should_invoke_cli_hooks_from_plugin(
        self,
        caplog,
        command,
        exit_code,
        mocker,
        fake_metadata,
        fake_plugin_distribution,
        entry_points,
    ):
        caplog.set_level(logging.DEBUG, logger="kedro")

        mocker.patch(
            "kedro.framework.cli.cli.is_kedro_project",
            return_value=True,
        )
        mocker.patch(
            "kedro.framework.cli.cli.bootstrap_project",
            return_value=fake_metadata,
        )
        kedro_cli = KedroCLI(fake_metadata.project_path)
        result = CliRunner().invoke(kedro_cli, [command])
        assert (
            f"Registered CLI hooks from 1 installed plugin(s): "

Review comment (suggestion):
```suggestion
        [("-V", 0), ("info", 0), ("pipeline list", 2), ("starter", 2)],
```

Code after:
                    f"After command `{' '.join(command_args)}` run for project {project_metadata} "
                    f"(exit: {exit_code})"
                )

        return FakeCLIHooks()


@pytest.fixture
def fake_plugin_distribution(mocker):
    fake_entrypoint = FakeEntryPoint()
    fake_distribution = FakeDistribution(
        entry_points=(fake_entrypoint,),
        metadata={"name": fake_entrypoint.name},
        version="0.1",
    )
    mocker.patch(
        "importlib.metadata.distributions",
        return_value=[fake_distribution],
    )
    return fake_distribution


class TestKedroCLIHooks:
    @pytest.mark.parametrize(
        "command, exit_code",
        # Exit code 2: click 8.2+ exits with code 2 when a group is invoked
        # without a subcommand (applies to 'starter')
        [("-V", 0), ("info", 0), ("pipeline list", 2), ("starter", 2)],
    )
    def test_kedro_cli_should_invoke_cli_hooks_from_plugin(
        self,
        caplog,
        command,
        exit_code,
        mocker,
        fake_metadata,
        fake_plugin_distribution,
        entry_points,
    ):
        caplog.set_level(logging.DEBUG, logger="kedro")

        mocker.patch(
            "kedro.framework.cli.cli.is_kedro_project",
            return_value=True,
        )
        mocker.patch(
            "kedro.framework.cli.cli.bootstrap_project",
            return_value=fake_metadata,
        )
        kedro_cli = KedroCLI(fake_metadata.project_path)
        result = CliRunner().invoke(kedro_cli, [command])