Merge pull request #984 from jodal/feature/move-dummies
Move dummies into the test package where they belong
This commit is contained in:
commit
4a38d1722c
@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
# flake8: noqa
|
# flake8: noqa
|
||||||
from .actor import Audio
|
from .actor import Audio
|
||||||
from .dummy import DummyAudio
|
|
||||||
from .listener import AudioListener
|
from .listener import AudioListener
|
||||||
from .constants import PlaybackState
|
from .constants import PlaybackState
|
||||||
from .utils import (
|
from .utils import (
|
||||||
|
|||||||
@ -2,8 +2,6 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pykka
|
|
||||||
|
|
||||||
from mopidy import listener
|
from mopidy import listener
|
||||||
|
|
||||||
|
|
||||||
@ -149,23 +147,3 @@ class MixerListener(listener.Listener):
|
|||||||
:type mute: bool
|
:type mute: bool
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DummyMixer(pykka.ThreadingActor, Mixer):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super(DummyMixer, self).__init__()
|
|
||||||
self._volume = None
|
|
||||||
self._mute = None
|
|
||||||
|
|
||||||
def get_volume(self):
|
|
||||||
return self._volume
|
|
||||||
|
|
||||||
def set_volume(self, volume):
|
|
||||||
self._volume = volume
|
|
||||||
|
|
||||||
def get_mute(self):
|
|
||||||
return self._mute
|
|
||||||
|
|
||||||
def set_mute(self, mute):
|
|
||||||
self._mute = mute
|
|
||||||
|
|||||||
@ -15,11 +15,10 @@ import mock
|
|||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import audio
|
from mopidy import audio
|
||||||
from mopidy.audio import dummy as dummy_audio
|
|
||||||
from mopidy.audio.constants import PlaybackState
|
from mopidy.audio.constants import PlaybackState
|
||||||
from mopidy.utils.path import path_to_uri
|
from mopidy.utils.path import path_to_uri
|
||||||
|
|
||||||
from tests import path_to_data_dir
|
from tests import dummy_audio, path_to_data_dir
|
||||||
|
|
||||||
# We want to make sure both our real audio class and the fake one behave
|
# We want to make sure both our real audio class and the fake one behave
|
||||||
# correctly. So each test is first run against the real class, then repeated
|
# correctly. So each test is first run against the real class, then repeated
|
||||||
|
|||||||
@ -7,14 +7,15 @@ import mock
|
|||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import core
|
from mopidy import core
|
||||||
from mopidy.backend import dummy
|
|
||||||
from mopidy.models import Track
|
from mopidy.models import Track
|
||||||
|
|
||||||
|
from tests import dummy_backend
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(core.CoreListener, 'send')
|
@mock.patch.object(core.CoreListener, 'send')
|
||||||
class BackendEventsTest(unittest.TestCase):
|
class BackendEventsTest(unittest.TestCase):
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.backend = dummy.create_dummy_backend_proxy()
|
self.backend = dummy_backend.create_proxy()
|
||||||
self.core = core.Core.start(backends=[self.backend]).proxy()
|
self.core = core.Core.start(backends=[self.backend]).proxy()
|
||||||
|
|
||||||
def tearDown(self): # noqa: N802
|
def tearDown(self): # noqa: N802
|
||||||
|
|||||||
@ -8,14 +8,17 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from .constants import PlaybackState
|
from mopidy import audio
|
||||||
from .listener import AudioListener
|
|
||||||
|
|
||||||
|
def create_proxy(config=None, mixer=None):
|
||||||
|
return DummyAudio.start(config, mixer).proxy()
|
||||||
|
|
||||||
|
|
||||||
class DummyAudio(pykka.ThreadingActor):
|
class DummyAudio(pykka.ThreadingActor):
|
||||||
def __init__(self, config=None, mixer=None):
|
def __init__(self, config=None, mixer=None):
|
||||||
super(DummyAudio, self).__init__()
|
super(DummyAudio, self).__init__()
|
||||||
self.state = PlaybackState.STOPPED
|
self.state = audio.PlaybackState.STOPPED
|
||||||
self._volume = 0
|
self._volume = 0
|
||||||
self._position = 0
|
self._position = 0
|
||||||
self._callback = None
|
self._callback = None
|
||||||
@ -42,21 +45,21 @@ class DummyAudio(pykka.ThreadingActor):
|
|||||||
|
|
||||||
def set_position(self, position):
|
def set_position(self, position):
|
||||||
self._position = position
|
self._position = position
|
||||||
AudioListener.send('position_changed', position=position)
|
audio.AudioListener.send('position_changed', position=position)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def start_playback(self):
|
def start_playback(self):
|
||||||
return self._change_state(PlaybackState.PLAYING)
|
return self._change_state(audio.PlaybackState.PLAYING)
|
||||||
|
|
||||||
def pause_playback(self):
|
def pause_playback(self):
|
||||||
return self._change_state(PlaybackState.PAUSED)
|
return self._change_state(audio.PlaybackState.PAUSED)
|
||||||
|
|
||||||
def prepare_change(self):
|
def prepare_change(self):
|
||||||
self._uri = None
|
self._uri = None
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def stop_playback(self):
|
def stop_playback(self):
|
||||||
return self._change_state(PlaybackState.STOPPED)
|
return self._change_state(audio.PlaybackState.STOPPED)
|
||||||
|
|
||||||
def get_volume(self):
|
def get_volume(self):
|
||||||
return self._volume
|
return self._volume
|
||||||
@ -84,21 +87,22 @@ class DummyAudio(pykka.ThreadingActor):
|
|||||||
if not self._uri:
|
if not self._uri:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.state == PlaybackState.STOPPED and self._uri:
|
if self.state == audio.PlaybackState.STOPPED and self._uri:
|
||||||
AudioListener.send('position_changed', position=0)
|
audio.AudioListener.send('position_changed', position=0)
|
||||||
AudioListener.send('stream_changed', uri=self._uri)
|
audio.AudioListener.send('stream_changed', uri=self._uri)
|
||||||
|
|
||||||
if new_state == PlaybackState.STOPPED:
|
if new_state == audio.PlaybackState.STOPPED:
|
||||||
self._uri = None
|
self._uri = None
|
||||||
AudioListener.send('stream_changed', uri=self._uri)
|
audio.AudioListener.send('stream_changed', uri=self._uri)
|
||||||
|
|
||||||
old_state, self.state = self.state, new_state
|
old_state, self.state = self.state, new_state
|
||||||
AudioListener.send('state_changed', old_state=old_state,
|
audio.AudioListener.send(
|
||||||
new_state=new_state, target_state=None)
|
'state_changed',
|
||||||
|
old_state=old_state, new_state=new_state, target_state=None)
|
||||||
|
|
||||||
if new_state == PlaybackState.PLAYING:
|
if new_state == audio.PlaybackState.PLAYING:
|
||||||
self._tags['audio-codec'] = [u'fake info...']
|
self._tags['audio-codec'] = [u'fake info...']
|
||||||
AudioListener.send('tags_changed', tags=['audio-codec'])
|
audio.AudioListener.send('tags_changed', tags=['audio-codec'])
|
||||||
|
|
||||||
return self._state_change_result
|
return self._state_change_result
|
||||||
|
|
||||||
@ -114,9 +118,9 @@ class DummyAudio(pykka.ThreadingActor):
|
|||||||
|
|
||||||
if not self._uri or not self._callback:
|
if not self._uri or not self._callback:
|
||||||
self._tags = {}
|
self._tags = {}
|
||||||
AudioListener.send('reached_end_of_stream')
|
audio.AudioListener.send('reached_end_of_stream')
|
||||||
else:
|
else:
|
||||||
AudioListener.send('position_changed', position=0)
|
audio.AudioListener.send('position_changed', position=0)
|
||||||
AudioListener.send('stream_changed', uri=self._uri)
|
audio.AudioListener.send('stream_changed', uri=self._uri)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
@ -12,7 +12,7 @@ from mopidy import backend
|
|||||||
from mopidy.models import Playlist, Ref, SearchResult
|
from mopidy.models import Playlist, Ref, SearchResult
|
||||||
|
|
||||||
|
|
||||||
def create_dummy_backend_proxy(config=None, audio=None):
|
def create_proxy(config=None, audio=None):
|
||||||
return DummyBackend.start(config=config, audio=audio).proxy()
|
return DummyBackend.start(config=config, audio=audio).proxy()
|
||||||
|
|
||||||
|
|
||||||
29
tests/dummy_mixer.py
Normal file
29
tests/dummy_mixer.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import pykka
|
||||||
|
|
||||||
|
from mopidy import mixer
|
||||||
|
|
||||||
|
|
||||||
|
def create_proxy(config=None):
|
||||||
|
return DummyMixer.start(config=None).proxy()
|
||||||
|
|
||||||
|
|
||||||
|
class DummyMixer(pykka.ThreadingActor, mixer.Mixer):
|
||||||
|
|
||||||
|
def __init__(self, config):
|
||||||
|
super(DummyMixer, self).__init__()
|
||||||
|
self._volume = None
|
||||||
|
self._mute = None
|
||||||
|
|
||||||
|
def get_volume(self):
|
||||||
|
return self._volume
|
||||||
|
|
||||||
|
def set_volume(self, volume):
|
||||||
|
self._volume = volume
|
||||||
|
|
||||||
|
def get_mute(self):
|
||||||
|
return self._mute
|
||||||
|
|
||||||
|
def set_mute(self, mute):
|
||||||
|
self._mute = mute
|
||||||
@ -6,10 +6,10 @@ import mock
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import audio, backend, core
|
from mopidy import backend, core
|
||||||
from mopidy.local import actor
|
from mopidy.local import actor
|
||||||
|
|
||||||
from tests import path_to_data_dir
|
from tests import dummy_audio, path_to_data_dir
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(backend.BackendListener, 'send')
|
@mock.patch.object(backend.BackendListener, 'send')
|
||||||
@ -24,7 +24,7 @@ class LocalBackendEventsTest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.audio = audio.DummyAudio.start().proxy()
|
self.audio = dummy_audio.create_proxy()
|
||||||
self.backend = actor.LocalBackend.start(
|
self.backend = actor.LocalBackend.start(
|
||||||
config=self.config, audio=self.audio).proxy()
|
config=self.config, audio=self.audio).proxy()
|
||||||
self.core = core.Core.start(backends=[self.backend]).proxy()
|
self.core = core.Core.start(backends=[self.backend]).proxy()
|
||||||
|
|||||||
@ -7,12 +7,12 @@ import mock
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import audio, core
|
from mopidy import core
|
||||||
from mopidy.core import PlaybackState
|
from mopidy.core import PlaybackState
|
||||||
from mopidy.local import actor
|
from mopidy.local import actor
|
||||||
from mopidy.models import Track
|
from mopidy.models import Track
|
||||||
|
|
||||||
from tests import path_to_data_dir
|
from tests import dummy_audio, path_to_data_dir
|
||||||
from tests.local import generate_song, populate_tracklist
|
from tests.local import generate_song, populate_tracklist
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ class LocalPlaybackProviderTest(unittest.TestCase):
|
|||||||
self.tracklist.add([track])
|
self.tracklist.add([track])
|
||||||
|
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.audio = audio.DummyAudio.start().proxy()
|
self.audio = dummy_audio.create_proxy()
|
||||||
self.backend = actor.LocalBackend.start(
|
self.backend = actor.LocalBackend.start(
|
||||||
config=self.config, audio=self.audio).proxy()
|
config=self.config, audio=self.audio).proxy()
|
||||||
self.core = core.Core(backends=[self.backend])
|
self.core = core.Core(backends=[self.backend])
|
||||||
|
|||||||
@ -7,11 +7,11 @@ import unittest
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import audio, core
|
from mopidy import core
|
||||||
from mopidy.local import actor
|
from mopidy.local import actor
|
||||||
from mopidy.models import Playlist, Track
|
from mopidy.models import Playlist, Track
|
||||||
|
|
||||||
from tests import path_to_data_dir
|
from tests import dummy_audio, path_to_data_dir
|
||||||
from tests.local import generate_song
|
from tests.local import generate_song
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class LocalPlaylistsProviderTest(unittest.TestCase):
|
|||||||
self.config['local']['playlists_dir'] = tempfile.mkdtemp()
|
self.config['local']['playlists_dir'] = tempfile.mkdtemp()
|
||||||
self.playlists_dir = self.config['local']['playlists_dir']
|
self.playlists_dir = self.config['local']['playlists_dir']
|
||||||
|
|
||||||
self.audio = audio.DummyAudio.start().proxy()
|
self.audio = dummy_audio.create_proxy()
|
||||||
self.backend = actor.LocalBackend.start(
|
self.backend = actor.LocalBackend.start(
|
||||||
config=self.config, audio=self.audio).proxy()
|
config=self.config, audio=self.audio).proxy()
|
||||||
self.core = core.Core(backends=[self.backend])
|
self.core = core.Core(backends=[self.backend])
|
||||||
|
|||||||
@ -5,12 +5,12 @@ import unittest
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import audio, core
|
from mopidy import core
|
||||||
from mopidy.core import PlaybackState
|
from mopidy.core import PlaybackState
|
||||||
from mopidy.local import actor
|
from mopidy.local import actor
|
||||||
from mopidy.models import Playlist, TlTrack, Track
|
from mopidy.models import Playlist, TlTrack, Track
|
||||||
|
|
||||||
from tests import path_to_data_dir
|
from tests import dummy_audio, path_to_data_dir
|
||||||
from tests.local import generate_song, populate_tracklist
|
from tests.local import generate_song, populate_tracklist
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class LocalTracklistProviderTest(unittest.TestCase):
|
|||||||
Track(uri=generate_song(i), length=4464) for i in range(1, 4)]
|
Track(uri=generate_song(i), length=4464) for i in range(1, 4)]
|
||||||
|
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.audio = audio.DummyAudio.start().proxy()
|
self.audio = dummy_audio.create_proxy()
|
||||||
self.backend = actor.LocalBackend.start(
|
self.backend = actor.LocalBackend.start(
|
||||||
config=self.config, audio=self.audio).proxy()
|
config=self.config, audio=self.audio).proxy()
|
||||||
self.core = core.Core(mixer=None, backends=[self.backend])
|
self.core = core.Core(mixer=None, backends=[self.backend])
|
||||||
|
|||||||
@ -6,10 +6,11 @@ import mock
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import core, mixer
|
from mopidy import core
|
||||||
from mopidy.backend import dummy
|
|
||||||
from mopidy.mpd import session, uri_mapper
|
from mopidy.mpd import session, uri_mapper
|
||||||
|
|
||||||
|
from tests import dummy_backend, dummy_mixer
|
||||||
|
|
||||||
|
|
||||||
class MockConnection(mock.Mock):
|
class MockConnection(mock.Mock):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -32,8 +33,8 @@ class BaseTestCase(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.mixer = mixer.DummyMixer.start().proxy()
|
self.mixer = dummy_mixer.create_proxy()
|
||||||
self.backend = dummy.create_dummy_backend_proxy()
|
self.backend = dummy_backend.create_proxy()
|
||||||
self.core = core.Core.start(
|
self.core = core.Core.start(
|
||||||
mixer=self.mixer, backends=[self.backend]).proxy()
|
mixer=self.mixer, backends=[self.backend]).proxy()
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,11 @@ import unittest
|
|||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import core
|
from mopidy import core
|
||||||
from mopidy.backend import dummy
|
|
||||||
from mopidy.mpd.dispatcher import MpdDispatcher
|
from mopidy.mpd.dispatcher import MpdDispatcher
|
||||||
from mopidy.mpd.exceptions import MpdAckError
|
from mopidy.mpd.exceptions import MpdAckError
|
||||||
|
|
||||||
|
from tests import dummy_backend
|
||||||
|
|
||||||
|
|
||||||
class MpdDispatcherTest(unittest.TestCase):
|
class MpdDispatcherTest(unittest.TestCase):
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
@ -17,7 +18,7 @@ class MpdDispatcherTest(unittest.TestCase):
|
|||||||
'password': None,
|
'password': None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.backend = dummy.create_dummy_backend_proxy()
|
self.backend = dummy_backend.create_proxy()
|
||||||
self.core = core.Core.start(backends=[self.backend]).proxy()
|
self.core = core.Core.start(backends=[self.backend]).proxy()
|
||||||
self.dispatcher = MpdDispatcher(config=config)
|
self.dispatcher = MpdDispatcher(config=config)
|
||||||
|
|
||||||
|
|||||||
@ -4,13 +4,15 @@ import unittest
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import core, mixer
|
from mopidy import core
|
||||||
from mopidy.backend import dummy
|
|
||||||
from mopidy.core import PlaybackState
|
from mopidy.core import PlaybackState
|
||||||
from mopidy.models import Track
|
from mopidy.models import Track
|
||||||
from mopidy.mpd import dispatcher
|
from mopidy.mpd import dispatcher
|
||||||
from mopidy.mpd.protocol import status
|
from mopidy.mpd.protocol import status
|
||||||
|
|
||||||
|
from tests import dummy_backend, dummy_mixer
|
||||||
|
|
||||||
|
|
||||||
PAUSED = PlaybackState.PAUSED
|
PAUSED = PlaybackState.PAUSED
|
||||||
PLAYING = PlaybackState.PLAYING
|
PLAYING = PlaybackState.PLAYING
|
||||||
STOPPED = PlaybackState.STOPPED
|
STOPPED = PlaybackState.STOPPED
|
||||||
@ -21,8 +23,8 @@ STOPPED = PlaybackState.STOPPED
|
|||||||
|
|
||||||
class StatusHandlerTest(unittest.TestCase):
|
class StatusHandlerTest(unittest.TestCase):
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.mixer = mixer.DummyMixer.start().proxy()
|
self.mixer = dummy_mixer.create_proxy()
|
||||||
self.backend = dummy.create_dummy_backend_proxy()
|
self.backend = dummy_backend.create_proxy()
|
||||||
self.core = core.Core.start(
|
self.core = core.Core.start(
|
||||||
mixer=self.mixer, backends=[self.backend]).proxy()
|
mixer=self.mixer, backends=[self.backend]).proxy()
|
||||||
self.dispatcher = dispatcher.MpdDispatcher(core=self.core)
|
self.dispatcher = dispatcher.MpdDispatcher(core=self.core)
|
||||||
|
|||||||
@ -8,9 +8,10 @@ import mock
|
|||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy import core, models
|
from mopidy import core, models
|
||||||
from mopidy.backend import dummy
|
|
||||||
from mopidy.utils import jsonrpc
|
from mopidy.utils import jsonrpc
|
||||||
|
|
||||||
|
from tests import dummy_backend
|
||||||
|
|
||||||
|
|
||||||
class Calculator(object):
|
class Calculator(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -50,7 +51,7 @@ class Calculator(object):
|
|||||||
|
|
||||||
class JsonRpcTestBase(unittest.TestCase):
|
class JsonRpcTestBase(unittest.TestCase):
|
||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.backend = dummy.create_dummy_backend_proxy()
|
self.backend = dummy_backend.create_proxy()
|
||||||
self.core = core.Core.start(backends=[self.backend]).proxy()
|
self.core = core.Core.start(backends=[self.backend]).proxy()
|
||||||
self.calc = Calculator()
|
self.calc = Calculator()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user