コード例 #1
0
 def test_eq(self):
     tlid = 123
     track = Track()
     tl_track1 = TlTrack(tlid=tlid, track=track)
     tl_track2 = TlTrack(tlid=tlid, track=track)
     assert tl_track1 == tl_track2
     assert hash(tl_track1) == hash(tl_track2)
コード例 #2
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_eq(self):
     tlid = 123
     track = Track()
     tl_track1 = TlTrack(tlid=tlid, track=track)
     tl_track2 = TlTrack(tlid=tlid, track=track)
     self.assertEqual(tl_track1, tl_track2)
     self.assertEqual(hash(tl_track1), hash(tl_track2))
コード例 #3
0
ファイル: test_tracklist.py プロジェクト: zvonimirfras/mopidy
    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)
コード例 #4
0
ファイル: test_listener.py プロジェクト: tylerball/mopidy
    def test_on_event_forwards_to_specific_handler(self):
        self.listener.track_playback_paused = mock.Mock()

        self.listener.on_event(
            'track_playback_paused', track=TlTrack(), position=0)

        self.listener.track_playback_paused.assert_called_with(
            track=TlTrack(), position=0)
コード例 #5
0
def test_track_playback_resumed_event_changes_playback_status(frontend):
    frontend.mpris.player.PlaybackStatus = "Playing"

    frontend.track_playback_resumed(tl_track=TlTrack(), time_position=0)

    frontend.mpris.player.PropertiesChanged.assert_called_with(
        player.Player.INTERFACE, {"PlaybackStatus": "Playing"}, [])
コード例 #6
0
    def add(self, tracks, at_position=None):
        """
        Add the track or list of tracks to the tracklist.

        If ``at_position`` is given, the tracks placed at the given position in
        the tracklist. If ``at_position`` is not given, the tracks are appended
        to the end of the tracklist.

        Triggers the :meth:`mopidy.core.CoreListener.tracklist_changed` event.

        :param tracks: tracks to add
        :type tracks: list of :class:`mopidy.models.Track`
        :param at_position: position in tracklist to add track
        :type at_position: int or :class:`None`
        :rtype: list of :class:`mopidy.models.TlTrack`
        """
        tl_tracks = []
        for track in tracks:
            tl_track = TlTrack(self._next_tlid, track)
            self._next_tlid += 1
            if at_position is not None:
                self._tl_tracks.insert(at_position, tl_track)
                at_position += 1
            else:
                self._tl_tracks.append(tl_track)
            tl_tracks.append(tl_track)

        if tl_tracks:
            self._increase_version()

        return tl_tracks
コード例 #7
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_iteration(self):
     tlid = 123
     track = Track()
     tl_track = TlTrack(tlid, track)
     (tlid2, track2) = tl_track
     self.assertEqual(tlid2, tlid)
     self.assertEqual(track2, track)
コード例 #8
0
 def test_iteration(self):
     tlid = 123
     track = Track()
     tl_track = TlTrack(tlid, track)
     (tlid2, track2) = tl_track
     assert tlid2 == tlid
     assert track2 == track
コード例 #9
0
 def test_track_to_mpd_format_for_nonempty_track(self):
     result = translator.track_to_mpd_format(TlTrack(122, self.track),
                                             tagtype_list.TAGTYPE_LIST,
                                             position=9)
     assert ("file", "à uri") in result
     assert ("Time", 137) in result
     assert ("Artist", "an artist") in result
     assert ("Artist", "yet another artist") in result
     assert ("Title", "a nàme") in result
     assert ("Album", "an album") in result
     assert ("AlbumArtist", "an other artist") in result
     assert ("AlbumArtist", "still another artist") in result
     assert ("Composer", "a composer") in result
     assert ("Composer", "another composer") in result
     assert ("Performer", "a performer") in result
     assert ("Performer", "another performer") in result
     assert ("Genre", "a genre") in result
     assert ("Track", "7/13") in result
     assert ("Date", "1977-01-01") in result
     assert ("Disc", 1) in result
     assert ("Pos", 9) in result
     assert ("Id", 122) in result
     assert ("X-AlbumUri", "urischeme:àlbum:12345") in result
     assert ("Comment", "a comment") not in result
     assert len(result) == 19
コード例 #10
0
 def test_track_playback_resumed_event_changes_playback_status(self):
     self.mpris_object.Get.return_value = 'Playing'
     self.mpris_frontend.track_playback_resumed(TlTrack(), 0)
     self.assertListEqual(self.mpris_object.Get.call_args_list, [
         ((objects.PLAYER_IFACE, 'PlaybackStatus'), {}),
     ])
     self.mpris_object.PropertiesChanged.assert_called_with(
         objects.PLAYER_IFACE, {'PlaybackStatus': 'Playing'}, [])
コード例 #11
0
 def test_track_to_mpd_format_with_position_and_tlid(self):
     result = translator.track_to_mpd_format(
         TlTrack(2, Track(uri="a uri")),
         tagtype_list.TAGTYPE_LIST,
         position=1,
     )
     assert ("Pos", 1) in result
     assert ("Id", 2) in result
コード例 #12
0
ファイル: tracklist.py プロジェクト: CarnosOS/Peridot
    def add(self, tracks=None, at_position=None, uri=None, uris=None):
        """
        Add the track or list of tracks to the tracklist.

        If ``uri`` is given instead of ``tracks``, the URI is looked up in the
        library and the resulting tracks are added to the tracklist.

        If ``uris`` is given instead of ``tracks``, the URIs are looked up in
        the library and the resulting tracks are added to the tracklist.

        If ``at_position`` is given, the tracks placed at the given position in
        the tracklist. If ``at_position`` is not given, the tracks are appended
        to the end of the tracklist.

        Triggers the :meth:`mopidy.core.CoreListener.tracklist_changed` event.

        :param tracks: tracks to add
        :type tracks: list of :class:`mopidy.models.Track`
        :param at_position: position in tracklist to add track
        :type at_position: int or :class:`None`
        :param uri: URI for tracks to add
        :type uri: string
        :rtype: list of :class:`mopidy.models.TlTrack`

        .. versionadded:: 1.0
            The ``uris`` argument.

        .. deprecated:: 1.0
            The ``tracks`` and ``uri`` arguments. Use ``uris``.
        """
        assert tracks is not None or uri is not None or uris is not None, \
            'tracks, uri or uris must be provided'

        if tracks is None:
            if uri is not None:
                tracks = self.core.library.lookup(uri=uri)
            elif uris is not None:
                tracks = []
                track_map = self.core.library.lookup(uris=uris)
                for uri in uris:
                    tracks.extend(track_map[uri])

        tl_tracks = []

        for track in tracks:
            tl_track = TlTrack(self._next_tlid, track)
            self._next_tlid += 1
            if at_position is not None:
                self._tl_tracks.insert(at_position, tl_track)
                at_position += 1
            else:
                self._tl_tracks.append(tl_track)
            tl_tracks.append(tl_track)

        if tl_tracks:
            self._increase_version()

        return tl_tracks
コード例 #13
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_serialize(self):
     track = Track(uri='uri', name='name')
     self.assertDictEqual(
         {
             '__model__': 'TlTrack',
             'tlid': 123,
             'track': track.serialize()
         },
         TlTrack(tlid=123, track=track).serialize())
コード例 #14
0
 def test_serialize(self):
     track = Track(uri="uri", name="name")
     self.assertDictEqual(
         {
             "__model__": "TlTrack",
             "tlid": 123,
             "track": track.serialize()
         },
         TlTrack(tlid=123, track=track).serialize(),
     )
コード例 #15
0
 def test_track_playback_ended_changes_playback_status_and_metadata(self):
     self.mpris_object.Get.return_value = '...'
     self.mpris_frontend.track_playback_ended(TlTrack(), 0)
     self.assertListEqual(self.mpris_object.Get.call_args_list, [
         ((objects.PLAYER_IFACE, 'PlaybackStatus'), {}),
         ((objects.PLAYER_IFACE, 'Metadata'), {}),
     ])
     self.mpris_object.PropertiesChanged.assert_called_with(
         objects.PLAYER_IFACE,
         {'Metadata': '...', 'PlaybackStatus': '...'}, [])
コード例 #16
0
    def test_next(self):
        core = mock.Mock()
        future_tl_track = mock.Mock()
        future_tl = mock.Mock()
        core.playback.get_current_tl_track.return_value = future_tl_track
        core.tracklist.get_length.return_value = future_tl
        future_tl.get.return_value = 3

        ctrls = PhonieboxControls(core)
        future_tl_track.get.return_value = TlTrack(2, None)
        ctrls.next()
        core.playback.next.assert_called_once()
        core.playback.play.assert_not_called()

        core.reset_mock()
        future_tl_track.get.return_value = TlTrack(3, None)
        ctrls.next()
        core.playback.next.assert_not_called()
        core.playback.play.assert_called_with(tlid=1)

        future_tl.get.return_value = 1
        core.reset_mock()
        future_tl_track.get.return_value = None
        ctrls.next()
        core.playback.next.assert_not_called()
        core.playback.play.assert_called_with(tlid=1)

        future_tl.get.return_value = 0
        core.reset_mock()
        future_tl_track.get.return_value = None
        ctrls.next()
        core.playback.next.assert_not_called()
        core.playback.play.assert_not_called()

        future_tl.get.return_value = 0
        core.reset_mock()
        future_tl_track.get.return_value = TlTrack(1, None)
        ctrls.next()
        core.playback.next.assert_not_called()
        core.playback.play.assert_not_called()
コード例 #17
0
def test_track_playback_started_changes_playback_status_and_metadata(frontend):
    frontend.mpris.player.Metadata = "..."
    frontend.mpris.player.PlaybackStatus = "Playing"

    frontend.track_playback_started(tl_track=TlTrack())

    frontend.mpris.player.PropertiesChanged.assert_called_with(
        player.Player.INTERFACE,
        {
            "Metadata": "...",
            "PlaybackStatus": "Playing"
        },
        [],
    )
コード例 #18
0
 def test_track_to_mpd_format_for_nonempty_track(self):
     result = translator.track_to_mpd_format(TlTrack(122, self.track),
                                             position=9)
     self.assertIn(('file', 'a uri'), result)
     self.assertIn(('Time', 137), result)
     self.assertIn(('Artist', 'an artist'), result)
     self.assertIn(('Title', 'a name'), result)
     self.assertIn(('Album', 'an album'), result)
     self.assertIn(('AlbumArtist', 'an other artist'), result)
     self.assertIn(('Track', '7/13'), result)
     self.assertIn(('Date', datetime.date(1977, 1, 1)), result)
     self.assertIn(('Pos', 9), result)
     self.assertIn(('Id', 122), result)
     self.assertEqual(len(result), 10)
コード例 #19
0
def test_track_playback_ended_changes_playback_status_and_metadata(frontend):
    frontend.mpris.player.Metadata = "..."
    frontend.mpris.player.PlaybackStatus = "Stopped"

    frontend.track_playback_ended(tl_track=TlTrack(), time_position=0)

    frontend.mpris.player.PropertiesChanged.assert_called_with(
        player.Player.INTERFACE,
        {
            "Metadata": "...",
            "PlaybackStatus": "Stopped"
        },
        [],
    )
コード例 #20
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)
コード例 #21
0
ファイル: test_translator.py プロジェクト: zhanghuabin/mopidy
 def test_track_to_mpd_format_for_nonempty_track(self):
     result = translator.track_to_mpd_format(TlTrack(122, self.track),
                                             position=9)
     self.assertIn(('file', 'à uri'), result)
     self.assertIn(('Time', 137), result)
     self.assertIn(('Artist', 'an artist'), result)
     self.assertIn(('Title', 'a nàme'), result)
     self.assertIn(('Album', 'an album'), result)
     self.assertIn(('AlbumArtist', 'an other artist'), result)
     self.assertIn(('Composer', 'a composer'), result)
     self.assertIn(('Performer', 'a performer'), result)
     self.assertIn(('Genre', 'a genre'), result)
     self.assertIn(('Track', '7/13'), result)
     self.assertIn(('Date', '1977-01-01'), result)
     self.assertIn(('Disc', 1), result)
     self.assertIn(('Pos', 9), result)
     self.assertIn(('Id', 122), result)
     self.assertIn(('X-AlbumUri', 'urischeme:àlbum:12345'), result)
     self.assertIn(('X-AlbumImage', 'image1'), result)
     self.assertNotIn(('Comment', 'a comment'), result)
     self.assertEqual(len(result), 16)
コード例 #22
0
 def test_track_to_mpd_client_filtered(self):
     configured_tagtypes = [
         "Artist",
         "Album",
         "Title",
         "Track",
         "Name",
         "Genre",
     ]
     result = translator.track_to_mpd_format(TlTrack(122, self.track),
                                             configured_tagtypes,
                                             position=9)
     assert ("file", "à uri") in result
     assert ("Time", 137) in result
     assert ("Artist", "an artist") in result
     assert ("Artist", "yet another artist") in result
     assert ("Title", "a nàme") in result
     assert ("Album", "an album") in result
     assert ("Genre", "a genre") in result
     assert ("Track", "7/13") in result
     assert ("Pos", 9) in result
     assert ("Id", 122) in result
     assert len(result) == 10
コード例 #23
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_to_json_and_back(self):
     tl_track1 = TlTrack(tlid=123, track=Track(uri='uri', name='name'))
     serialized = json.dumps(tl_track1, cls=ModelJSONEncoder)
     tl_track2 = json.loads(serialized, object_hook=model_json_decoder)
     self.assertEqual(tl_track1, tl_track2)
コード例 #24
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_repr(self):
     self.assertEquals(
         "TlTrack(tlid=123, track=Track(artists=[], composers=[], "
         "performers=[], uri=u'uri'))",
         repr(TlTrack(tlid=123, track=Track(uri='uri'))))
コード例 #25
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_ne_tlid(self):
     tl_track1 = TlTrack(tlid=123)
     tl_track2 = TlTrack(tlid=321)
     self.assertNotEqual(tl_track1, tl_track2)
     self.assertNotEqual(hash(tl_track1), hash(tl_track2))
コード例 #26
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_eq_none(self):
     self.assertNotEqual(TlTrack(), None)
コード例 #27
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_eq_other(self):
     self.assertNotEqual(TlTrack(), 'other')
コード例 #28
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_invalid_kwarg(self):
     test = lambda: TlTrack(foo='baz')
     self.assertRaises(TypeError, test)
コード例 #29
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_ne_track(self):
     tl_track1 = TlTrack(track=Track(uri='a'))
     tl_track2 = TlTrack(track=Track(uri='b'))
     self.assertNotEqual(tl_track1, tl_track2)
     self.assertNotEqual(hash(tl_track1), hash(tl_track2))
コード例 #30
0
ファイル: test_models.py プロジェクト: zimbatm/mopidy
 def test_positional_args(self):
     tlid = 123
     track = Track()
     tl_track = TlTrack(tlid, track)
     self.assertEqual(tl_track.tlid, tlid)
     self.assertEqual(tl_track.track, track)