diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 0000000..792a419 --- /dev/null +++ b/tests/test_client.py @@ -0,0 +1,41 @@ +"""Tests for MumbleClient dispatcher and callback wiring.""" + +from tuimble.client import MumbleClient + + +def test_default_state(): + client = MumbleClient(host="localhost") + assert client.connected is False + assert client.users == {} + assert client.channels == {} + assert client.my_channel_id is None + + +def test_dispatcher_routes_callback(): + client = MumbleClient(host="localhost") + calls = [] + client.set_dispatcher(lambda fn, *a: calls.append((fn, a))) + + sentinel = object() + client.on_connected = sentinel + client._dispatch(client.on_connected) + assert len(calls) == 1 + assert calls[0] == (sentinel, ()) + + +def test_dispatch_without_dispatcher_calls_directly(): + client = MumbleClient(host="localhost") + results = [] + + def callback(): + results.append("called") + + client.on_connected = callback + client._dispatch(client.on_connected) + assert results == ["called"] + + +def test_dispatch_skips_none_callback(): + client = MumbleClient(host="localhost") + # Should not raise + client._dispatch(None)