Skip to content

Commit

Permalink
Make --rating-up work when song has no previous rating (#4172)
Browse files Browse the repository at this point in the history
Now assume songs with no ratings have the default rating.  (Also fix
other relative rating changes.)
  • Loading branch information
nemethf committed Oct 21, 2022
1 parent 5aecadf commit 99b956c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion quodlibet/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def _rating(app, value):
change = (1 / RATINGS.number)
if value[0] == '-':
change = -change
rating = song["~#rating"] + change
rating = song("~#rating") + change
else:
try:
rating = float(value)
Expand Down
15 changes: 12 additions & 3 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ def test_misc(self):
self.__send("random album")
self.__send("refresh")
self.__send("repeat 0")
self.__send("rating 0.5")
self.__send("rating +0.01")
self.__send("rating -10")
self.__send("show-window")
self.__send("song-list 1")
self.__send("stop-after 1")
Expand All @@ -109,3 +106,15 @@ def test_enqueue_files(self):
self.__send("enqueue-files "
"one,two\\, please,slash\\\\.mp3,four")
self.assertEquals(app.window.playlist.q.get(), songs)

def test_rating(self):
app.player.song = AudioFile(
{"album": "foo", "~filename": fsnative("/dev/null")})
self.__send("rating +")
self.assertAlmostEqual(app.player.song['~#rating'], 0.75)
self.__send("rating 0.4")
self.assertAlmostEqual(app.player.song['~#rating'], 0.4)
self.__send("rating +0.01")
self.assertAlmostEqual(app.player.song['~#rating'], 0.41)
self.__send("rating -10")
self.assertEquals(app.player.song['~#rating'], 0)

0 comments on commit 99b956c

Please sign in to comment.