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

Code before:
@forward_command(stub_cli)
def unnamed(args, **kwargs):
    print("fred", args)


@fixture
def requirements_file(tmp_path):
    body = "\n".join(["SQLAlchemy>=1.2.0, <2.0", "pandas==0.23.0", "toposort"]) + "\n"
    reqs_file = tmp_path / "requirements.txt"
    reqs_file.write_text(body)
    yield reqs_file


@fixture
def fake_session(mocker):
    mock_session_create = mocker.patch.object(KedroSession, "create")
    mocked_session = mock_session_create.return_value.__enter__.return_value
    return mocked_session


class TestCliCommands:
    def test_cli(self):
        """Run `kedro` without arguments."""
        result = CliRunner().invoke(cli, [])

        assert result.exit_code in (0, 2)
        assert "kedro" in result.output

    def test_print_version(self):
        """Check that `kedro --version` and `kedro -V` outputs contain
        the current package version."""
        result = CliRunner().invoke(cli, ["--version"])

        assert result.exit_code == 0
        assert version in result.output

        result_abr = CliRunner().invoke(cli, ["-V"])
        assert result_abr.exit_code == 0
        assert version in result_abr.output

    def test_info_contains_plugin_versions(self, entry_point):
        entry_point.dist.version = "1.0.2"
        entry_point.module = "bob.fred"

        result = CliRunner().invoke(cli, ["info"])
        assert result.exit_code == 0
        assert (
            "bob: 1.0.2 (entry points:cli_hooks,global,hooks,init,line_magic,project,starters)"
            in result.output
        )


Review comment (suggestion):
```suggestion
        assert result.exit_code == 2
```
Since we are pinning to >=8.2 we don't need the option

Code after:
@forward_command(stub_cli)
def unnamed(args, **kwargs):
    print("fred", args)


@fixture
def requirements_file(tmp_path):
    body = "\n".join(["SQLAlchemy>=1.2.0, <2.0", "pandas==0.23.0", "toposort"]) + "\n"
    reqs_file = tmp_path / "requirements.txt"
    reqs_file.write_text(body)
    yield reqs_file


@fixture
def fake_session(mocker):
    mock_session_create = mocker.patch.object(KedroSession, "create")
    mocked_session = mock_session_create.return_value.__enter__.return_value
    return mocked_session


class TestCliCommands:
    def test_cli(self):
        """Run `kedro` without arguments."""
        result = CliRunner().invoke(cli, [])

        # Exit code 2: click 8.2+ exits with code 2 when a group is invoked
        # without a subcommand
        assert result.exit_code == 2
        assert "kedro" in result.output

    def test_print_version(self):
        """Check that `kedro --version` and `kedro -V` outputs contain
        the current package version."""
        result = CliRunner().invoke(cli, ["--version"])

        assert result.exit_code == 0
        assert version in result.output

        result_abr = CliRunner().invoke(cli, ["-V"])
        assert result_abr.exit_code == 0
        assert version in result_abr.output

    def test_info_contains_plugin_versions(self, entry_point):
        entry_point.dist.version = "1.0.2"
        entry_point.module = "bob.fred"

        result = CliRunner().invoke(cli, ["info"])
        assert result.exit_code == 0
        assert (
            "bob: 1.0.2 (entry points:cli_hooks,global,hooks,init,line_magic,project,starters)"
            in result.output