Skip to content

Commit

Permalink
core: Make history.add() private
Browse files Browse the repository at this point in the history
Instead of changing the signature to add(uri, name) I opted for
renaming it to _add_track(track).

Since it's internal we may change it whenever we like to. Since you need
different logic for extracting an interesting name from a track and from
a ref or a stream title, it makes sense to add another method for adding
refs/stream titles to the history when that time comes.

Fixes #1056
  • Loading branch information
jodal committed Mar 20, 2015
1 parent 35a8fec commit bb0a6a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Expand Up @@ -26,7 +26,7 @@ v1.0.0 (UNRELEASED)
the Python API with the WebSocket/JavaScript API. (Fixes: :issue:`952`)

- Add :class:`mopidy.core.HistoryController` which keeps track of what tracks
have been played. (Fixes: :issue:`423`, PR: :issue:`803`)
have been played. (Fixes: :issue:`423`, :issue:`1056`, PR: :issue:`803`)

- Add :class:`mopidy.core.MixerController` which keeps track of volume and
mute. (Fixes: :issue:`962`)
Expand Down
4 changes: 3 additions & 1 deletion mopidy/core/history.py
Expand Up @@ -15,9 +15,11 @@ class HistoryController(object):
def __init__(self):
self._history = []

def add(self, track):
def _add_track(self, track):
"""Add track to the playback history.
Internal method for :class:`mopidy.core.PlaybackController`.
:param track: track to add
:type track: :class:`mopidy.models.Track`
"""
Expand Down
2 changes: 1 addition & 1 deletion mopidy/core/playback.py
Expand Up @@ -312,7 +312,7 @@ def play(self, tl_track=None, on_error_step=1):

if success:
self.core.tracklist._mark_playing(tl_track)
self.core.history.add(tl_track.track)
self.core.history._add_track(tl_track.track)
# TODO: replace with stream-changed
self._trigger_track_playback_started()
else:
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_history.py
Expand Up @@ -18,24 +18,24 @@ def setUp(self): # noqa: N802
self.history = HistoryController()

def test_add_track(self):
self.history.add(self.tracks[0])
self.history._add_track(self.tracks[0])
self.assertEqual(self.history.get_length(), 1)

self.history.add(self.tracks[1])
self.history._add_track(self.tracks[1])
self.assertEqual(self.history.get_length(), 2)

self.history.add(self.tracks[2])
self.history._add_track(self.tracks[2])
self.assertEqual(self.history.get_length(), 3)

def test_non_tracks_are_rejected(self):
with self.assertRaises(TypeError):
self.history.add(object())
self.history._add_track(object())

self.assertEqual(self.history.get_length(), 0)

def test_history_entry_contents(self):
track = self.tracks[0]
self.history.add(track)
self.history._add_track(track)

result = self.history.get_history()
(timestamp, ref) = result[0]
Expand Down

0 comments on commit bb0a6a9

Please sign in to comment.