import sys import unittest import importlib from pathlib import Path from unittest import mock sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) sys.modules.pop("cthulhu.speech", None) speech = importlib.import_module("cthulhu.speech") class PresentationInterruptSoundRegressionTests(unittest.TestCase): def test_speech_stop_also_stops_sound_playback(self): speechServer = mock.Mock() echoServer = mock.Mock() soundPlayer = mock.Mock() with ( mock.patch.object(speech, "_speechserver", speechServer), mock.patch.object(speech, "_echoSpeechserver", echoServer), mock.patch.object(speech.sound, "getPlayer", return_value=soundPlayer), ): speech.stop() speechServer.stop.assert_called_once_with() echoServer.stop.assert_called_once_with() soundPlayer.stop.assert_called_once_with() if __name__ == "__main__": unittest.main()