add client dispatcher unit tests
This commit is contained in:
41
tests/test_client.py
Normal file
41
tests/test_client.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user