mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Raise CLI errors in debug mode (#771)
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user