mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
f9a987ca18
* Add doctests to SmartBulb * Add SmartDevice doctests, cleanup README.md * add doctests for smartplug and smartstrip * add discover doctests * Fix bulb mock * add smartdimmer doctests * add sphinx-generated docs, cleanup readme a bit * remove sphinx-click as it does not work with asyncclick * in preparation for rtd hooking, move doc deps to be separate from dev deps * pytestmark needs to be applied separately for each and every file, this fixes the tests * use pathlib for resolving relative paths * Skip discovery doctest on python3.7 The code is just fine, but some reason the mocking behaves differently between 3.7 and 3.8. The latter seems to accept a discrete object for asyncio.run where the former expects a coroutine..
115 lines
2.7 KiB
Python
115 lines
2.7 KiB
Python
from asyncclick.testing import CliRunner
|
|
|
|
from kasa import SmartDevice
|
|
from kasa.cli import alias, brightness, emeter, raw_command, state, sysinfo
|
|
|
|
from .conftest import handle_turn_on, pytestmark, turn_on
|
|
|
|
|
|
async def test_sysinfo(dev):
|
|
runner = CliRunner()
|
|
res = await runner.invoke(sysinfo, obj=dev)
|
|
assert "System info" in res.output
|
|
assert dev.alias in res.output
|
|
|
|
|
|
@turn_on
|
|
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)
|
|
|
|
if dev.is_on:
|
|
assert "Device state: ON" in res.output
|
|
else:
|
|
assert "Device state: OFF" in res.output
|
|
|
|
|
|
async def test_alias(dev):
|
|
runner = CliRunner()
|
|
|
|
res = await runner.invoke(alias, obj=dev)
|
|
assert f"Alias: {dev.alias}" in res.output
|
|
|
|
new_alias = "new alias"
|
|
res = await runner.invoke(alias, [new_alias], obj=dev)
|
|
assert f"Setting alias to {new_alias}" in res.output
|
|
|
|
res = await runner.invoke(alias, obj=dev)
|
|
assert f"Alias: {new_alias}" in res.output
|
|
|
|
|
|
async def test_raw_command(dev):
|
|
runner = CliRunner()
|
|
res = await runner.invoke(raw_command, ["system", "get_sysinfo"], obj=dev)
|
|
|
|
assert res.exit_code == 0
|
|
assert dev.alias in res.output
|
|
|
|
res = await runner.invoke(raw_command, obj=dev)
|
|
assert res.exit_code != 0
|
|
assert "Usage" in res.output
|
|
|
|
|
|
async def test_emeter(dev: SmartDevice, mocker):
|
|
runner = CliRunner()
|
|
|
|
res = await runner.invoke(emeter, obj=dev)
|
|
if not dev.has_emeter:
|
|
assert "Device has no emeter" in res.output
|
|
return
|
|
|
|
assert "== Emeter ==" in res.output
|
|
|
|
monthly = mocker.patch.object(dev, "get_emeter_monthly")
|
|
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")
|
|
res = await runner.invoke(emeter, ["--month", "1900-12"], obj=dev)
|
|
assert "For month" in res.output
|
|
daily.assert_called()
|
|
|
|
|
|
async def test_brightness(dev):
|
|
runner = CliRunner()
|
|
res = await runner.invoke(brightness, obj=dev)
|
|
if not dev.is_dimmable:
|
|
assert "This device does not support brightness." in res.output
|
|
return
|
|
|
|
res = await runner.invoke(brightness, obj=dev)
|
|
assert f"Brightness: {dev.brightness}" in res.output
|
|
|
|
res = await runner.invoke(brightness, ["12"], obj=dev)
|
|
assert "Setting brightness" in res.output
|
|
|
|
res = await runner.invoke(brightness, obj=dev)
|
|
assert "Brightness: 12" in res.output
|
|
|
|
|
|
async def test_temperature(dev):
|
|
pass
|
|
|
|
|
|
async def test_hsv(dev):
|
|
pass
|
|
|
|
|
|
async def test_led(dev):
|
|
pass
|
|
|
|
|
|
async def test_on(dev):
|
|
pass
|
|
|
|
|
|
async def test_off(dev):
|
|
pass
|
|
|
|
|
|
async def test_reboot(dev):
|
|
pass
|