Merge pull request #332 from jodal/feature/dummy-audio

Add dummy audio actor
This commit is contained in:
Stein Magnus Jodal 2013-02-25 14:12:20 -08:00
commit 86a7c2d751
6 changed files with 78 additions and 6 deletions

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
# flake8: noqa
from .actor import Audio
from .dummy import DummyAudio
from .listener import AudioListener
from .constants import PlaybackState
from .utils import (calculate_duration, create_buffer, millisecond_to_clocktime,

68
mopidy/audio/dummy.py Normal file
View File

@ -0,0 +1,68 @@
"""A dummy audio actor for use in tests.
This class implements the audio API in the simplest way possible. It is used in
tests of the core and backends.
"""
from __future__ import unicode_literals
import pykka
from .constants import PlaybackState
from .listener import AudioListener
class DummyAudio(pykka.ThreadingActor):
def __init__(self):
super(DummyAudio, self).__init__()
self.state = PlaybackState.STOPPED
self._position = 0
def set_on_end_of_track(self, callback):
pass
def set_uri(self, uri):
pass
def set_appsrc(self, *args, **kwargs):
pass
def emit_data(self, buffer_):
pass
def emit_end_of_stream(self):
pass
def get_position(self):
return self._position
def set_position(self, position):
self._position = position
return True
def start_playback(self):
return self._change_state(PlaybackState.PLAYING)
def pause_playback(self):
return self._change_state(PlaybackState.PAUSED)
def prepare_change(self):
return True
def stop_playback(self):
return self._change_state(PlaybackState.STOPPED)
def get_volume(self):
return 0
def set_volume(self, volume):
pass
def set_metadata(self, track):
pass
def _change_state(self, new_state):
old_state, self.state = self.state, new_state
AudioListener.send(
'state_changed', old_state=old_state, new_state=new_state)
return True

View File

@ -10,7 +10,7 @@ from mopidy.backends import listener
@mock.patch.object(listener.BackendListener, 'send')
class BackendEventsTest(object):
def setUp(self):
self.audio = mock.Mock(spec=audio.Audio)
self.audio = audio.DummyAudio.start().proxy()
self.backend = self.backend_class.start(audio=self.audio).proxy()
self.core = core.Core.start(backends=[self.backend]).proxy()

View File

@ -4,6 +4,8 @@ import mock
import random
import time
import pykka
from mopidy import audio, core
from mopidy.core import PlaybackState
from mopidy.models import Track
@ -18,7 +20,7 @@ class PlaybackControllerTest(object):
tracks = []
def setUp(self):
self.audio = mock.Mock(spec=audio.Audio)
self.audio = audio.DummyAudio.start().proxy()
self.backend = self.backend_class.start(audio=self.audio).proxy()
self.core = core.Core(backends=[self.backend])
self.playback = self.core.playback
@ -29,6 +31,9 @@ class PlaybackControllerTest(object):
assert self.tracks[0].length >= 2000, \
'First song needs to be at least 2000 miliseconds'
def tearDown(self):
pykka.ActorRegistry.stop_all()
def test_initial_state_is_stopped(self):
self.assertEqual(self.playback.state, PlaybackState.STOPPED)

View File

@ -4,7 +4,6 @@ import os
import shutil
import tempfile
import mock
import pykka
from mopidy import audio, core, settings
@ -19,7 +18,7 @@ class PlaylistsControllerTest(object):
settings.LOCAL_TAG_CACHE_FILE = path_to_data_dir('library_tag_cache')
settings.LOCAL_MUSIC_PATH = path_to_data_dir('')
self.audio = mock.Mock(spec=audio.Audio)
self.audio = audio.DummyAudio.start().proxy()
self.backend = self.backend_class.start(audio=self.audio).proxy()
self.core = core.Core(backends=[self.backend])

View File

@ -1,6 +1,5 @@
from __future__ import unicode_literals
import mock
import random
import pykka
@ -16,7 +15,7 @@ class TracklistControllerTest(object):
tracks = []
def setUp(self):
self.audio = mock.Mock(spec=audio.Audio)
self.audio = audio.DummyAudio.start().proxy()
self.backend = self.backend_class.start(audio=self.audio).proxy()
self.core = core.Core(audio=self.audio, backends=[self.backend])
self.controller = self.core.tracklist