|
| 1 | +import pytest |
1 | 2 | import typer |
| 3 | +import typer.core |
2 | 4 | from typer.testing import CliRunner |
3 | 5 |
|
| 6 | +from tests.utils import needs_rich |
| 7 | + |
4 | 8 | runner = CliRunner() |
5 | 9 |
|
6 | 10 |
|
@@ -96,3 +100,35 @@ def delete(): # pragma: no cover |
96 | 100 | assert result.exit_code != 0 |
97 | 101 | assert "No such command" in result.output |
98 | 102 | assert "Did you mean" not in result.output |
| 103 | + |
| 104 | + |
| 105 | +@pytest.mark.parametrize( |
| 106 | + "use_rich", |
| 107 | + [ |
| 108 | + pytest.param(False), |
| 109 | + pytest.param(True, marks=needs_rich), |
| 110 | + ], |
| 111 | +) |
| 112 | +def test_typo_suggestion_excludes_hidden_commands( |
| 113 | + monkeypatch: pytest.MonkeyPatch, use_rich: bool |
| 114 | +) -> None: |
| 115 | + monkeypatch.setattr(typer.core, "HAS_RICH", use_rich) |
| 116 | + app = typer.Typer() |
| 117 | + |
| 118 | + @app.command() |
| 119 | + def secret_agent(): # pragma: no cover |
| 120 | + typer.echo("Visible command") |
| 121 | + |
| 122 | + @app.command(hidden=True) |
| 123 | + def secret_admin(): |
| 124 | + typer.echo("Hidden command") |
| 125 | + |
| 126 | + result = runner.invoke(app, ["secret-admi"]) |
| 127 | + assert result.exit_code != 0 |
| 128 | + assert "No such command" in result.output |
| 129 | + assert "'secret-agent'" in result.output |
| 130 | + assert "'secret-admin'" not in result.output |
| 131 | + |
| 132 | + result = runner.invoke(app, ["secret-admin"]) |
| 133 | + assert result.exit_code == 0 |
| 134 | + assert "Hidden command" in result.output |
0 commit comments