curds: Implement a GenreNode
This will eventually replace the GenreManager instance, and makes use of the new playlist node code Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0ea715a6d5
commit
751ad812f3
|
@ -1,6 +1,25 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import node
|
||||
from . import playlist
|
||||
from .. import notify
|
||||
|
||||
class GenrePlaylist(playlist.Playlist):
|
||||
def __init__(self, name):
|
||||
playlist.Playlist.__init__(self, name.title(), "audio-x-generic-symbolic")
|
||||
|
||||
|
||||
class GenreNode(node.PlaylistNode):
|
||||
def __init__(self):
|
||||
node.PlaylistNode.__init__(self, "Genres", "audio-x-generic-symbolic")
|
||||
notify.register("new-track", self.new_track)
|
||||
|
||||
def new_track(self, track):
|
||||
plist = self.lookup(track["genre"])
|
||||
if plist == None:
|
||||
plist = playlist.Playlist(track["genre"], self.icon)
|
||||
self.insert_child(plist)
|
||||
plist.add(track)
|
||||
|
||||
def reset(self):
|
||||
node.PlaylistNode.reset(self)
|
||||
notify.register("new-track", self.new_track)
|
||||
|
|
|
@ -1,9 +1,52 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import genre
|
||||
from . import node
|
||||
from . import playlist
|
||||
from .. import notify
|
||||
from .. import tags
|
||||
import os
|
||||
import unittest
|
||||
|
||||
test_library = os.path.abspath("./trier/Test Library/Test Artist 01")
|
||||
|
||||
class TestGenrePlaylist(unittest.TestCase):
|
||||
def test_genre_node(self):
|
||||
gnode = genre.GenreNode()
|
||||
self.assertIsInstance(gnode, node.PlaylistNode)
|
||||
self.assertEqual(gnode.name, "Genres")
|
||||
self.assertEqual(gnode.icon, "audio-x-generic-symbolic")
|
||||
|
||||
|
||||
track1 = tags.Track.lookup(os.path.join(test_library, "Test Album 1",
|
||||
"01 - Test Track 01.ogg"))
|
||||
self.assertEqual(gnode.n_children(), 1)
|
||||
|
||||
plist = gnode.nth_child(0)
|
||||
self.assertEqual(plist.name, "Test Genre 1")
|
||||
self.assertEqual(plist.icon, "audio-x-generic-symbolic")
|
||||
self.assertEqual(len(plist), 1)
|
||||
self.assertEqual(plist[0], track1)
|
||||
|
||||
|
||||
track2 = tags.Track.lookup(os.path.join(test_library, "Test Album 2",
|
||||
"02 - Test Track 02.ogg"))
|
||||
self.assertEqual(gnode.n_children(), 2)
|
||||
|
||||
plist = gnode.nth_child(1)
|
||||
self.assertEqual(plist.name, "Test Genre 2")
|
||||
self.assertEqual(len(plist), 1)
|
||||
|
||||
|
||||
track3 = tags.Track.lookup(os.path.join(test_library, "Test Album 2",
|
||||
"03 - Test Track 03.ogg"))
|
||||
self.assertEqual(gnode.n_children(), 2)
|
||||
self.assertEqual(len(plist), 2)
|
||||
|
||||
notify.cancel("new-track", gnode.new_track)
|
||||
gnode.reset()
|
||||
self.assertEqual(gnode.n_children(), 0)
|
||||
self.assertIn((gnode.new_track, False), notify.registered["new-track"])
|
||||
|
||||
def test_genre_plist(self):
|
||||
plist = genre.GenrePlaylist("genre")
|
||||
self.assertIsInstance(plist, genre.GenrePlaylist)
|
||||
|
|
Loading…
Reference in New Issue