def test_play_internals(self, play_wav_mock, play_ogg_mock, play_mp3_mock): bus = mock.Mock() process_mock = mock.Mock(name='process') completed = False def wait_for_completion(): nonlocal completed if not completed: return None else: completed = False return True process_mock.poll.side_effect = wait_for_completion play_wav_mock.return_value = process_mock play_ogg_mock.return_value = process_mock play_mp3_mock.return_value = process_mock service = simple.SimpleAudioService(config, bus) tracks = ['a.mp3', ['b.ogg', 'audio/ogg'], ['c.wav', 'audio/wav']] service.add_list(tracks) service.play() thread = Thread(target=service._play, args=[Message('plaything')]) thread.daemon = True thread.start() time.sleep(0.1) play_mp3_mock.assert_called_with('a.mp3') completed = True time.sleep(1) self.assertEqual(service.index, 1) thread.join() thread = Thread(target=service._play, args=[Message('plaything')]) thread.daemon = True thread.start() time.sleep(0.1) play_ogg_mock.assert_called_with('b.ogg') service.pause() process_mock.send_signal.assert_called_with(signal.SIGSTOP) self.assertEqual(service._paused, True) service.resume() self.assertEqual(service._paused, False) completed = True thread.join() thread = Thread(target=service._play, args=[Message('plaything')]) thread.daemon = True thread.start() time.sleep(0.2) play_wav_mock.assert_called_with('c.wav') service.stop() thread.join()
def test_playlist_methods(self): bus = mock.Mock() service = simple.SimpleAudioService(config, bus) self.assertEqual(service.tracks, []) self.assertTrue(isinstance(service.supported_uris(), list)) service.add_list(['a', 'b', 'c']) self.assertEqual(service.tracks, ['a', 'b', 'c']) service.clear_list() self.assertEqual(service.tracks, [])
def test_play(self): bus = mock.Mock() service = simple.SimpleAudioService(config, bus) service.play() self.assertTrue(bus.emit.called)