chore: add documentation RI
Code functionality left unchanged, only added docs where missing close: N25B-298
This commit is contained in:
@@ -11,11 +11,26 @@ from robot_interface.endpoints.audio_sender import AudioSender
|
||||
|
||||
@pytest.fixture
|
||||
def zmq_context():
|
||||
"""
|
||||
A pytest fixture that creates and yields a ZMQ context.
|
||||
|
||||
:return: An initialized ZeroMQ context.
|
||||
:rtype: zmq.Context
|
||||
"""
|
||||
context = zmq.Context()
|
||||
yield context
|
||||
|
||||
|
||||
def test_no_microphone(zmq_context, mocker):
|
||||
"""
|
||||
Tests the scenario where no valid microphone can be chosen for recording.
|
||||
|
||||
:param zmq_context: The ZeroMQ context fixture.
|
||||
:type zmq_context: zmq.Context
|
||||
|
||||
:param mocker: The pytest-mock fixture used to patch internal dependencies.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
mock_info_logger = mocker.patch("robot_interface.endpoints.audio_sender.logger.info")
|
||||
mock_choose_mic = mocker.patch("robot_interface.endpoints.audio_sender.choose_mic")
|
||||
mock_choose_mic.return_value = None
|
||||
@@ -31,6 +46,16 @@ def test_no_microphone(zmq_context, mocker):
|
||||
|
||||
|
||||
def test_unicode_mic_name(zmq_context, mocker):
|
||||
"""
|
||||
Tests the robustness of the `AudioSender` when handling microphone names
|
||||
that contain Unicode characters.
|
||||
|
||||
:param zmq_context: The ZeroMQ context fixture.
|
||||
:type zmq_context: zmq.Context
|
||||
|
||||
:param mocker: The pytest-mock fixture used to patch internal dependencies.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
mocker.patch("robot_interface.endpoints.audio_sender.threading")
|
||||
mock_choose_mic = mocker.patch("robot_interface.endpoints.audio_sender.choose_mic")
|
||||
mock_choose_mic.return_value = {"name": u"• Some Unicode name"}
|
||||
@@ -47,10 +72,25 @@ def test_unicode_mic_name(zmq_context, mocker):
|
||||
|
||||
|
||||
def _fake_read(num_frames):
|
||||
"""
|
||||
Helper function to simulate reading raw audio data from a microphone stream.
|
||||
|
||||
:param num_frames: The number of audio frames requested.
|
||||
:type num_frames: int
|
||||
|
||||
:return: A byte string containing random data, simulating audio.
|
||||
:rtype: str
|
||||
"""
|
||||
return os.urandom(num_frames * 4)
|
||||
|
||||
|
||||
def test_sending_audio(mocker):
|
||||
"""
|
||||
Tests the successful sending of audio data over a ZeroMQ socket.
|
||||
|
||||
:param mocker: The pytest-mock fixture used to patch internal dependencies.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
mock_choose_mic = mocker.patch("robot_interface.endpoints.audio_sender.choose_mic")
|
||||
mock_choose_mic.return_value = {"name": u"Some mic", "index": 0L}
|
||||
|
||||
@@ -76,10 +116,22 @@ def test_sending_audio(mocker):
|
||||
|
||||
|
||||
def _fake_read_error(num_frames):
|
||||
"""
|
||||
Helper function to simulate an I/O error during microphone stream reading.
|
||||
|
||||
:param num_frames: The number of audio frames requested.
|
||||
:type num_frames: int
|
||||
"""
|
||||
raise IOError()
|
||||
|
||||
|
||||
def test_break_microphone(mocker):
|
||||
"""
|
||||
Tests the error handling when the microphone stream breaks (raises an IOError).
|
||||
|
||||
:param mocker: The pytest-mock fixture used to patch internal dependencies.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
mock_choose_mic = mocker.patch("robot_interface.endpoints.audio_sender.choose_mic")
|
||||
mock_choose_mic.return_value = {"name": u"Some mic", "index": 0L}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user