From ef4886b68c4470b0f437ff00a3e3d647336b3b15 Mon Sep 17 00:00:00 2001 From: Alex <52292902+alexrudd2@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:11:02 -0500 Subject: [PATCH] Fix some mypy type checking errors in test_transaction.py (#2250) --- test/test_transaction.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/test/test_transaction.py b/test/test_transaction.py index 546807f64..2508c34ff 100755 --- a/test/test_transaction.py +++ b/test/test_transaction.py @@ -120,10 +120,9 @@ def test_execute(self, mock_time): assert trans.retries == 3 assert not trans.retry_on_empty - trans.getTransaction = mock.MagicMock() - trans.getTransaction.return_value = "response" + trans.getTransaction = mock.MagicMock(return_value = b"response") response = trans.execute(request) - assert response == "response" + assert response == b"response" # No response trans._recv = mock.MagicMock( # pylint: disable=protected-access return_value=b"abcdef" @@ -195,33 +194,20 @@ def test_transaction_manager_tid(self): def test_get_transaction_manager_transaction(self): """Test the getting a transaction from the transaction manager.""" - - class Request: # pylint: disable=too-few-public-methods - """Request.""" - self._manager.reset() - handle = Request() - handle.transaction_id = ( # pylint: disable=attribute-defined-outside-init - self._manager.getNextTID() + handle = ModbusRequest( + 0, self._manager.getNextTID(), 0, False ) - handle.message = b"testing" # pylint: disable=attribute-defined-outside-init self._manager.addTransaction(handle) result = self._manager.getTransaction(handle.transaction_id) - assert handle.message == result.message + assert handle is result def test_delete_transaction_manager_transaction(self): """Test deleting a transaction from the dict transaction manager.""" - - class Request: # pylint: disable=too-few-public-methods - """Request.""" - self._manager.reset() - handle = Request() - handle.transaction_id = ( # pylint: disable=attribute-defined-outside-init - self._manager.getNextTID() + handle = ModbusRequest( + 0, self._manager.getNextTID(), 0, False ) - handle.message = b"testing" # pylint: disable=attribute-defined-outside-init - self._manager.addTransaction(handle) self._manager.delTransaction(handle.transaction_id) assert not self._manager.getTransaction(handle.transaction_id)