mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Split out main cli module into lazily loaded submodules (#1039)
This commit is contained in:
@@ -17,29 +17,28 @@ from kasa import (
|
||||
Module,
|
||||
UnsupportedDeviceError,
|
||||
)
|
||||
from kasa.cli.main import (
|
||||
TYPE_TO_CLASS,
|
||||
from kasa.cli.device import (
|
||||
alias,
|
||||
brightness,
|
||||
cli,
|
||||
cmd_command,
|
||||
effect,
|
||||
emeter,
|
||||
energy,
|
||||
hsv,
|
||||
led,
|
||||
raw_command,
|
||||
reboot,
|
||||
state,
|
||||
sysinfo,
|
||||
temperature,
|
||||
time,
|
||||
toggle,
|
||||
update_credentials,
|
||||
wifi,
|
||||
)
|
||||
from kasa.cli.light import (
|
||||
brightness,
|
||||
effect,
|
||||
hsv,
|
||||
temperature,
|
||||
)
|
||||
from kasa.cli.main import TYPES, _legacy_type_to_class, cli, cmd_command, raw_command
|
||||
from kasa.cli.time import time
|
||||
from kasa.cli.usage import emeter, energy
|
||||
from kasa.cli.wifi import wifi
|
||||
from kasa.discover import Discover, DiscoveryResult
|
||||
from kasa.iot import IotDevice
|
||||
from kasa.smart import SmartDevice
|
||||
|
||||
from .conftest import (
|
||||
device_smart,
|
||||
@@ -59,6 +58,12 @@ def runner():
|
||||
return runner
|
||||
|
||||
|
||||
async def test_help(runner):
|
||||
"""Test that all the lazy modules are correctly names."""
|
||||
res = await runner.invoke(cli, ["--help"])
|
||||
assert res.exit_code == 0, "--help failed, check lazy module names"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("device_family", "encrypt_type"),
|
||||
[
|
||||
@@ -500,7 +505,7 @@ async def test_credentials(discovery_mock, mocker, runner):
|
||||
f"Username:{dev.credentials.username} Password:{dev.credentials.password}"
|
||||
)
|
||||
|
||||
mocker.patch("kasa.cli.main.state", new=_state)
|
||||
mocker.patch("kasa.cli.device.state", new=_state)
|
||||
|
||||
dr = DiscoveryResult(**discovery_mock.discovery_data["result"])
|
||||
res = await runner.invoke(
|
||||
@@ -735,7 +740,7 @@ async def test_host_auth_failed(discovery_mock, mocker, runner):
|
||||
assert isinstance(res.exception, AuthenticationError)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", list(TYPE_TO_CLASS))
|
||||
@pytest.mark.parametrize("device_type", TYPES)
|
||||
async def test_type_param(device_type, mocker, runner):
|
||||
"""Test for handling only one of username or password supplied."""
|
||||
result_device = FileNotFoundError
|
||||
@@ -746,8 +751,11 @@ async def test_type_param(device_type, mocker, runner):
|
||||
nonlocal result_device
|
||||
result_device = dev
|
||||
|
||||
mocker.patch("kasa.cli.main.state", new=_state)
|
||||
expected_type = TYPE_TO_CLASS[device_type]
|
||||
mocker.patch("kasa.cli.device.state", new=_state)
|
||||
if device_type == "smart":
|
||||
expected_type = SmartDevice
|
||||
else:
|
||||
expected_type = _legacy_type_to_class(device_type)
|
||||
mocker.patch.object(expected_type, "update")
|
||||
res = await runner.invoke(
|
||||
cli,
|
||||
|
Reference in New Issue
Block a user