Raise CLI errors in debug mode (#771)

This commit is contained in:
Steven B
2024-02-20 11:21:04 +00:00
committed by GitHub
parent 29e6b92b1e
commit 5ba3676422
2 changed files with 82 additions and 10 deletions

View File

@@ -504,6 +504,7 @@ async def test_host_unsupported(unsupported_device_info):
"foo",
"--password",
"bar",
"--debug",
],
)
@@ -563,6 +564,7 @@ async def test_host_auth_failed(discovery_mock, mocker):
"foo",
"--password",
"bar",
"--debug",
],
)
@@ -610,3 +612,49 @@ async def test_shell(dev: Device, mocker):
res = await runner.invoke(cli, ["shell"], obj=dev)
assert res.exit_code == 0
embed.assert_called()
async def test_errors(mocker):
runner = CliRunner()
err = SmartDeviceException("Foobar")
# Test masking
mocker.patch("kasa.Discover.discover", side_effect=err)
res = await runner.invoke(
cli,
["--username", "foo", "--password", "bar"],
)
assert res.exit_code == 1
assert "Raised error: Foobar" in res.output
assert "Run with --debug enabled to see stacktrace" in res.output
assert isinstance(res.exception, SystemExit)
# Test --debug
res = await runner.invoke(
cli,
["--debug"],
)
assert res.exit_code == 1
assert "Raised error: Foobar" in res.output
assert res.exception == err
# Test no device passed to subcommand
mocker.patch("kasa.Discover.discover", return_value={})
res = await runner.invoke(
cli,
["sysinfo"],
)
assert res.exit_code == 1
assert (
"Raised error: Managed to invoke callback without a context object of type 'Device' existing."
in res.output
)
assert isinstance(res.exception, SystemExit)
# Test click error
res = await runner.invoke(
cli,
["--foobar"],
)
assert res.exit_code == 2
assert "Raised error:" not in res.output