-
Notifications
You must be signed in to change notification settings - Fork 509
test(cli): add direct unit tests for CLI layout renderers #1015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import click | ||
|
|
||
| from app.cli.__main__ import cli | ||
| from app.cli.layout import ( | ||
| _HELP_COMMANDS, | ||
| _LANDING_COMMANDS, | ||
| _SHORT_OPTIONS, | ||
| RichGroup, | ||
| render_help, | ||
| render_landing, | ||
| ) | ||
|
|
||
|
|
||
| def _normalized_output(output: str) -> str: | ||
| return " ".join(output.split()) | ||
|
|
||
|
|
||
| def test_render_help_shows_root_commands(capsys) -> None: | ||
| render_help() | ||
| output = _normalized_output(capsys.readouterr().out) | ||
|
|
||
| assert "Usage: opensre [OPTIONS] COMMAND [ARGS]..." in output | ||
| assert "Commands:" in output | ||
| assert "Options:" in output | ||
|
|
||
| for label, description in _HELP_COMMANDS: | ||
| assert label in output | ||
| assert description in output | ||
|
|
||
|
Comment on lines
+28
to
+31
|
||
| for label, description in _SHORT_OPTIONS: | ||
| assert label in output | ||
| assert description in output | ||
|
Comment on lines
+20
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @7vignesh is this solved? |
||
|
|
||
|
|
||
| def test_render_landing_shows_root_commands_and_header(capsys) -> None: | ||
| render_landing() | ||
| output = _normalized_output(capsys.readouterr().out) | ||
|
|
||
| assert ( | ||
| "open-source SRE agent for automated incident investigation and root cause analysis" | ||
| in output | ||
| ) | ||
| assert "Usage: opensre [OPTIONS] COMMAND [ARGS]..." in output | ||
| assert "Quick start:" in output | ||
| assert "Options:" in output | ||
|
|
||
| for label, description in _LANDING_COMMANDS: | ||
| assert label in output | ||
| assert description in output | ||
|
|
||
| for label, description in _SHORT_OPTIONS: | ||
| assert label in output | ||
| assert description in output | ||
|
|
||
|
|
||
| def test_help_command_names_match_layout_metadata() -> None: | ||
| assert tuple(cli.commands.keys()) == tuple(label for label, _description in _HELP_COMMANDS) | ||
|
|
||
|
|
||
| def test_rich_group_format_help_delegates_to_render_help(monkeypatch) -> None: | ||
| called = [] | ||
|
|
||
| def fake_render_help() -> None: | ||
| called.append(True) | ||
|
|
||
| monkeypatch.setattr("app.cli.layout.render_help", fake_render_help) | ||
|
|
||
| group = RichGroup(name="opensre") | ||
| group.format_help(click.Context(group), click.HelpFormatter()) | ||
|
|
||
| assert called == [True] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why new layouts are added?