Skip to content

Commit 52a04c3

Browse files
committed
add test
1 parent 324940d commit 52a04c3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/test_loop.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff 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

7089
if __name__ == "__main__":
7190
main()

0 commit comments

Comments
 (0)