1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
def test_interactive_shell(app, mocker, console):
mocker.patch(
"cyclopts.core.input",
side_effect=[
"foo 1 2 3",
"bad-command 123",
"",
"bar bloop",
"quit",
],
)
foo_called, bar_called = 0, 0
@app.command
def foo(a: int, b: int, c: int):
nonlocal foo_called
foo_called += 1
@app.command
def bar(token):
nonlocal bar_called
bar_called += 1
with console.capture() as capture:
app.interactive_shell(console=console)
actual = capture.get()
assert foo_called == 1
assert bar_called == 1
assert actual == (
"╭─ Error ────────────────────────────────────────────────────────────╮\n"
'│ Unknown command "bad-command". Available commands: foo, bar. │\n'
"╰────────────────────────────────────────────────────────────────────╯\n"
)
|