File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,11 @@ def test_loop_basic(self) -> None:
4444 ssl_context = ssl .create_default_context (),
4545 )
4646
47- with patch .object (mqtt_client , "_wait_for_msg" ) as wait_for_msg_mock , \
48- patch .object (mqtt_client , "is_connected" ) as is_connected_mock :
47+ with patch .object (
48+ mqtt_client , "_wait_for_msg"
49+ ) as wait_for_msg_mock , patch .object (
50+ mqtt_client , "is_connected"
51+ ) as is_connected_mock :
4952
5053 wait_for_msg_mock .side_effect = self .fake_wait_for_msg
5154 is_connected_mock .side_effect = lambda : True
@@ -66,6 +69,22 @@ def test_loop_basic(self) -> None:
6669 assert ret_code == expected_rc
6770 expected_rc += 1
6871
72+ def test_loop_is_connected (self ):
73+ """
74+ loop() should throw MMQTTException if not connected
75+ """
76+ mqtt_client = MQTT .MQTT (
77+ broker = "127.0.0.1" ,
78+ port = 1883 ,
79+ socket_pool = socket ,
80+ ssl_context = ssl .create_default_context (),
81+ )
82+
83+ with self .assertRaises (MQTT .MMQTTException ) as context :
84+ mqtt_client .loop (timeout = 1 )
85+
86+ assert "not connected" in str (context .exception )
87+
6988
7089if __name__ == "__main__" :
7190 main ()
You can’t perform that action at this time.
0 commit comments