Skip to content

Commit

Permalink
Coverage == 91%. (#2132)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Mar 28, 2024
1 parent 86d5afe commit 331dc63
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
5 changes: 1 addition & 4 deletions pymodbus/framer/socket_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def frameProcessIncomingPacket(self, single, callback, slave, tid=None, **kwargs
while True:
used_len, use_tid, dev_id, data = self.message_handler.decode(self._buffer)
if not data:
if not used_len:
return
self._buffer = self._buffer[used_len :]
continue
return
self._header["uid"] = dev_id
self._header["tid"] = use_tid
self._header["pid"] = 0
Expand Down
12 changes: 2 additions & 10 deletions pymodbus/framer/tls_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
ModbusIOException,
)
from pymodbus.framer.base import TLS_FRAME_HEADER, ModbusFramer
from pymodbus.logging import Log
from pymodbus.message.tls import MessageTLS


Expand Down Expand Up @@ -44,25 +43,18 @@ def decode_data(self, data):
return {"fcode": fcode}
return {}

def frameProcessIncomingPacket(self, single, callback, slave, _tid=None, **kwargs):
def frameProcessIncomingPacket(self, _single, callback, _slave, _tid=None, **kwargs):
"""Process new packet pattern."""
# no slave id for Modbus Security Application Protocol

while True:
used_len, use_tid, dev_id, data = self.message_handler.decode(self._buffer)
if not data:
if not used_len:
return
self._buffer = self._buffer[used_len :]
continue
return
self._header["uid"] = dev_id
self._header["tid"] = use_tid
self._header["pid"] = 0

if not self._validate_slave_id(slave, single):
Log.debug("Not in valid slave id - {}, ignoring!!", slave)
self.resetFrame()
return
if (result := self.decoder.decode(data)) is None:
raise ModbusIOException("Unable to decode request")
self.populateResult(result)
Expand Down
3 changes: 3 additions & 0 deletions pymodbus/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ def __init__(self, function_code, **kwargs):
def decode(self, _data):
"""Decode so this failure will run correctly."""

def encode(self):
"""Decode so this failure will run correctly."""

def execute(self, _context):
"""Build an illegal function request error response.
Expand Down
2 changes: 2 additions & 0 deletions test/test_framers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ModbusAsciiFramer,
ModbusRtuFramer,
ModbusSocketFramer,
ModbusTlsFramer,
)
from pymodbus.transport import CommType
from pymodbus.utilities import ModbusTransactionState
Expand Down Expand Up @@ -481,6 +482,7 @@ def test_processincomingpacket_ok(self, framer, message, slave):
(ModbusAsciiFramer, b':01270001000ACD\r\n',),
(ModbusRtuFramer, b"\x01\x03\x03\x01\x00\n\x94\x49",),
(ModbusSocketFramer, b'\x00\x00\x00\x00\x00\x06\x01\x27\x00\x01\x00\n',),
(ModbusTlsFramer, b'\x54\x00\x7c\x00\x02',),
]
)
def test_processincomingpacket_not_ok(self, framer, message):
Expand Down

0 comments on commit 331dc63

Please sign in to comment.