Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some mypy type checking errors in test_transaction.py #2250

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions test/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down