chore: add documentation RI
Code functionality left unchanged, only added docs where missing close: N25B-298
This commit is contained in:
@@ -17,10 +17,15 @@ class MicrophoneUtils(object):
|
||||
|
||||
def test_choose_mic_default(self, pyaudio_instance):
|
||||
"""
|
||||
The result must contain at least "index", as this is used to identify the microphone.
|
||||
The "name" is used for logging, so it should also exist.
|
||||
It must have one or more channels.
|
||||
Lastly it must be capable of sending at least 16000 samples per second.
|
||||
Tests that the default microphone selection function returns a valid
|
||||
microphone dictionary containing all necessary keys with correct types and values.
|
||||
|
||||
The result must contain at least "index", as this is used to identify the microphone,
|
||||
and "name" for logging. It must have one or more channels (`maxInputChannels`),
|
||||
and a default sample rate of at least 16000 Hz.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance used to query microphone information.
|
||||
:type pyaudio_instance: PyAudio
|
||||
"""
|
||||
result = choose_mic_default(pyaudio_instance)
|
||||
assert "index" in result
|
||||
@@ -39,7 +44,15 @@ class MicrophoneUtils(object):
|
||||
|
||||
def test_choose_mic_interactive_input_not_int(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
First mock an input that's not an integer, then a valid integer. There should be no errors.
|
||||
Tests the robustness of the interactive selection when the user first enters
|
||||
a non-integer value, ensuring the system prompts again without error and accepts
|
||||
a valid integer on the second attempt.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
microphones = get_microphones(pyaudio_instance)
|
||||
target_microphone = next(microphones)
|
||||
@@ -59,7 +72,14 @@ class MicrophoneUtils(object):
|
||||
|
||||
def test_choose_mic_interactive_negative_index(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Make sure that the interactive method does not allow negative integers as input.
|
||||
Tests that the interactive selection method prevents the user from entering
|
||||
a negative integer as a microphone index.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
microphones = get_microphones(pyaudio_instance)
|
||||
target_microphone = next(microphones)
|
||||
@@ -79,7 +99,14 @@ class MicrophoneUtils(object):
|
||||
|
||||
def test_choose_mic_interactive_index_too_high(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Make sure that the interactive method does not allow indices higher than the highest mic index.
|
||||
Tests that the interactive selection method prevents the user from entering
|
||||
an index that exceeds the total number of available microphones.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
real_count = len(list(get_microphones(pyaudio_instance)))
|
||||
mock_input = mocker.patch("__builtin__.raw_input", side_effect=[str(real_count), "0"])
|
||||
@@ -96,7 +123,15 @@ class MicrophoneUtils(object):
|
||||
|
||||
def test_choose_mic_interactive_random_index(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Get a random index from the list of available mics, make sure it's correct.
|
||||
Tests the core interactive functionality by simulating the selection of a
|
||||
random valid microphone index and verifying that the correct microphone
|
||||
information is returned.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
microphones = list(get_microphones(pyaudio_instance))
|
||||
random_index = random.randrange(len(microphones))
|
||||
@@ -115,6 +150,16 @@ class MicrophoneUtils(object):
|
||||
assert result is None
|
||||
|
||||
def test_choose_mic_arguments(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Tests `choose_mic_arguments` when the microphone name is passed as a separate
|
||||
argument.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
for mic in get_microphones(pyaudio_instance):
|
||||
mocker.patch.object(sys, "argv", ["--microphone", mic["name"]])
|
||||
|
||||
@@ -124,6 +169,16 @@ class MicrophoneUtils(object):
|
||||
assert result == mic
|
||||
|
||||
def test_choose_mic_arguments_eq(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Tests `choose_mic_arguments` when the microphone name is passed using an
|
||||
equals sign (`--microphone=NAME`).
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
for mic in get_microphones(pyaudio_instance):
|
||||
mocker.patch.object(sys, "argv", ["--microphone={}".format(mic["name"])])
|
||||
|
||||
@@ -132,7 +187,17 @@ class MicrophoneUtils(object):
|
||||
assert result is not None
|
||||
assert result == mic
|
||||
|
||||
def test_choose_mic_arguments_not_exits(self, pyaudio_instance, mocker):
|
||||
def test_choose_mic_arguments_not_exist(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Tests `choose_mic_arguments` when a non-existent microphone name is passed
|
||||
via command-line arguments, expecting the function to return None.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
mocker.patch.object(sys, "argv", ["--microphone", "Surely this microphone doesn't exist"])
|
||||
|
||||
result = choose_mic_arguments(pyaudio_instance)
|
||||
@@ -140,6 +205,16 @@ class MicrophoneUtils(object):
|
||||
assert result is None
|
||||
|
||||
def test_choose_mic_with_argument(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Tests `choose_mic` function when a valid microphone is
|
||||
specified via command-line arguments.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
mic = next(get_microphones(pyaudio_instance))
|
||||
mocker.patch.object(sys, "argv", ["--microphone", mic["name"]])
|
||||
|
||||
@@ -149,6 +224,17 @@ class MicrophoneUtils(object):
|
||||
assert result == mic
|
||||
|
||||
def test_choose_mic_no_argument(self, pyaudio_instance, mocker):
|
||||
"""
|
||||
Tests `choose_mic` function when no command-line arguments
|
||||
are provided, verifying that the function falls back correctly to the
|
||||
system's default microphone selection.
|
||||
|
||||
:param pyaudio_instance: A mocked or real PyAudio instance.
|
||||
:type pyaudio_instance: PyAudio
|
||||
|
||||
:param mocker: The fixture used for mocking built-in functions and system objects.
|
||||
:type mocker: pytest_mock.plugin.MockerFixture
|
||||
"""
|
||||
default_mic = choose_mic_default(pyaudio_instance)
|
||||
mocker.patch.object(sys, "argv", [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user