client: add ConnectionFailed and reconnect method

This commit is contained in:
Username
2026-02-24 14:34:40 +01:00
parent 0b186f1f0c
commit a041069cc9
2 changed files with 101 additions and 14 deletions

View File

@@ -1,8 +1,8 @@
"""Tests for MumbleClient dispatcher and callback wiring."""
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from tuimble.client import MumbleClient
from tuimble.client import ConnectionFailed, MumbleClient
def test_default_state():
@@ -83,3 +83,40 @@ def test_cert_custom():
)
assert client._certfile == "/path/cert.pem"
assert client._keyfile == "/path/key.pem"
def test_connection_failed_retryable():
exc = ConnectionFailed("network error", retryable=True)
assert str(exc) == "network error"
assert exc.retryable is True
def test_connection_failed_not_retryable():
exc = ConnectionFailed("auth rejected", retryable=False)
assert str(exc) == "auth rejected"
assert exc.retryable is False
def test_connection_failed_default_retryable():
exc = ConnectionFailed("something broke")
assert exc.retryable is True
def test_reconnect_resets_state():
client = MumbleClient(host="localhost")
client._connected = True
client._mumble = MagicMock()
with patch.object(client, "connect"):
client.reconnect()
# disconnect should have cleared _mumble before connect
assert client._connected is False
def test_disconnect_clears_connected():
client = MumbleClient(host="localhost")
client._connected = True
client._mumble = MagicMock()
client.disconnect()
assert client.connected is False