-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client more robust against faulty response. (#1547)
- Loading branch information
1 parent
d347bc8
commit 4334930
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Test server working as slave on a multidrop RS485 line.""" | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from pymodbus.exceptions import ModbusIOException | ||
from pymodbus.factory import ClientDecoder | ||
from pymodbus.framer import ModbusSocketFramer | ||
|
||
|
||
class TestFaultyResponses: | ||
"""Test that server works on a multidrop line.""" | ||
|
||
slaves = [0] | ||
|
||
good_frame = b"\x00\x01\x00\x00\x00\x05\x00\x03\x02\x00\x01" | ||
|
||
@pytest.fixture(name="framer") | ||
def fixture_framer(self): | ||
"""Prepare framer.""" | ||
return ModbusSocketFramer(ClientDecoder()) | ||
|
||
@pytest.fixture(name="callback") | ||
def fixture_callback(self): | ||
"""Prepare dummy callback.""" | ||
return mock.Mock() | ||
|
||
def test_ok_frame(self, framer, callback): | ||
"""Test ok frame.""" | ||
framer.processIncomingPacket(self.good_frame, callback, self.slaves) | ||
callback.assert_called_once() | ||
|
||
def test_faulty_frame1(self, framer, callback): | ||
"""Test ok frame.""" | ||
faulty_frame = b"\x00\x04\x00\x00\x00\x05\x00\x03\x0a\x00\x04" | ||
with pytest.raises(ModbusIOException): | ||
framer.processIncomingPacket(faulty_frame, callback, self.slaves) | ||
callback.assert_not_called() | ||
framer.processIncomingPacket(self.good_frame, callback, self.slaves) | ||
callback.assert_called_once() |
File renamed without changes.