mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-22 23:38:01 +00:00
Improve testing harness to allow tests on real devices (#197)
* test_cli: provide return values to patched objects to avoid warning about non-awaited calls * test_cli: restore alias after testing * smartstrip: remove internal update() calls for turn_{on,off}, set_led * Make sure power is always a float * Fix discovery tests * Make tests runnable on real devices * Add a note about running tests on a real device * test_strip: run update against the parent device
This commit is contained in:
@@ -18,7 +18,7 @@ async def test_state(dev, turn_on):
|
||||
await handle_turn_on(dev, turn_on)
|
||||
runner = CliRunner()
|
||||
res = await runner.invoke(state, obj=dev)
|
||||
print(res.output)
|
||||
await dev.update()
|
||||
|
||||
if dev.is_on:
|
||||
assert "Device state: ON" in res.output
|
||||
@@ -32,6 +32,8 @@ async def test_alias(dev):
|
||||
res = await runner.invoke(alias, obj=dev)
|
||||
assert f"Alias: {dev.alias}" in res.output
|
||||
|
||||
old_alias = dev.alias
|
||||
|
||||
new_alias = "new alias"
|
||||
res = await runner.invoke(alias, [new_alias], obj=dev)
|
||||
assert f"Setting alias to {new_alias}" in res.output
|
||||
@@ -39,6 +41,8 @@ async def test_alias(dev):
|
||||
res = await runner.invoke(alias, obj=dev)
|
||||
assert f"Alias: {new_alias}" in res.output
|
||||
|
||||
await dev.set_alias(old_alias)
|
||||
|
||||
|
||||
async def test_raw_command(dev):
|
||||
runner = CliRunner()
|
||||
@@ -63,11 +67,13 @@ async def test_emeter(dev: SmartDevice, mocker):
|
||||
assert "== Emeter ==" in res.output
|
||||
|
||||
monthly = mocker.patch.object(dev, "get_emeter_monthly")
|
||||
monthly.return_value = []
|
||||
res = await runner.invoke(emeter, ["--year", "1900"], obj=dev)
|
||||
assert "For year" in res.output
|
||||
monthly.assert_called()
|
||||
|
||||
daily = mocker.patch.object(dev, "get_emeter_daily")
|
||||
daily.return_value = []
|
||||
res = await runner.invoke(emeter, ["--month", "1900-12"], obj=dev)
|
||||
assert "For month" in res.output
|
||||
daily.assert_called()
|
||||
|
Reference in New Issue
Block a user