@@ -32,6 +32,7 @@ def test_websocket_observeproperty(server):
32
32
33
33
class ThingWithProperties (lt .Thing ):
34
34
dataprop : int = lt .property (default = 0 )
35
+ non_property : int = 0
35
36
36
37
@lt .property
37
38
def funcprop (self ) -> int :
@@ -41,6 +42,11 @@ def funcprop(self) -> int:
41
42
def set_funcprop (self , val : int ) -> None :
42
43
pass
43
44
45
+ @lt .thing_action
46
+ def increment_dataprop (self ):
47
+ """Increment the data property."""
48
+ self .dataprop += 1
49
+
44
50
45
51
def test_observing_dataprop (mocker ):
46
52
"""Check `observe_property` is OK on a data property.
@@ -99,6 +105,26 @@ def test_observing_missing_prop(mocker):
99
105
thing .observe_property ("missing_property" , mocker .Mock ())
100
106
101
107
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
+
102
128
def test_websocket_observeproperty_counter (server ):
103
129
with TestClient (server .app ) as client :
104
130
with client .websocket_connect ("/my_thing/ws" ) as ws :
0 commit comments