curds: Implement an artist playlist node

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-19 14:45:39 -04:00
parent 0cd702c908
commit 42a26832eb
2 changed files with 68 additions and 0 deletions

20
curds/playlist/artist.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright 2019 (c) Anna Schumaker.
from . import node
from . import playlist
from .. import notify
class ArtistNode(node.PlaylistNode):
def __init__(self):
node.PlaylistNode.__init__(self, "Artists", "system-users")
notify.register("new-track", self.new_track)
def new_track(self, track):
plist = self.lookup(track["albumartist"])
if plist == None:
plist = playlist.Playlist(track["albumartist"], self.icon)
self.insert_child(plist)
plist.add(track)
def reset(self):
node.PlaylistNode.reset(self)
notify.register("new-track", self.new_track)

View File

@ -0,0 +1,48 @@
# Copyright 2019 (c) Anna Schumaker
from . import artist
from . import node
from .. import notify
from .. import tags
import os
import unittest
test_library = os.path.abspath("./trier/Test Library")
test_album = os.path.join("Test Album 1", "01 - Test Track 01.ogg")
test_album2 = os.path.join("Test Album 2", "01 - Test Track 01.ogg")
class TestArtistPlaylist(unittest.TestCase):
def test_artist_node(self):
notify.registered.clear()
tags.clear()
anode = artist.ArtistNode()
self.assertIsInstance(anode, node.PlaylistNode)
self.assertEqual(anode.name, "Artists")
self.assertEqual(anode.icon, "system-users")
track1 = tags.Track.lookup(os.path.join(test_library, "Test Artist 01", test_album))
self.assertEqual(anode.n_children(), 1)
plist = anode.nth_child(0)
self.assertEqual(plist.name, "Test Artist 01")
self.assertEqual(plist.icon, "system-users")
self.assertEqual(len(plist), 1)
self.assertEqual(plist[0], track1)
track2 = tags.Track.lookup(os.path.join(test_library, "Test Artist 02", test_album))
self.assertEqual(anode.n_children(), 2)
plist = anode.nth_child(1)
self.assertEqual(plist.name, "Test Artist 02")
self.assertEqual(len(plist), 1)
track3 = tags.Track.lookup(os.path.join(test_library, "Test Artist 02", test_album2))
self.assertEqual(anode.n_children(), 2)
self.assertEqual(len(plist), 2)
notify.cancel("new-track", anode.new_track)
anode.reset()
self.assertEqual(anode.n_children(), 0)
self.assertIn((anode.new_track, False), notify.registered["new-track"])