Skip to content

Commit f7f47c1

Browse files
committed
Add tests for errors when observing properties/actions.
There was no test for observing something that wasn't a property, or something that wasn't an action. These are added.
1 parent 7683649 commit f7f47c1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_websocket.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_websocket_observeproperty(server):
3232

3333
class ThingWithProperties(lt.Thing):
3434
dataprop: int = lt.property(default=0)
35+
non_property: int = 0
3536

3637
@lt.property
3738
def funcprop(self) -> int:
@@ -41,6 +42,11 @@ def funcprop(self) -> int:
4142
def set_funcprop(self, val: int) -> None:
4243
pass
4344

45+
@lt.thing_action
46+
def increment_dataprop(self):
47+
"""Increment the data property."""
48+
self.dataprop += 1
49+
4450

4551
def test_observing_dataprop(mocker):
4652
"""Check `observe_property` is OK on a data property.
@@ -99,6 +105,26 @@ def test_observing_missing_prop(mocker):
99105
thing.observe_property("missing_property", mocker.Mock())
100106

101107

108+
def test_observing_not_prop(mocker):
109+
"""Check observing an attribute that's not a property raises an error."""
110+
thing = ThingWithProperties()
111+
with pytest.raises(KeyError):
112+
thing.observe_property("non_property", mocker.Mock())
113+
114+
115+
def test_observing_action(mocker):
116+
"""Check observing an action is successful."""
117+
thing = ThingWithProperties()
118+
thing.observe_action("increment_dataprop", mocker.Mock())
119+
120+
121+
def test_observing_not_action(mocker):
122+
"""Check observing an attribute that's not an action raises an error."""
123+
thing = ThingWithProperties()
124+
with pytest.raises(KeyError):
125+
thing.observe_action("non_property", mocker.Mock())
126+
127+
102128
def test_websocket_observeproperty_counter(server):
103129
with TestClient(server.app) as client:
104130
with client.websocket_connect("/my_thing/ws") as ws:

0 commit comments

Comments
 (0)