diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index c28f5cf01..0820cf161 100755 --- a/examples/client_custom_msg.py +++ b/examples/client_custom_msg.py @@ -38,7 +38,8 @@ class CustomModbusPDU(ModbusPDU): def __init__(self, values=None, slave=1, transaction=0, skip_encode=False): """Initialize.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.values = values or [] def encode(self): @@ -70,7 +71,8 @@ class CustomRequest(ModbusPDU): def __init__(self, address=None, slave=1, transaction=0, skip_encode=False): """Initialize.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.count = 16 diff --git a/pymodbus/pdu/bit_read_message.py b/pymodbus/pdu/bit_read_message.py index cb879e87d..e37a6985e 100644 --- a/pymodbus/pdu/bit_read_message.py +++ b/pymodbus/pdu/bit_read_message.py @@ -20,7 +20,8 @@ def __init__(self, address, count, slave, transaction, skip_encode): :param count: The number of bits after "address" to read :param slave: Modbus slave slave ID """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.count = count @@ -70,7 +71,8 @@ def __init__(self, values, slave, transaction, skip_encode): :param values: The requested values to be returned :param slave: Modbus slave slave ID """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) #: A list of booleans representing bit values self.bits = values or [] diff --git a/pymodbus/pdu/bit_write_message.py b/pymodbus/pdu/bit_write_message.py index a8270afb4..ad995f9a7 100644 --- a/pymodbus/pdu/bit_write_message.py +++ b/pymodbus/pdu/bit_write_message.py @@ -49,7 +49,8 @@ def __init__(self, address=None, value=None, slave=None, transaction=0, skip_enc :param address: The variable address to write :param value: The value to write at address """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.value = bool(value) @@ -116,7 +117,8 @@ def __init__(self, address=None, value=None, slave=1, transaction=0, skip_encode :param address: The variable address written to :param value: The value written at address """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.value = value @@ -170,7 +172,8 @@ def __init__(self, address=0, values=None, slave=None, transaction=0, skip_encod :param address: The starting request address :param values: The values to write """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address if values is None: # pragma: no cover values = [] @@ -246,7 +249,8 @@ def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode :param address: The starting variable address written to :param count: The number of values written """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.count = count diff --git a/pymodbus/pdu/decoders.py b/pymodbus/pdu/decoders.py index f2df9bbde..6df645b8e 100644 --- a/pymodbus/pdu/decoders.py +++ b/pymodbus/pdu/decoders.py @@ -98,7 +98,8 @@ def decode(self, frame: bytes) -> base.ModbusPDU | None: if not (pdu_type := self.lookup.get(function_code, None)): Log.debug("decode PDU failed for function code {}", function_code) raise ModbusException(f"Unknown response {function_code}") - pdu = pdu_type(0, 0, False) + pdu = pdu_type() + pdu.setData(0, 0, False) Log.debug("decode PDU for {}", function_code) pdu.decode(frame[1:]) diff --git a/pymodbus/pdu/diag_message.py b/pymodbus/pdu/diag_message.py index 686c8bd52..3fa580334 100644 --- a/pymodbus/pdu/diag_message.py +++ b/pymodbus/pdu/diag_message.py @@ -34,7 +34,8 @@ class DiagnosticStatusRequest(ModbusPDU): def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a diagnostic request.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.message = None def encode(self): @@ -95,7 +96,8 @@ class DiagnosticStatusResponse(ModbusPDU): def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a diagnostic response.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.message = None def encode(self): diff --git a/pymodbus/pdu/file_message.py b/pymodbus/pdu/file_message.py index 96804b8ad..163375792 100644 --- a/pymodbus/pdu/file_message.py +++ b/pymodbus/pdu/file_message.py @@ -94,7 +94,8 @@ def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): :param records: The file record requests to be read """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -159,7 +160,8 @@ def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): :param records: The requested file records """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -215,7 +217,8 @@ def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): :param records: The file record requests to be read """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -279,7 +282,8 @@ def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): :param records: The file record requests to be read """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -344,7 +348,8 @@ def __init__(self, address=0x0000, slave=1, transaction=0, skip_encode=False): :param address: The fifo pointer address (0x0000 to 0xffff) """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.values = [] # this should be added to the context @@ -405,7 +410,8 @@ def __init__(self, values=None, slave=1, transaction=0, skip_encode=False): :param values: The list of values of the fifo to return """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.values = values or [] def encode(self): diff --git a/pymodbus/pdu/mei_message.py b/pymodbus/pdu/mei_message.py index 75f4b53d2..0085f23dc 100644 --- a/pymodbus/pdu/mei_message.py +++ b/pymodbus/pdu/mei_message.py @@ -58,7 +58,8 @@ def __init__(self, read_code=None, object_id=0x00, slave=1, transaction=0, skip_ :param read_code: The device information read code :param object_id: The object to read from """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.read_code = read_code or DeviceInformation.BASIC self.object_id = object_id @@ -136,7 +137,8 @@ def __init__(self, read_code=None, information=None, slave=1, transaction=0, ski :param read_code: The device information read code :param information: The requested information request """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.read_code = read_code or DeviceInformation.BASIC self.information = information or {} self.number_of_objects = 0 diff --git a/pymodbus/pdu/other_message.py b/pymodbus/pdu/other_message.py index fd5b5d6bd..597a37bde 100644 --- a/pymodbus/pdu/other_message.py +++ b/pymodbus/pdu/other_message.py @@ -32,7 +32,8 @@ class ReadExceptionStatusRequest(ModbusPDU): def __init__(self, slave=None, transaction=0, skip_encode=0): """Initialize a new instance.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -74,7 +75,8 @@ def __init__(self, status=0x00, slave=1, transaction=0, skip_encode=False): :param status: The status response to report """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.status = status if status < 256 else 255 def encode(self): @@ -131,7 +133,8 @@ class GetCommEventCounterRequest(ModbusPDU): def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a new instance.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -174,7 +177,8 @@ def __init__(self, count=0x0000, slave=1, transaction=0, skip_encode=False): :param count: The current event counter value """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.count = count self.status = True # this means we are ready, not waiting @@ -236,7 +240,8 @@ class GetCommEventLogRequest(ModbusPDU): def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a new instance.""" - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -289,7 +294,8 @@ def __init__(self, status=True, message_count=0, event_count=0, events=None, sla :param event_count: The current event count :param events: The collection of events to send """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.status = status self.message_count = message_count self.event_count = event_count @@ -361,7 +367,8 @@ def __init__(self, slave=1, transaction=0, skip_encode=False): :param slave: Modbus slave slave ID """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -420,7 +427,8 @@ def __init__(self, identifier=b"\x00", status=True, slave=1, transaction=0, skip :param identifier: The identifier of the slave :param status: The status response to report """ - ModbusPDU.__init__(self, slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.identifier = identifier self.status = status self.byte_count = None diff --git a/pymodbus/pdu/pdu.py b/pymodbus/pdu/pdu.py index f75932914..5a07014ed 100644 --- a/pymodbus/pdu/pdu.py +++ b/pymodbus/pdu/pdu.py @@ -17,22 +17,20 @@ class ModbusPDU: _rtu_frame_size: int = 0 _rtu_byte_count_pos: int = 0 - def __init__(self, slave: int, transaction: int, skip_encode: bool) -> None: + def __init__(self) -> None: """Initialize the base data for a modbus request.""" + self.transaction_id: int + self.slave_id: int + self.skip_encode: bool + self.bits: list[bool] + self.registers: list[int] + self.fut: asyncio.Future + + def setData(self, slave: int, transaction: int, skip_encode: bool) -> None: + """Set data common for all PDU.""" self.transaction_id = transaction self.slave_id = slave self.skip_encode = skip_encode - self.bits: list[bool] = [] - self.registers: list[int] = [] - self.fut: asyncio.Future | None = None - - @abstractmethod - def encode(self) -> bytes: - """Encode the message.""" - - @abstractmethod - def decode(self, data: bytes) -> None: - """Decode data part of the message.""" def doException(self, exception: int) -> ExceptionResponse: """Build an error response based on the function.""" @@ -48,6 +46,14 @@ def get_response_pdu_size(self) -> int: """Calculate response pdu size.""" return 0 + @abstractmethod + def encode(self) -> bytes: + """Encode the message.""" + + @abstractmethod + def decode(self, data: bytes) -> None: + """Decode data part of the message.""" + @classmethod def calculateRtuFrameSize(cls, data: bytes) -> int: @@ -63,7 +69,6 @@ def calculateRtuFrameSize(cls, data: bytes) -> int: ) - class ModbusExceptions: # pylint: disable=too-few-public-methods """An enumeration of the valid modbus exceptions.""" @@ -102,7 +107,8 @@ def __init__( transaction: int = 0, skip_encode: bool = False) -> None: """Initialize the modbus exception response.""" - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.function_code = function_code | 0x80 self.exception_code = exception_code diff --git a/pymodbus/pdu/register_read_message.py b/pymodbus/pdu/register_read_message.py index f60ad4b5b..524f05091 100644 --- a/pymodbus/pdu/register_read_message.py +++ b/pymodbus/pdu/register_read_message.py @@ -21,7 +21,8 @@ def __init__(self, address, count, slave=1, transaction=0, skip_encode=False): :param count: The number of registers to read :param slave: Modbus slave slave ID """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.count = count @@ -68,7 +69,8 @@ def __init__(self, values, slave=1, transaction=0, skip_encode=False): :param values: The values to write to :param slave: Modbus slave slave ID """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) #: A list of register values self.registers = values or [] @@ -263,7 +265,8 @@ def __init__(self, read_address=0x00, read_count=0, write_address=0x00, write_re :param write_address: The address to start writing to :param write_registers: The registers to write to the specified address """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.read_address = read_address self.read_count = read_count self.write_address = write_address diff --git a/pymodbus/pdu/register_write_message.py b/pymodbus/pdu/register_write_message.py index 328e9a263..bb94bad18 100644 --- a/pymodbus/pdu/register_write_message.py +++ b/pymodbus/pdu/register_write_message.py @@ -26,7 +26,8 @@ def __init__(self, address=None, value=None, slave=None, transaction=0, skip_enc :param address: The address to start writing add :param value: The values to write """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.value = value @@ -97,7 +98,8 @@ def __init__(self, address=0, value=0, slave=1, transaction=0, skip_encode=False :param address: The address to start writing add :param value: The values to write """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.value = value @@ -158,7 +160,8 @@ def __init__(self, address=0, values=None, slave=None, transaction=0, skip_encod :param address: The address to start writing to :param values: The values to write """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address if values is None: values = [] @@ -248,7 +251,8 @@ def __init__(self, address=0, count=0, slave=1, transaction=0, skip_encode=False :param address: The address to start writing to :param count: The number of registers to write to """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.count = count @@ -297,7 +301,8 @@ def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, tra :param and_mask: The and bitmask to apply to the register address :param or_mask: The or bitmask to apply to the register address """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.and_mask = and_mask self.or_mask = or_mask @@ -352,7 +357,8 @@ def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, tra :param and_mask: The and bitmask applied to the register address :param or_mask: The or bitmask applied to the register address """ - super().__init__(slave, transaction, skip_encode) + super().__init__() + super().setData(slave, transaction, skip_encode) self.address = address self.and_mask = and_mask self.or_mask = or_mask diff --git a/test/framer/test_framer.py b/test/framer/test_framer.py index 78d23893a..cce0d98bd 100644 --- a/test/framer/test_framer.py +++ b/test/framer/test_framer.py @@ -431,7 +431,8 @@ def test_processIncomingFrame_roundtrip(self, entry, test_framer, msg, dev_id, t def test_framer_encode(self, test_framer, msg): """Test a tcp frame transaction.""" with mock.patch.object(ModbusPDU, "encode") as mock_encode: - message = ModbusPDU(0, 0, False) + message = ModbusPDU() + message.setData(0, 0, False) message.transaction_id = 0x0001 message.slave_id = 0xFF message.function_code = 0x01 diff --git a/test/pdu/test_all_messages.py b/test/pdu/test_all_messages.py deleted file mode 100644 index e2581e9d4..000000000 --- a/test/pdu/test_all_messages.py +++ /dev/null @@ -1,93 +0,0 @@ -"""Test all messages.""" -from pymodbus.pdu.bit_read_message import ( - ReadCoilsRequest, - ReadCoilsResponse, - ReadDiscreteInputsRequest, - ReadDiscreteInputsResponse, -) -from pymodbus.pdu.bit_write_message import ( - WriteMultipleCoilsRequest, - WriteMultipleCoilsResponse, - WriteSingleCoilRequest, - WriteSingleCoilResponse, -) -from pymodbus.pdu.register_read_message import ( - ReadHoldingRegistersRequest, - ReadHoldingRegistersResponse, - ReadInputRegistersRequest, - ReadInputRegistersResponse, - ReadWriteMultipleRegistersRequest, - ReadWriteMultipleRegistersResponse, -) -from pymodbus.pdu.register_write_message import ( - WriteMultipleRegistersRequest, - WriteMultipleRegistersResponse, - WriteSingleRegisterRequest, - WriteSingleRegisterResponse, -) - - -# ---------------------------------------------------------------------------# -# Fixture -# ---------------------------------------------------------------------------# - - -class TestAllMessages: - """All messages tests.""" - - # -----------------------------------------------------------------------# - # Setup/TearDown - # -----------------------------------------------------------------------# - - requests = [ - lambda slave: ReadCoilsRequest(1, 5, slave=slave), - lambda slave: ReadDiscreteInputsRequest(1, 5, slave=slave), - lambda slave: WriteSingleCoilRequest(1, 1, slave=slave), - lambda slave: WriteMultipleCoilsRequest(1, [1], slave=slave), - lambda slave: ReadHoldingRegistersRequest(1, 5, slave=slave), - lambda slave: ReadInputRegistersRequest(1, 5, slave=slave), - lambda slave: ReadWriteMultipleRegistersRequest( - slave=slave, - read_address=1, - read_count=1, - write_address=1, - write_registers=1, - ), - lambda slave: WriteSingleRegisterRequest(1, 1, slave=slave), - lambda slave: WriteMultipleRegistersRequest(1, [1], slave=slave), - ] - responses = [ - lambda slave: ReadCoilsResponse([1], slave=slave), - lambda slave: ReadDiscreteInputsResponse([1], slave=slave), - lambda slave: WriteSingleCoilResponse(1, 1, slave=slave), - lambda slave: WriteMultipleCoilsResponse(1, [1], slave=slave), - lambda slave: ReadHoldingRegistersResponse([1], slave=slave), - lambda slave: ReadInputRegistersResponse([1], slave=slave), - lambda slave: ReadWriteMultipleRegistersResponse([1], slave=slave), - lambda slave: WriteSingleRegisterResponse(1, 1, slave=slave), - lambda slave: WriteMultipleRegistersResponse(1, 1, slave=slave), - ] - - def test_initializing_slave_address_request(self): - """Test that every request can initialize the slave id.""" - slave_id = 0x12 - for factory in self.requests: - request = factory(slave_id) - assert request.slave_id == slave_id - - def test_initializing_slave_address_response(self): - """Test that every response can initialize the slave id.""" - slave_id = 0x12 - for factory in self.responses: - response = factory(slave_id) - assert response.slave_id == slave_id - - def test_forwarding_to_pdu(self): - """Test that parameters are forwarded to the pdu correctly.""" - request = ReadCoilsRequest(1, 5, slave=18, transaction=0x12,) - assert request.slave_id == 0x12 - assert request.transaction_id == 0x12 - - request = ReadCoilsRequest(1, 5) - assert request.slave_id == 1 - assert not request.transaction_id diff --git a/test/pdu/test_pdu.py b/test/pdu/test_pdu.py index 6895341ae..9b9344218 100644 --- a/test/pdu/test_pdu.py +++ b/test/pdu/test_pdu.py @@ -31,7 +31,8 @@ async def test_is_error(self): def test_request_exception(self): """Test request exception.""" - request = ModbusPDU(0, 0, False) + request = ModbusPDU() + request.setData(0, 0, False) request.function_code = 1 errors = {ModbusExceptions.decode(c): c for c in range(1, 20)} for error, code in iter(errors.items()): diff --git a/test/pdu/test_pdutype.py b/test/pdu/test_pdutype.py index 0c2e07fb5..38a16cfb9 100644 --- a/test/pdu/test_pdutype.py +++ b/test/pdu/test_pdutype.py @@ -111,6 +111,19 @@ def test_pdu_instance_args(self, pdutype, kwargs): assert pdu assert str(pdu) + @pytest.mark.parametrize(("pdutype", "kwargs", "framer"), requests + responses) + @pytest.mark.usefixtures("framer") + def test_pdu_instance_extras(self, pdutype, kwargs): + """Test that all PDU types can be created.""" + tid = 9112 + slave_id = 63 + pdu = pdutype(transaction=tid, slave=slave_id, **kwargs) + assert pdu + assert str(pdu) + assert pdu.slave_id == slave_id + assert pdu.transaction_id == tid + assert pdu.function_code > 0 + @pytest.mark.parametrize(("pdutype", "kwargs", "framer"), requests + responses) @pytest.mark.usefixtures("framer") def test_pdu_instance_encode(self, pdutype, kwargs): diff --git a/test/sub_client/test_client.py b/test/sub_client/test_client.py index 1bb08847c..44482e241 100755 --- a/test/sub_client/test_client.py +++ b/test/sub_client/test_client.py @@ -240,8 +240,10 @@ async def test_client_instanciate( # a unsuccessful connect client.connect = lambda: False client.transport = None + pdu = ModbusPDU() + pdu.setData(0, 0, False) with pytest.raises(ConnectionException): - client.execute(False, ModbusPDU(0, 0, False)) + client.execute(False, pdu) async def test_client_modbusbaseclient(): """Test modbus base client class.""" @@ -690,14 +692,18 @@ async def test_client_build_response(): None, comm_params=CommParams(), ) + pdu = ModbusPDU() + pdu.setData(0, 0, False) with pytest.raises(ConnectionException): - await client.build_response(ModbusPDU(0, 0, False)) + await client.build_response(pdu) async def test_client_mixin_execute(): """Test dummy execute for both sync and async.""" client = ModbusClientMixin() + pdu = ModbusPDU() + pdu.setData(0, 0, False) with pytest.raises(NotImplementedError): - client.execute(False, ModbusPDU(0, 0, False)) + client.execute(False, pdu) with pytest.raises(NotImplementedError): - await client.execute(False, ModbusPDU(0, 0, False)) + await client.execute(False, pdu) diff --git a/test/sub_current/test_transaction.py b/test/sub_current/test_transaction.py index 4b9ff7e58..c24c28d79 100755 --- a/test/sub_current/test_transaction.py +++ b/test/sub_current/test_transaction.py @@ -165,7 +165,8 @@ def test_transaction_manager_tid(self): def test_get_transaction_manager_transaction(self): """Test the getting a transaction from the transaction manager.""" self._manager.reset() - handle = ModbusPDU(0, self._manager.getNextTID(), False) + handle = ModbusPDU() + handle.setData(0, self._manager.getNextTID(), False) self._manager.addTransaction(handle) result = self._manager.getTransaction(handle.transaction_id) assert handle is result @@ -173,7 +174,8 @@ def test_get_transaction_manager_transaction(self): def test_delete_transaction_manager_transaction(self): """Test deleting a transaction from the dict transaction manager.""" self._manager.reset() - handle = ModbusPDU(0, self._manager.getNextTID(), False) + handle = ModbusPDU() + handle.setData(0, self._manager.getNextTID(), False) self._manager.addTransaction(handle) self._manager.delTransaction(handle.transaction_id) assert not self._manager.getTransaction(handle.transaction_id)