Пример #1
0
    def setUp(self):  # noqa: N802
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        self.tracks = [
            Track(uri='dummy1:a', name='foo'),
            Track(uri='dummy1:b', name='foo'),
            Track(uri='dummy1:c', name='bar'),
        ]

        self.tl_tracks = [
            TlTrack(tlid=4, track=Track(uri='first', name='First')),
            TlTrack(tlid=5, track=Track(uri='second', name='Second')),
            TlTrack(tlid=6, track=Track(uri='third', name='Third')),
            TlTrack(tlid=8, track=Track(uri='last', name='Last'))
        ]

        def lookup(uris):
            return {u: [t for t in self.tracks if t.uri == u] for u in uris}

        self.core = core.Core(config, mixer=None, backends=[])
        self.core.library = mock.Mock(spec=core.LibraryController)
        self.core.library.lookup.side_effect = lookup

        self.core.playback = mock.Mock(spec=core.PlaybackController)
Пример #2
0
    def setUp(self):  # noqa: N802
        dummy1_root = Ref.directory(uri='dummy1:directory', name='dummy1')
        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ['dummy1']
        self.library1 = mock.Mock(spec=backend.LibraryProvider)
        self.library1.get_images().get.return_value = {}
        self.library1.get_images.reset_mock()
        self.library1.root_directory.get.return_value = dummy1_root
        self.backend1.library = self.library1

        dummy2_root = Ref.directory(uri='dummy2:directory', name='dummy2')
        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ['dummy2', 'du2']
        self.library2 = mock.Mock(spec=backend.LibraryProvider)
        self.library2.get_images().get.return_value = {}
        self.library2.get_images.reset_mock()
        self.library2.root_directory.get.return_value = dummy2_root
        self.backend2.library = self.library2

        # A backend without the optional library provider
        self.backend3 = mock.Mock()
        self.backend3.uri_schemes.get.return_value = ['dummy3']
        self.backend3.has_library().get.return_value = False
        self.backend3.has_library_browse().get.return_value = False

        self.core = core.Core(
            mixer=None, backends=[self.backend1, self.backend2, self.backend3])
Пример #3
0
    def setUp(self):  # noqa: N802
        # TODO: use create_proxy helpers.
        self.audio = dummy_audio.DummyAudio.start().proxy()
        self.backend = TestBackend.start(audio=self.audio,
                                         config=self.config).proxy()
        self.core = core.Core(audio=self.audio,
                              backends=[self.backend],
                              config=self.config)
        self.playback = self.core.playback

        # We don't have a core actor running, so call about to finish directly.
        self.audio.set_about_to_finish_callback(
            self.playback._on_about_to_finish)

        with deprecation.ignore('core.tracklist.add:tracks_arg'):
            self.core.tracklist.add(self.tracks)

        self.events = []
        self.patcher = mock.patch('mopidy.audio.listener.AudioListener.send')
        self.send_mock = self.patcher.start()

        def send(event, **kwargs):
            self.events.append((event, kwargs))

        self.send_mock.side_effect = send
Пример #4
0
    def setUp(self):  # noqa: N802
        dummy1_root = Ref.directory(uri="dummy1:directory", name="dummy1")
        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ["dummy1"]
        self.backend1.actor_ref.actor_class.__name__ = "DummyBackend1"
        self.library1 = mock.Mock(spec=backend.LibraryProvider)
        self.library1.get_images.return_value.get.return_value = {}
        self.library1.root_directory.get.return_value = dummy1_root
        self.backend1.library = self.library1
        self.backend1.has_playlists.return_value.get.return_value = False

        dummy2_root = Ref.directory(uri="dummy2:directory", name="dummy2")
        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ["dummy2", "du2"]
        self.backend2.actor_ref.actor_class.__name__ = "DummyBackend2"
        self.library2 = mock.Mock(spec=backend.LibraryProvider)
        self.library2.get_images.return_value.get.return_value = {}
        self.library2.root_directory.get.return_value = dummy2_root
        self.backend2.library = self.library2
        self.backend2.has_playlists.return_value.get.return_value = False

        # A backend without the optional library provider
        self.backend3 = mock.Mock()
        self.backend3.uri_schemes.get.return_value = ["dummy3"]
        self.backend3.actor_ref.actor_class.__name__ = "DummyBackend3"
        self.backend3.has_library.return_value.get.return_value = False
        self.backend3.has_library_browse.return_value.get.return_value = False

        self.core = core.Core(
            mixer=None, backends=[self.backend1, self.backend2, self.backend3])
Пример #5
0
    def setup_method(self, method):
        self.audio = dummy_audio.create_proxy(config=self.config, mixer=None)
        self.backend = MyTestBackend.start(
            audio=self.audio, config=self.config
        ).proxy()
        self.core = core.Core(
            audio=self.audio, backends=[self.backend], config=self.config
        )
        self.playback = self.core.playback

        # We don't have a core actor running, so call about to finish directly.
        self.audio.set_about_to_finish_callback(
            self.playback._on_about_to_finish
        )

        with deprecation.ignore():
            self.core.tracklist.add(self.tracks)

        self.events = []
        self.patcher = mock.patch("mopidy.audio.listener.AudioListener.send")
        self.send_mock = self.patcher.start()

        def send(event, **kwargs):
            self.events.append((event, kwargs))

        self.send_mock.side_effect = send
Пример #6
0
    def setUp(self):  # noqa: N802
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ['dummy1']
        self.playback1 = mock.Mock(spec=backend.PlaybackProvider)
        self.backend1.playback = self.playback1

        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ['dummy2']
        self.playback2 = mock.Mock(spec=backend.PlaybackProvider)
        self.backend2.playback = self.playback2

        self.tracks = [
            Track(uri='dummy1:a', length=40000),
            Track(uri='dummy2:a', length=40000),
        ]

        self.core = core.Core(config,
                              mixer=None,
                              backends=[self.backend1, self.backend2])

        self.tl_tracks = self.core.tracklist.add(self.tracks)
Пример #7
0
    def setUp(self):  # noqa: N802
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        self.audio = audio.DummyAudio.start().proxy()
        self.backend = TestBackend.start(config={}, audio=self.audio).proxy()
        self.core = core.Core(config,
                              audio=self.audio,
                              backends=[self.backend])
        self.playback = self.core.playback

        self.tracks = [
            Track(uri='dummy:a', length=1234),
            Track(uri='dummy:b', length=1234)
        ]

        self.lookup_patcher = mock.patch.object(self.core.library, 'lookup')
        self.lookup_mock = self.lookup_patcher.start()
        self.lookup_mock.return_value = {t.uri: [t] for t in self.tracks}

        self.core.tracklist.add(uris=[t.uri for t in self.tracks])

        self.events = []
        self.send_patcher = mock.patch(
            'mopidy.audio.listener.AudioListener.send')
        self.send_mock = self.send_patcher.start()

        def send(event, **kwargs):
            self.events.append((event, kwargs))

        self.send_mock.side_effect = send
Пример #8
0
    def setUp(self):
        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ['dummy1']
        self.sp1 = mock.Mock(spec=backend.PlaylistsProvider)
        self.backend1.playlists = self.sp1

        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ['dummy2']
        self.sp2 = mock.Mock(spec=backend.PlaylistsProvider)
        self.backend2.playlists = self.sp2

        # A backend without the optional playlists provider
        self.backend3 = mock.Mock()
        self.backend3.uri_schemes.get.return_value = ['dummy3']
        self.backend3.has_playlists().get.return_value = False
        self.backend3.playlists = None

        self.pl1a = Playlist(name='A', tracks=[Track(uri='dummy1:a')])
        self.pl1b = Playlist(name='B', tracks=[Track(uri='dummy1:b')])
        self.sp1.playlists.get.return_value = [self.pl1a, self.pl1b]

        self.pl2a = Playlist(name='A', tracks=[Track(uri='dummy2:a')])
        self.pl2b = Playlist(name='B', tracks=[Track(uri='dummy2:b')])
        self.sp2.playlists.get.return_value = [self.pl2a, self.pl2b]

        self.core = core.Core(
            mixer=None, backends=[self.backend3, self.backend1, self.backend2])
Пример #9
0
    def test(self):
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        b = mock.Mock()
        b.uri_schemes.get.return_value = ['dummy']
        b.playback = mock.Mock(spec=backend.PlaybackProvider)
        b.playback.change_track.return_value.get.return_value = True
        b.playback.play.return_value.get.return_value = True

        track1 = Track(uri='dummy:a', length=40000)
        track2 = Track(uri='dummy:b', length=40000)

        c = core.Core(config, mixer=None, backends=[b])
        c.tracklist.add([track1, track2])

        c.playback.play()
        b.playback.change_track.assert_called_once_with(track1)
        b.playback.change_track.reset_mock()

        c.playback.pause()
        c.playback.next()
        b.playback.change_track.assert_called_once_with(track2)
Пример #10
0
    def setUp(self):
        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ['dummy1']
        self.playback1 = mock.Mock(spec=backend.PlaybackProvider)
        self.playback1.get_time_position().get.return_value = 1000
        self.playback1.reset_mock()
        self.backend1.playback = self.playback1

        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ['dummy2']
        self.playback2 = mock.Mock(spec=backend.PlaybackProvider)
        self.playback2.get_time_position().get.return_value = 2000
        self.playback2.reset_mock()
        self.backend2.playback = self.playback2

        # A backend without the optional playback provider
        self.backend3 = mock.Mock()
        self.backend3.uri_schemes.get.return_value = ['dummy3']
        self.backend3.has_playback().get.return_value = False

        self.tracks = [
            Track(uri='dummy1:a', length=40000),
            Track(uri='dummy2:a', length=40000),
            Track(uri='dummy3:a', length=40000),  # Unplayable
            Track(uri='dummy1:b', length=40000),
        ]

        self.core = core.Core(
            audio=None, backends=[self.backend1, self.backend2, self.backend3])
        self.core.tracklist.add(self.tracks)

        self.tl_tracks = self.core.tracklist.tl_tracks
        self.unplayable_tl_track = self.tl_tracks[2]
Пример #11
0
    def setUp(self):  # noqa: N802
        self.config['m3u']['playlists_dir'] = tempfile.mkdtemp()
        self.playlists_dir = self.config['m3u']['playlists_dir']

        audio = dummy_audio.create_proxy()
        backend = M3UBackend.start(config=self.config, audio=audio).proxy()
        self.core = core.Core(backends=[backend])
Пример #12
0
    def setUp(self):  # noqa:
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        self.tracks = [
            Track(uri='dummy1:a', name='foo'),
            Track(uri='dummy1:b', name='foo'),
            Track(uri='dummy1:c', name='bar'),
        ]

        def lookup(uri):
            future = mock.Mock()
            future.get.return_value = [t for t in self.tracks if t.uri == uri]
            return future

        self.backend = mock.Mock()
        self.backend.uri_schemes.get.return_value = ['dummy1']
        self.library = mock.Mock(spec=backend.LibraryProvider)
        self.library.lookup.side_effect = lookup
        self.backend.library = self.library

        self.core = core.Core(config, mixer=None, backends=[self.backend])
        self.tl_tracks = self.core.tracklist.add(
            uris=[t.uri for t in self.tracks])
Пример #13
0
    def setUp(self):
        self.audio = mock.Mock(spec=audio.Audio)
        self.backend = self.backend_class.start(audio=self.audio).proxy()
        self.core = core.Core(audio=audio, backends=[self.backend])
        self.controller = self.core.tracklist
        self.playback = self.core.playback

        assert len(self.tracks) == 3, 'Need three tracks to run tests.'
Пример #14
0
    def setUp(self):
        settings.LOCAL_PLAYLIST_PATH = tempfile.mkdtemp()
        settings.LOCAL_TAG_CACHE_FILE = path_to_data_dir('library_tag_cache')
        settings.LOCAL_MUSIC_PATH = path_to_data_dir('')

        self.audio = audio.DummyAudio.start().proxy()
        self.backend = self.backend_class.start(audio=self.audio).proxy()
        self.core = core.Core(backends=[self.backend])
Пример #15
0
    def setUp(self):
        self.config['local']['playlists_dir'] = tempfile.mkdtemp()
        self.playlists_dir = self.config['local']['playlists_dir']

        self.audio = audio.DummyAudio.start().proxy()
        self.backend = actor.LocalBackend.start(config=self.config,
                                                audio=self.audio).proxy()
        self.core = core.Core(backends=[self.backend])
Пример #16
0
    def setUp(self):  # noqa: N802
        self.config["m3u"]["playlists_dir"] = pathlib.Path(tempfile.mkdtemp())
        self.playlists_dir = self.config["m3u"]["playlists_dir"]
        self.base_dir = self.config["m3u"]["base_dir"] or self.playlists_dir

        audio = dummy_audio.create_proxy()
        backend = M3UBackend.start(config=self.config, audio=audio).proxy()
        self.core = core.Core(backends=[backend])
Пример #17
0
    def setUp(self):  # noqa: N802
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ['dummy1']
        self.playback1 = mock.Mock(spec=backend.PlaybackProvider)
        self.playback1.get_time_position.return_value.get.return_value = 1000
        self.backend1.playback = self.playback1

        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ['dummy2']
        self.playback2 = mock.Mock(spec=backend.PlaybackProvider)
        self.playback2.get_time_position.return_value.get.return_value = 2000
        self.backend2.playback = self.playback2

        # A backend without the optional playback provider
        self.backend3 = mock.Mock()
        self.backend3.uri_schemes.get.return_value = ['dummy3']
        self.backend3.has_playback().get.return_value = False

        self.tracks = [
            Track(uri='dummy1:a', length=40000),
            Track(uri='dummy2:a', length=40000),
            Track(uri='dummy3:a', length=40000),  # Unplayable
            Track(uri='dummy1:b', length=40000),
            Track(uri='dummy1:c', length=None),  # No duration
        ]

        self.uris = [
            'dummy1:a', 'dummy2:a', 'dummy3:a', 'dummy1:b', 'dummy1:c'
        ]

        self.core = core.Core(
            config,
            mixer=None,
            backends=[self.backend1, self.backend2, self.backend3])

        def lookup(uris):
            result = {uri: [] for uri in uris}
            for track in self.tracks:
                if track.uri in result:
                    result[track.uri].append(track)
            return result

        self.lookup_patcher = mock.patch.object(self.core.library, 'lookup')
        self.lookup_mock = self.lookup_patcher.start()
        self.lookup_mock.side_effect = lookup

        self.core.tracklist.add(uris=self.uris)

        self.tl_tracks = self.core.tracklist.tl_tracks
        self.unplayable_tl_track = self.tl_tracks[2]
        self.duration_less_tl_track = self.tl_tracks[4]
Пример #18
0
    def setUp(self):  # noqa: N802
        self.audio = dummy_audio.create_proxy()
        self.backend = actor.LocalBackend.start(config=self.config,
                                                audio=self.audio).proxy()
        self.core = core.Core(self.config, mixer=None, backends=[self.backend])
        self.controller = self.core.tracklist
        self.playback = self.core.playback

        assert len(self.tracks) == 3, 'Need three tracks to run tests.'
Пример #19
0
    def setUp(self):  # noqa: N802
        self.playlists = mock.Mock(spec=backend.PlaylistsProvider)

        self.backend = mock.Mock()
        self.backend.actor_ref.actor_class.__name__ = "DummyBackend"
        self.backend.uri_schemes.get.return_value = ["dummy"]
        self.backend.playlists = self.playlists

        self.core = core.Core(mixer=None, backends=[self.backend])
Пример #20
0
    def setUp(self):
        self.audio = audio.DummyAudio.start().proxy()
        self.backend = actor.LocalBackend.start(
            config=self.config, audio=self.audio).proxy()
        self.core = core.Core(audio=self.audio, backends=[self.backend])
        self.controller = self.core.tracklist
        self.playback = self.core.playback

        assert len(self.tracks) == 3, 'Need three tracks to run tests.'
Пример #21
0
    def test_type_error_from_old_backend_does_not_crash_core(self):
        b = mock.Mock()
        b.uri_schemes.get.return_value = ['dummy1']
        b.playback = mock.Mock(spec=backend.PlaybackProvider)
        b.playback.play.side_effect = TypeError

        c = core.Core(mixer=None, backends=[b])
        c.tracklist.add([Track(uri='dummy1:a', length=40000)])
        c.playback.play()  # No TypeError == test passed.
Пример #22
0
    def setUp(self):
        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
        self.tracklist = self.core.tracklist

        assert len(self.tracks) >= 3, \
            'Need at least three tracks to run tests.'
        assert self.tracks[0].length >= 2000, \
            'First song needs to be at least 2000 miliseconds'
Пример #23
0
    def setUp(self):  # noqa: N802
        dummy_root = Ref.directory(uri="dummy:directory", name="dummy")

        self.library = mock.Mock(spec=backend.LibraryProvider)
        self.library.root_directory.get.return_value = dummy_root

        self.backend = mock.Mock()
        self.backend.actor_ref.actor_class.__name__ = "DummyBackend"
        self.backend.uri_schemes.get.return_value = ["dummy"]
        self.backend.library = self.library

        self.core = core.Core(mixer=None, backends=[self.backend])
Пример #24
0
    def setUp(self):  # noqa: N802
        self.audio = dummy_audio.create_proxy()
        self.backend = actor.LocalBackend.start(config=self.config,
                                                audio=self.audio).proxy()
        self.core = core.Core(self.config, backends=[self.backend])
        self.playback = self.core.playback
        self.tracklist = self.core.tracklist

        assert len(self.tracks) >= 3, \
            'Need at least three tracks to run tests.'
        assert self.tracks[0].length >= 2000, \
            'First song needs to be at least 2000 miliseconds'
Пример #25
0
    def setUp(self):  # noqa: N802
        self.tracks = [
            Track(uri='dummy1:a', name='foo'),
            Track(uri='dummy1:b', name='foo'),
            Track(uri='dummy1:c', name='bar'),
        ]

        self.backend = mock.Mock()
        self.backend.uri_schemes.get.return_value = ['dummy1']
        self.library = mock.Mock(spec=backend.LibraryProvider)
        self.backend.library = self.library

        self.core = core.Core(mixer=None, backends=[self.backend])
        self.tl_tracks = self.core.tracklist.add(self.tracks)
Пример #26
0
    def test_type_error_from_old_backend_does_not_crash_core(self):
        config = {"core": {"max_tracklist_length": 10000}}

        b = mock.Mock()
        b.actor_ref.actor_class.__name__ = "DummyBackend"
        b.uri_schemes.get.return_value = ["dummy1"]
        b.playback = mock.Mock(spec=backend.PlaybackProvider)
        b.playback.play.side_effect = TypeError
        b.library.lookup.return_value.get.return_value = [
            Track(uri="dummy1:a", length=40000)
        ]

        c = core.Core(config, mixer=None, backends=[b])
        c.tracklist.add(uris=["dummy1:a"])
        c.playback.play()  # No TypeError == test passed.
        b.playback.play.assert_called_once_with()
Пример #27
0
    def setUp(self):  # noqa: N802
        config = {
            'core': {
                'max_tracklist_length': 10000,
            }
        }

        self.backend = mock.Mock()
        self.backend.uri_schemes.get.return_value = ['dummy']
        self.core = core.Core(config, backends=[self.backend])

        self.tracks = [
            Track(uri='dummy:a', length=1234),
            Track(uri='dummy:b', length=1234)
        ]

        with deprecation.ignore('core.tracklist.add:tracks_arg'):
            self.tl_tracks = self.core.tracklist.add(tracks=self.tracks)
Пример #28
0
    def setUp(self):  # noqa: N802
        self.audio = audio.DummyAudio.start().proxy()
        self.backend = TestBackend.start(config={}, audio=self.audio).proxy()
        self.core = core.Core(audio=self.audio, backends=[self.backend])
        self.playback = self.core.playback

        self.tracks = [Track(uri='dummy:a', length=1234),
                       Track(uri='dummy:b', length=1234)]

        self.core.tracklist.add(self.tracks)

        self.events = []
        self.patcher = mock.patch('mopidy.audio.listener.AudioListener.send')
        self.send_mock = self.patcher.start()

        def send(event, **kwargs):
            self.events.append((event, kwargs))

        self.send_mock.side_effect = send
Пример #29
0
    def setUp(self):  # noqa: N802
        self.plr1a = Ref.playlist(name="A", uri="dummy1:pl:a")
        self.plr1b = Ref.playlist(name="B", uri="dummy1:pl:b")
        self.plr2a = Ref.playlist(name="A", uri="dummy2:pl:a")
        self.plr2b = Ref.playlist(name="B", uri="dummy2:pl:b")

        self.pl1a = Playlist(name="A", tracks=[Track(uri="dummy1:t:a")])
        self.pl1b = Playlist(name="B", tracks=[Track(uri="dummy1:t:b")])
        self.pl2a = Playlist(name="A", tracks=[Track(uri="dummy2:t:a")])
        self.pl2b = Playlist(name="B", tracks=[Track(uri="dummy2:t:b")])

        self.sp1 = mock.Mock(spec=backend.PlaylistsProvider)
        self.sp1.as_list.return_value.get.return_value = [
            self.plr1a,
            self.plr1b,
        ]
        self.sp1.lookup.return_value.get.side_effect = [self.pl1a, self.pl1b]

        self.sp2 = mock.Mock(spec=backend.PlaylistsProvider)
        self.sp2.as_list.return_value.get.return_value = [
            self.plr2a,
            self.plr2b,
        ]
        self.sp2.lookup.return_value.get.side_effect = [self.pl2a, self.pl2b]

        self.backend1 = mock.Mock()
        self.backend1.actor_ref.actor_class.__name__ = "Backend1"
        self.backend1.uri_schemes.get.return_value = ["dummy1"]
        self.backend1.playlists = self.sp1

        self.backend2 = mock.Mock()
        self.backend2.actor_ref.actor_class.__name__ = "Backend2"
        self.backend2.uri_schemes.get.return_value = ["dummy2"]
        self.backend2.playlists = self.sp2

        # A backend without the optional playlists provider
        self.backend3 = mock.Mock()
        self.backend3.uri_schemes.get.return_value = ["dummy3"]
        self.backend3.has_playlists().get.return_value = False
        self.backend3.playlists = None

        self.core = core.Core(
            mixer=None, backends=[self.backend3, self.backend1, self.backend2])
Пример #30
0
    def setUp(self):  # noqa: N802
        config = {"core": {"max_tracklist_length": 10000}}

        self.tracks = [
            Track(uri="dummy1:a", name="foo"),
            Track(uri="dummy1:b", name="foo"),
            Track(uri="dummy1:c", name="bar"),
        ]

        def lookup(uris):
            return {u: [t for t in self.tracks if t.uri == u] for u in uris}

        self.core = core.Core(config, mixer=None, backends=[])
        self.core.library = mock.Mock(spec=core.LibraryController)
        self.core.library.lookup.side_effect = lookup

        self.core.playback = mock.Mock(spec=core.PlaybackController)

        self.tl_tracks = self.core.tracklist.add(
            uris=[t.uri for t in self.tracks])