Skip to content

Commit

Permalink
Temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Nov 16, 2024
1 parent 30b6636 commit 5d95b8a
Showing 1 changed file with 7 additions and 45 deletions.
52 changes: 7 additions & 45 deletions test/transaction/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,47 +159,6 @@ def test_sync_transaction_instance(self, use_clc):
TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client)
TransactionManager(use_clc, FramerRTU(DecodePDU(True)), 5, True, sync_client=client)

def test_sync_transaction_manager_tid(self, use_clc):
"""Test next TID."""
client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc)
transact = TransactionManager(use_clc, client.framer, 5, False, sync_client=client)
assert transact.getNextTID() == 1
for tid in range(2, 12):
assert tid == transact.getNextTID()
assert transact.getNextTID() == 12
transact.next_tid = 64999
assert transact.getNextTID() == 65000
assert transact.getNextTID() == 1

def test_sync_transaction_cbs(self, use_clc):
"""Test dummy calls from transport."""
client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc)
transact = TransactionManager(use_clc, client.framer, 5, False, sync_client=client)
transact.callback_new_connection()
transact.callback_connected()

@pytest.mark.parametrize("test", [True, False])
def test_sync_transaction_data(self, use_clc, test):
"""Test tracers in disconnect."""
client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc)
transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client)
transact.framer.processIncomingFrame = mock.Mock(return_value=(0, None))
packet = b'123'
transact.callback_data(packet)
assert not transact.response_future.done()
transact.trace_recv_packet = mock.Mock()
pdu = "dummy pdu"
if test:
transact.framer.processIncomingFrame.return_value = (1, pdu)
transact.callback_data(packet)
transact.trace_recv_packet.assert_called_once_with(packet)
else:
transact.trace_recv_pdu = mock.Mock(return_value=pdu)
transact.framer.processIncomingFrame.return_value = (1, pdu)
transact.callback_data(packet)
transact.trace_recv_packet.assert_called_with(packet)
transact.trace_recv_pdu.assert_called_once_with(pdu)
assert transact.response_future.result() == pdu

@pytest.mark.parametrize("scenario", range(6))
async def test_sync_transaction_execute(self, use_clc, scenario):
Expand All @@ -209,7 +168,7 @@ async def test_sync_transaction_execute(self, use_clc, scenario):
transact.send = mock.Mock()
transact.sync_client.connect = mock.Mock(return_value=True)
request = ReadCoilsRequest(address=117, count=5)
response = ReadCoilsResponse(bits=[True, False, True, True, False])
response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False])
transact.retries = 0
if scenario == 0: # transport not ok and no connect
transact.transport = None
Expand All @@ -218,7 +177,7 @@ async def test_sync_transaction_execute(self, use_clc, scenario):
transact.sync_execute(False, request)
elif scenario == 1: # transport not ok and connect, no trace
transact.transport = None
transact.sync_client.connect = mock.AsyncMock(return_value=True)
transact.sync_client.connect = mock.Mock(return_value=True)
transact.sync_execute(True, request)
elif scenario == 2: # transport ok, trace and send
transact.trace_send_pdu = mock.Mock(return_value=request)
Expand All @@ -235,10 +194,13 @@ async def test_sync_transaction_execute(self, use_clc, scenario):
transact.comm_params.timeout_connect = 0.1
assert not transact.sync_execute(False, request)
elif scenario == 5: # response
pytest.fail("TBD!")
transact.transport = 1
resp_bytes = transact.framer.buildFrame(response)
transact.sync_client.recv = mock.Mock(return_value=resp_bytes)
transact.sync_client.send = mock.Mock()
transact.comm_params.timeout_connect = 0.2
resp = transact.sync_execute(False, request)
assert response == resp
assert response.bits == resp.bits

def test_sync_transaction_receiver(self, use_clc):
"""Test tracers in disconnect."""
Expand Down

0 comments on commit 5d95b8a

Please sign in to comment.