10000 add tests · python-kasa/python-kasa@85a147a · GitHub
[go: up one dir, main page]

Skip to content

Commit 85a147a

Browse files
committed
add tests
1 parent 66f101c commit 85a147a

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/smart/modules/test_speaker.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
from pytest_mock import MockerFixture
5+
6+
from kasa import Module
7+
from kasa.smart import SmartDevice
8+
9+
from ...device_fixtures import get_parent_and_child_modules, parametrize
10+
11+
speaker = parametrize(
12+
"has speaker", component_filter="speaker", protocol_filter={"SMART"}
13+
)
14+
15+
16+
@speaker
17+
@pytest.mark.parametrize(
18+
("feature", "prop_name", "type"),
19+
[
20+
("volume", "volume", int),
21+
],
22+
)
23+
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
24+
"""Test that features are registered and work as expected."""
25+
speaker = next(get_parent_and_child_modules(dev, Module.Speaker))
26+
assert speaker is not None
27+
28+
prop = getattr(speaker, prop_name)
29+
assert isinstance(prop, type)
30+
31+
feat = speaker._device.features[feature]
32+
assert feat.value == prop
33+
assert isinstance(feat.value, type)
34+
35+
36+
@speaker
37+
async def test_set_volume(dev: SmartDevice, mocker: MockerFixture):
38+
"""Test speaker settings."""
39+
speaker = next(get_parent_and_child_modules(dev, Module.Speaker))
40+
call = mocker.spy(speaker, "call")
41+
42+
volume = speaker._device.features["volume"]
43+
assert speaker.volume == volume.volume
44+
45+
new_volume = 15
46+
await speaker.set_volume(new_volume)
47+
48+
await dev.update()
49+
50+
call.assert_called_with("setVolume", {"volume": new_volume})
51+
52+
await dev.update()
53+
54+
assert speaker.volume == new_volume
55+
56+
57+
@speaker
58+
async def test_locate(dev: SmartDevice, mocker: MockerFixture):
59+
"""Test the locate method."""
60+
speaker = next(get_parent_and_child_modules(dev, Module.Speaker))
61+
call = mocker.spy(speaker, "call")
62+
63+
call.assert_called_with("playSelectAudio", {"audio_type": "seek_me"})

0 commit comments

Comments
 (0)
0