core: Make index return current index when missing args
This commit is contained in:
parent
2e705cf8d4
commit
fba4069cfd
@ -204,6 +204,9 @@ class TracklistController(object):
|
|||||||
"""
|
"""
|
||||||
The position of the given track in the tracklist.
|
The position of the given track in the tracklist.
|
||||||
|
|
||||||
|
If neither *tl_track* or *tlid* is given we return the index of
|
||||||
|
the currently playing track.
|
||||||
|
|
||||||
:param tl_track: the track to find the index of
|
:param tl_track: the track to find the index of
|
||||||
:type tl_track: :class:`mopidy.models.TlTrack` or :class:`None`
|
:type tl_track: :class:`mopidy.models.TlTrack` or :class:`None`
|
||||||
:param tlid: of the track to find the index of
|
:param tlid: of the track to find the index of
|
||||||
@ -216,6 +219,9 @@ class TracklistController(object):
|
|||||||
tl_track is None or validation.check_instance(tl_track, TlTrack)
|
tl_track is None or validation.check_instance(tl_track, TlTrack)
|
||||||
tlid is None or validation.check_integer(tlid, min=0)
|
tlid is None or validation.check_integer(tlid, min=0)
|
||||||
|
|
||||||
|
if tl_track is None and tlid is None:
|
||||||
|
tl_track = self.core.playback.get_current_tl_track()
|
||||||
|
|
||||||
if tl_track is not None:
|
if tl_track is not None:
|
||||||
try:
|
try:
|
||||||
return self._tl_tracks.index(tl_track)
|
return self._tl_tracks.index(tl_track)
|
||||||
|
|||||||
@ -117,9 +117,11 @@ class TracklistIndexTest(unittest.TestCase):
|
|||||||
return {u: [t for t in self.tracks if t.uri == u] for u in uris}
|
return {u: [t for t in self.tracks if t.uri == u] for u in uris}
|
||||||
|
|
||||||
self.core = core.Core(mixer=None, backends=[])
|
self.core = core.Core(mixer=None, backends=[])
|
||||||
self.core.library.lookup = mock.Mock()
|
self.core.library = mock.Mock(spec=core.LibraryController)
|
||||||
self.core.library.lookup.side_effect = lookup
|
self.core.library.lookup.side_effect = lookup
|
||||||
|
|
||||||
|
self.core.playback = mock.Mock(spec=core.PlaybackController)
|
||||||
|
|
||||||
self.tl_tracks = self.core.tracklist.add(uris=[
|
self.tl_tracks = self.core.tracklist.add(uris=[
|
||||||
t.uri for t in self.tracks])
|
t.uri for t in self.tracks])
|
||||||
|
|
||||||
@ -154,3 +156,12 @@ class TracklistIndexTest(unittest.TestCase):
|
|||||||
def test_index_errors_out_for_invalid_tlid(self):
|
def test_index_errors_out_for_invalid_tlid(self):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
self.core.tracklist.index(tlid=-1)
|
self.core.tracklist.index(tlid=-1)
|
||||||
|
|
||||||
|
def test_index_without_args_returns_current_tl_track_index(self):
|
||||||
|
self.core.playback.get_current_tl_track.side_effect = [
|
||||||
|
None, self.tl_tracks[0], self.tl_tracks[1], self.tl_tracks[2]]
|
||||||
|
|
||||||
|
self.assertEqual(None, self.core.tracklist.index())
|
||||||
|
self.assertEqual(0, self.core.tracklist.index())
|
||||||
|
self.assertEqual(1, self.core.tracklist.index())
|
||||||
|
self.assertEqual(2, self.core.tracklist.index())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user