Added unittest for audioRecorder

This commit is contained in:
Manuel Cortez 2019-01-05 18:54:57 -06:00
parent 200d476462
commit 17e90c4761
3 changed files with 49 additions and 24 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest import unittest
testmodules = ["test.test_setup_py2exe", "test.test_base_interactor", "test.test_renderers"] testmodules = ["test.test_setup_py2exe", "test.test_base_interactor", "test.test_audiorecorder", "test.test_renderers"]
suite = unittest.TestSuite() suite = unittest.TestSuite()

View File

@ -9,34 +9,59 @@ class audioRecorderTestCase(unittest.TestCase):
""" Test both the presenter and interactor of the audio recorder feature. View stuff will be mocked.""" """ Test both the presenter and interactor of the audio recorder feature. View stuff will be mocked."""
# @mock.patch("presenters.audioRecorder.sound_lib", esp_set=True) @mock.patch("presenters.audioRecorder.sound_lib", esp_set=True)
# @mock.patch("presenters.audioRecorder.pub", esp_set=True) @mock.patch("presenters.audioRecorder.pub", esp_set=True)
# @mock.patch("presenters.audioRecorder.tempfile", esp_set=True) @mock.patch("presenters.audioRecorder.tempfile", esp_set=True)
# @mock.patch("presenters.audioRecorder.sound", esp_set=True) @mock.patch("presenters.audioRecorder.sound", esp_set=True)
# @mock.patch("presenters.audioRecorder.output", esp_set=True) @mock.patch("presenters.audioRecorder.output", esp_set=True)
# @mock.patch("presenters.audioRecorder.os", esp_set=True) @mock.patch("presenters.audioRecorder.os", esp_set=True)
# def test_audiorecorder_interactor(self, soundlib_mock, pub_mock, tempfile_mock, sound_mock, output_mock, os_mock, widgetUtils_mock, interactor_pub_mock): def test_audiorecorder_presenter(self, os_mock, output_mock, sound_mock, tempfile_mock, pub_mock, soundlib_mock):
# """ Test methods for audio recorder. """ """ Test methods for audio recorder presenter. """
# tempfile_mock.mktemp.return_value = "somefile.wav" tempfile_mock.mktemp.return_value = "somefile.wav"
# sound_mock.get_recording.return_value = "some_recording" sound_mock.get_recording.return_value = mock.MagicMock()
# view=mock.MagicMock(name="view") soundlib_mock.stream.fileStream.return_value = mock.MagicMock()
# interactor_ = interactor.audioRecorderInteractor() view=mock.MagicMock(name="view")
# presenter_ = presenter.audioRecorderPresenter(view=view, interactor=interactor_) interactor_ = mock.MagicMock(name="interactor", esp_set=interactor.audioRecorderInteractor)
# interactor_.install.assert_called_with(view=view, presenter=presenter_) presenter_ = presenter.audioRecorderPresenter(view=view, interactor=interactor_)
# interactor_.start.assert_called_with() # Start sending events to the presenter and see its reactions.
# # Start sending events to the presenter and see its reactions. presenter_.start_recording()
# presenter_.start_recording() tempfile_mock.mktemp.assert_any_call(suffix=".wav")
# print(presenter_.recording) sound_mock.get_recording.assert_any_call(presenter_.file)
presenter_.recording.play.assert_any_call()
pub_mock.sendMessage.assert_any_call("audiorecorder_set_label", control="record", label=_("&Stop"))
pub_mock.sendMessage.assert_any_call("audiorecorder_disable_control", control="ok")
presenter_.stop_recording()
presenter_.recording.stop.assert_any_call()
presenter_.recording.free.assert_any_call()
pub_mock.sendMessage.assert_any_call("audiorecorder_set_label", control="record", label=_("&Record"))
pub_mock.sendMessage.assert_any_call("audiorecorder_disable_control", control="record")
pub_mock.sendMessage.assert_any_call("audiorecorder_enable_control", control="play")
pub_mock.sendMessage.assert_any_call("audiorecorder_enable_control", control="discard")
pub_mock.sendMessage.assert_any_call("audiorecorder_enable_control", control="ok")
pub_mock.sendMessage.assert_any_call("audiorecorder_focus_control", control="play")
presenter_.discard_recording()
self.assertTrue(presenter_.playing==None)
@mock.patch("interactors.base.pub", esp_set=True)
@mock.patch("interactors.audioRecorder.widgetUtils", esp_set=True) @mock.patch("interactors.audioRecorder.widgetUtils", esp_set=True)
def test_audiorecorder_interactor(self, widgetUtils_mock, pub_mock): def test_audiorecorder_interactor(self, widgetUtils_mock):
pub_mock.subscribe.return_value = True
view=mock.MagicMock(name="view") view=mock.MagicMock(name="view")
interactor_ = interactor.audioRecorderInteractor() interactor_ = interactor.audioRecorderInteractor()
presenter_ = mock.MagicMock(name="Presenter", esp_set=presenter.audioRecorderPresenter) presenter_ = mock.MagicMock(name="Presenter", esp_set=presenter.audioRecorderPresenter)
interactor_.install(view=view, presenter=presenter_) interactor_.install(view=view, presenter=presenter_)
print(pub_mock.subscribe.called) # Test if events have been connected to WX
widgetUtils_mock.connect_event.assert_any_call(view.play, widgetUtils_mock.BUTTON_PRESSED, interactor_.on_play)
widgetUtils_mock.connect_event.assert_any_call(view.record, widgetUtils_mock.BUTTON_PRESSED, interactor_.on_record)
widgetUtils_mock.connect_event.assert_any_call(view.discard, widgetUtils_mock.BUTTON_PRESSED, interactor_.on_discard)
# Let's call some methods simulating user interaction.
interactor_.on_record()
presenter_.toggle_recording.assert_called_with()
interactor_.on_play()
presenter_.play.assert_called_with()
# Let's simulate user response here
view.get_response.return_value = widgetUtils_mock.OK
interactor_.start()
# this should call on_postprocess after receiving the OK signal.
presenter_.postprocess.assert_called_with()
def setUp(self): def setUp(self):
languageHandler.setLanguage("en") languageHandler.setLanguage("en")

View File

@ -26,7 +26,7 @@ class baseInteractorTestCase(unittest.TestCase):
interactor_.set_label(control="some_control", label="label") interactor_.set_label(control="some_control", label="label")
view.set.assert_called_with("some_control", "label") view.set.assert_called_with("some_control", "label")
interactor_.focus_control(control="some_control") interactor_.focus_control(control="some_control")
view.some_control.SetFocus() view.some_control.SetFocus.assert_called_with()
interactor_.uninstall() interactor_.uninstall()
pub_mock.unsubscribe.assert_any_call(interactor_.disable_control, "base_disable_control"), pub_mock.unsubscribe.assert_any_call(interactor_.disable_control, "base_disable_control"),
pub_mock.unsubscribe.assert_any_call(interactor_.enable_control, "base_enable_control"), pub_mock.unsubscribe.assert_any_call(interactor_.enable_control, "base_enable_control"),