Skip to content

Commit

Permalink
feat: ComAux ability to clear receiving buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien THOMAS committed Jul 6, 2022
1 parent 0a6e3ea commit 126fcd8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/test_suite_1/test_suite_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
using TestApp.
"""

import logging
import importlib
import logging
from itertools import cycle

import pykiso
Expand Down
11 changes: 10 additions & 1 deletion src/pykiso/lib/auxiliaries/communication_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,27 @@ def send_message(self, raw_msg: bytes) -> bool:
return self.run_command("send", raw_msg, timeout_in_s=None)

def receive_message(
self, blocking: bool = True, timeout_in_s: float = None
self,
blocking: bool = True,
timeout_in_s: float = None,
empty_queue: bool = True,
) -> Optional[bytes]:
"""Receive a raw message.
:param blocking: wait for message till timeout elapses?
:param timeout_in_s: maximum time in second to wait for a response
:param empty_queue: empty buffer flag
:returns: raw message
"""
log.debug(
f"retrieving message in {self} (blocking={blocking}, timeout={timeout_in_s})"
)

if empty_queue:
log.info("Clearing receiving buffer.")
self.queue_out = self.queue_out.empty()

response = self.wait_and_get_report(
blocking=blocking, timeout_in_s=timeout_in_s
)
Expand Down
2 changes: 1 addition & 1 deletion src/pykiso/test_coordinator/test_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Handle common communication with device under test
**************************************************
When using a Remote TestCase/TestSuite, the integration test framework handles
When using a Remote TestCase/TestSuite, the integration test framework handles
internal messaging and control flow using a message format defined in
:py:class:`pykiso.Message`. :py:mod:`pykiso.test_message_handler`
defines the messaging protocol from a behavioral point of view.
Expand Down
15 changes: 10 additions & 5 deletions tests/test_com_aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
##########################################################################

import logging
import queue

import pytest

Expand Down Expand Up @@ -136,9 +137,7 @@ def test_run_command_valid(
expected_function_return,
):
com_aux_init.logger = logging.Logger("ok")
mock_channel = mocker.patch.object(
com_aux_init.channel, "cc_send", side_effect=side_effect_mock
)
mocker.patch.object(com_aux_init.channel, "cc_send", side_effect=side_effect_mock)
with caplog.at_level(logging.INFO):
result_create_inst = com_aux_init._run_command("send")
assert result_create_inst is expected_function_return
Expand Down Expand Up @@ -183,9 +182,15 @@ def test_receive_message_exception(mocker, com_aux_init, caplog):
)


def test_receive_message_none(mocker, com_aux_init):
@pytest.mark.parametrize("clear_buffer", [True, False])
def test_receive_message_none(mocker, com_aux_init, clear_buffer):
mocker.patch.object(com_aux_init, "wait_and_get_report", return_value=None)
recv = com_aux_init.receive_message(2)
mock_empty = mocker.patch.object(queue.Queue, "empty")

recv = com_aux_init.receive_message(timeout_in_s=2, empty_queue=clear_buffer)

if clear_buffer:
mock_empty.assert_called_once()

assert recv is None

Expand Down
2 changes: 1 addition & 1 deletion tests/test_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# SPDX-License-Identifier: EPL-2.0
##########################################################################

import unittest
import logging
import unittest
from functools import partial

import pytest
Expand Down

0 comments on commit 126fcd8

Please sign in to comment.