feat: add application parameter to choose a custom microphone
ref: N25B-119
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
from __future__ import unicode_literals # So that we can format strings with Unicode characters
|
||||
import random
|
||||
import sys
|
||||
from StringIO import StringIO
|
||||
|
||||
from robot_interface.utils.microphone import choose_mic_default, choose_mic_interactive, get_microphones
|
||||
from robot_interface.utils.microphone import (
|
||||
choose_mic_default,
|
||||
choose_mic_interactive,
|
||||
choose_mic_arguments,
|
||||
choose_mic,
|
||||
get_microphones,
|
||||
)
|
||||
|
||||
|
||||
class MicrophoneUtils(object):
|
||||
@@ -93,3 +100,53 @@ class MicrophoneUtils(object):
|
||||
assert "index" in result
|
||||
assert isinstance(result["index"], (int, long))
|
||||
assert result["index"] == microphones[random_index]["index"]
|
||||
|
||||
def test_choose_mic_no_arguments(self, pyaudio_instance, mocker):
|
||||
mocker.patch.object(sys, "argv", [])
|
||||
|
||||
result = choose_mic_arguments(pyaudio_instance)
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_choose_mic_arguments(self, pyaudio_instance, mocker):
|
||||
for mic in get_microphones(pyaudio_instance):
|
||||
mocker.patch.object(sys, "argv", ["--microphone", mic["name"]])
|
||||
|
||||
result = choose_mic_arguments(pyaudio_instance)
|
||||
|
||||
assert result is not None
|
||||
assert result == mic
|
||||
|
||||
def test_choose_mic_arguments_eq(self, pyaudio_instance, mocker):
|
||||
for mic in get_microphones(pyaudio_instance):
|
||||
mocker.patch.object(sys, "argv", ["--microphone={}".format(mic["name"])])
|
||||
|
||||
result = choose_mic_arguments(pyaudio_instance)
|
||||
|
||||
assert result is not None
|
||||
assert result == mic
|
||||
|
||||
def test_choose_mic_arguments_not_exits(self, pyaudio_instance, mocker):
|
||||
mocker.patch.object(sys, "argv", ["--microphone", "Surely this microphone doesn't exist"])
|
||||
|
||||
result = choose_mic_arguments(pyaudio_instance)
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_choose_mic_with_argument(self, pyaudio_instance, mocker):
|
||||
mic = next(get_microphones(pyaudio_instance))
|
||||
mocker.patch.object(sys, "argv", ["--microphone", mic["name"]])
|
||||
|
||||
result = choose_mic(pyaudio_instance)
|
||||
|
||||
assert result is not None
|
||||
assert result == mic
|
||||
|
||||
def test_choose_mic_no_argument(self, pyaudio_instance, mocker):
|
||||
default_mic = choose_mic_default(pyaudio_instance)
|
||||
mocker.patch.object(sys, "argv", [])
|
||||
|
||||
result = choose_mic(pyaudio_instance)
|
||||
|
||||
assert result is not None
|
||||
assert result == default_mic
|
||||
|
||||
Reference in New Issue
Block a user