Beispiel #1
0
 def test_tlid(self):
     tlid = 123
     tl_track = TlTrack(tlid=tlid)
     self.assertEqual(tl_track.tlid, tlid)
     with self.assertRaises(AttributeError):
         tl_track.tlid = None
Beispiel #2
0
 def test_track_to_mpd_format_with_tlid(self):
     result = translator.track_to_mpd_format(TlTrack(1, Track()))
     self.assertNotIn(('Id', 1), result)
Beispiel #3
0
 def test_tlid(self):
     tlid = 123
     tl_track = TlTrack(tlid=tlid)
     self.assertEqual(tl_track.tlid, tlid)
     with self.assertRaises(AttributeError):
         tl_track.tlid = None
Beispiel #4
0
 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))
Beispiel #5
0
    def add(self, tracks=None, at_position=None, uri=None, uris=None):
        """
        Add 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 ``uri`` or ``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 are inserted 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` or :class:`None`
        :param at_position: position in tracklist to add tracks
        :type at_position: int or :class:`None`
        :param uri: URI for tracks to add
        :type uri: string or :class:`None`
        :param uris: list of URIs for tracks to add
        :type uris: list of string or :class:`None`
        :rtype: list of :class:`mopidy.models.TlTrack`

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

        .. deprecated:: 1.0
            The ``tracks`` and ``uri`` arguments. Use ``uris``.
        """
        if sum(o is not None for o in [tracks, uri, uris]) != 1:
            raise ValueError(
                'Exactly one of "tracks", "uri" or "uris" must be set')

        tracks is None or validation.check_instances(tracks, Track)
        uri is None or validation.check_uri(uri)
        uris is None or validation.check_uris(uris)
        validation.check_integer(at_position or 0)

        if tracks:
            deprecation.warn('core.tracklist.add:tracks_arg')

        if uri:
            deprecation.warn('core.tracklist.add:uri_arg')

        if tracks is None:
            if uri is not None:
                uris = [uri]

            tracks = []
            track_map = self.core.library.lookup(uris=uris)
            for uri in uris:
                tracks.extend(track_map[uri])

        tl_tracks = []
        max_length = self.core._config['core']['max_tracklist_length']

        for track in tracks:
            if self.get_length() >= max_length:
                raise exceptions.TracklistFull(
                    'Tracklist may contain at most %d tracks.' % max_length)

            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
Beispiel #6
0
 def test_repr(self):
     self.assertEquals(
         "TlTrack(tlid=123, track=Track(artists=[], uri=u'uri'))",
         repr(TlTrack(tlid=123, track=Track(uri='uri'))))
Beispiel #7
0
 def test_eq_none(self):
     self.assertNotEqual(TlTrack(), None)
Beispiel #8
0
 def test_repr(self):
     assert "TlTrack(tlid=123, track=Track(uri='uri'))" == repr(
         TlTrack(tlid=123, track=Track(uri="uri")))
Beispiel #9
0
 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)
     assert tl_track1 == tl_track2
Beispiel #10
0
 def test_invalid_kwarg(self):
     with self.assertRaises(TypeError):
         TlTrack(foo="baz")
Beispiel #11
0
 def test_positional_args(self):
     tlid = 123
     track = Track()
     tl_track = TlTrack(tlid, track)
     assert tl_track.tlid == tlid
     assert tl_track.track == track
Beispiel #12
0
 def test_track(self):
     track = Track()
     tl_track = TlTrack(track=track)
     assert tl_track.track == track
     with self.assertRaises(AttributeError):
         tl_track.track = None
Beispiel #13
0
 def test_tlid(self):
     tlid = 123
     tl_track = TlTrack(tlid=tlid)
     assert tl_track.tlid == tlid
     with self.assertRaises(AttributeError):
         tl_track.tlid = None
Beispiel #14
0
 def test_index_raises_value_error_if_item_not_found(self):
     test = lambda: self.controller.index(TlTrack(0, Track()))
     self.assertRaises(ValueError, test)
Beispiel #15
0
 def test_index_returns_none_if_item_not_found(self):
     tl_track = TlTrack(0, Track())
     self.assertEqual(self.controller.index(tl_track), None)
Beispiel #16
0
 def test_eq_none(self):
     assert TlTrack() is not None
Beispiel #17
0
 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)
Beispiel #18
0
 def test_eq_other(self):
     assert TlTrack() != "other"
Beispiel #19
0
 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)
Beispiel #20
0
 def test_ne_tlid(self):
     tl_track1 = TlTrack(tlid=123)
     tl_track2 = TlTrack(tlid=321)
     assert tl_track1 != tl_track2
     assert hash(tl_track1) != hash(tl_track2)
Beispiel #21
0
 def test_eq_other(self):
     self.assertNotEqual(TlTrack(), 'other')
Beispiel #22
0
 def test_ne_track(self):
     tl_track1 = TlTrack(track=Track(uri="a"))
     tl_track2 = TlTrack(track=Track(uri="b"))
     assert tl_track1 != tl_track2
     assert hash(tl_track1) != hash(tl_track2)
Beispiel #23
0
 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))
Beispiel #24
0
 def test_listener_has_default_impl_for_track_playback_ended(self):
     self.listener.track_playback_ended(TlTrack(), 0)
Beispiel #25
0
 def test_track_to_mpd_format_with_tlid(self):
     result = translator.track_to_mpd_format(TlTrack(1, Track()),
                                             tagtype_list.TAGTYPE_LIST)
     assert ("Id", 1) not in result
Beispiel #26
0
 def test_tlid(self):
     tlid = 123
     tl_track = TlTrack(tlid=tlid)
     self.assertEqual(tl_track.tlid, tlid)
     self.assertRaises(AttributeError, setattr, tl_track, 'tlid', None)
Beispiel #27
0
 def test_track_to_mpd_format_with_position_and_tlid(self):
     result = translator.track_to_mpd_format(TlTrack(2, Track()),
                                             position=1)
     self.assertIn(('Pos', 1), result)
     self.assertIn(('Id', 2), result)
Beispiel #28
0
 def test_track(self):
     track = Track()
     tl_track = TlTrack(track=track)
     self.assertEqual(tl_track.track, track)
     self.assertRaises(AttributeError, setattr, tl_track, 'track', None)
Beispiel #29
0
 def test_track(self):
     track = Track()
     tl_track = TlTrack(track=track)
     self.assertEqual(tl_track.track, track)
     with self.assertRaises(AttributeError):
         tl_track.track = None
Beispiel #30
0
 def test_invalid_kwarg(self):
     test = lambda: TlTrack(foo='baz')
     self.assertRaises(TypeError, test)
Beispiel #31
0
 def test_track(self):
     track = Track()
     tl_track = TlTrack(track=track)
     self.assertEqual(tl_track.track, track)
     with self.assertRaises(AttributeError):
         tl_track.track = None
Beispiel #32
0
 def test_track_to_mpd_format_with_position_and_tlid(self):
     result = translator.track_to_mpd_format(
         TlTrack(2, Track(uri="a uri")), position=1
     )
     assert ("Pos", 1) in result
     assert ("Id", 2) in result