Skip to content

Commit

Permalink
Fix test_message_with_timeout
Browse files Browse the repository at this point in the history
Need to send a real request (so we know how much data to wait for), use
a request that has more response data than the request (in terms of
bytes) to trigger when a Timeout should be detected properly.
  • Loading branch information
lutostag committed May 19, 2018
1 parent 1154d72 commit 9cf56c9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/unit/client/serial/test_rtu.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import pytest
from serial import serial_for_url

from umodbus.client.serial.rtu import send_message
from umodbus.client.serial.rtu import send_message, read_coils


def test_send_message_with_timeout():
""" Test if TimoutError is raised when serial port doesn't receive data."""
""" Test if TimoutError is raised when serial port doesn't receive enough
data.
"""
s = serial_for_url('loop://', timeout=0)
# as we are using a loop, we need the request will be read back as response
# to test timeout we need a request with a response that needs more bytes
message = read_coils(slave_id=0, starting_address=1, quantity=40)

with pytest.raises(ValueError):
send_message(b'', s)
send_message(message, s)

0 comments on commit 9cf56c9

Please sign in to comment.