Skip to content

Commit

Permalink
kiss unit tests: Check frame queue handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlongland committed May 26, 2024
1 parent 2d5b34c commit f093282
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion tests/test_kiss/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
KISSPort,
)
from ..loop import DummyLoop
from asyncio import BaseEventLoop
from asyncio import BaseEventLoop, Future


class DummyKISSDevice(BaseKISSDevice):
Expand Down Expand Up @@ -467,6 +467,67 @@ def _on_fail(**kwargs):
assert failures == []


def test_send_data_emptybuffer():
"""
Test that _send_data will pick the next frame off the transmit queue if
it has nothing to send in the buffer.
"""
loop = DummyLoop()
kissdev = DummyKISSDevice(loop=loop)
my_future = Future()
assert bytes(kissdev._tx_buffer) == b""

kissdev._tx_queue = [(b"test output data", my_future)]

failures = []

def _on_fail(**kwargs):
failures.append(kwargs)

kissdev.failed.connect(_on_fail)

# Send the data out.
kissdev._send_data()

# We should now see this was "sent" and now in 'transmitted'
assert bytes(kissdev.transmitted) == b"\xc0test output data\xc0"

# my_future should be the current transmit future
assert kissdev._tx_future is my_future

# That should be the lot
assert len(loop.calls) == 0

# There should be no failures
assert failures == []


def test_send_data_emptybuffer_emptyqueue():
"""
Test that _send_data does nothing if all queues are empty.
"""
loop = DummyLoop()
kissdev = DummyKISSDevice(loop=loop)
assert bytes(kissdev._tx_buffer) == b""
assert kissdev._tx_queue == []

failures = []

def _on_fail(**kwargs):
failures.append(kwargs)

kissdev.failed.connect(_on_fail)

# Send the data out.
kissdev._send_data()

# That should be the lot
assert len(loop.calls) == 0

# There should be no failures
assert failures == []


def test_send_data_fail():
"""
Test that _send_data puts device in failed state if send fails.
Expand Down

0 comments on commit f093282

Please sign in to comment.