Skip to content

Commit

Permalink
Update test_modbus_modbus.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudrat9 authored Nov 18, 2024
1 parent f360f89 commit 46b4eaa
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sunspec2/tests/test_modbus_modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,20 @@ def test_write(self, monkeypatch):
check_req = b"\x00\x00\x00\x00\x00'\x01\x10\x9ct\x00\x10 sn-000\x00\x00\x00\x00\x00\x00\x00" \
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
assert c.socket.request[0] == check_req

def test_write_over_max_size(self, monkeypatch):
c = modbus_client.ModbusClientTCP()
monkeypatch.setattr(socket, 'socket', MockSocket.mock_socket)
c.connect()
data_to_write = bytearray((c.max_write_count+1)*2)
data_to_write[:6] = b'sn-000'

buffer = [b'\x00\x00\x00\x00\x00\x06\x01\x10\x9ct\x00\x7b',
b'\x00\x00\x00\x00\x00\x06\x01\x10\x9c\xef\x00\x01']
c.socket._set_buffer(buffer)
c.write(40052, data_to_write)

check_req0 = b"\x00\x00\x00\x00\x00\xfd\x01" + b"\x10\x9ct\x00{\xf6" + data_to_write[:(c.max_write_count*2)]
check_req1 = b"\x00\x00\x00\x00\x00\x09\x01" + b"\x10\x9c\xef\x00\x01\x02\x00\x00"
assert c.socket.request[0] == check_req0
assert c.socket.request[1] == check_req1

0 comments on commit 46b4eaa

Please sign in to comment.