emmental/curds/playlist/test_library.py

64 lines
2.0 KiB
Python

# Copyright 2019 (c) Anna Schumaker.
from . import library
from . import playlist
from .. import notify
from .. import threadqueue
from .. import trak
from .. import tree
import os
import time
import unittest
test_library = os.path.abspath("./trier/Test Library")
test_album = os.path.abspath("./trier/Test Album")
class TestLibraryPlaylist(unittest.TestCase):
def setUp(self):
library.reset()
notify.clear()
trak.reset()
def tearDownClass():
library.stop()
def test_library_node(self):
lnode = library.LibraryNode()
self.assertIsInstance(lnode, tree.ETree)
self.assertEqual(lnode.name, "Libraries")
self.assertEqual(lnode.icon, "folder-music")
def test_library_alloc_child(self):
lnode = library.LibraryNode()
plist = lnode.alloc_child(test_library, library.LIBRARY_ICON)
self.assertIsInstance(plist, library.LibraryPlaylist)
self.assertEqual(plist.name, test_library)
self.assertEqual(plist.icon, "folder-music")
self.assertEqual(plist.sort_order,
[ "artist", "date", "album", "discnumber", "tracknumber"])
library.join()
self.assertEqual(len(plist), 0)
def test_library_lookup(self):
lnode = library.LibraryNode()
self.assertFalse(trak.exists())
plist = lnode.lookup(test_library)
self.assertEqual(lnode.n_children(), 1)
self.assertIsInstance(plist, library.LibraryPlaylist)
library.join()
self.assertEqual(len(plist), 1250)
self.assertEqual(lnode.lookup(test_library + "/"), plist)
self.assertTrue(trak.exists())
plist = lnode.lookup(test_album)
self.assertEqual(lnode.n_children(), 2)
library.join()
self.assertEqual(len(plist), 12)
def test_library_thread_reset(self):
self.assertTrue(library.library_thread.is_alive())
library.stop()
self.assertFalse(library.library_thread.is_alive())
library.reset()
self.assertTrue(library.library_thread.is_alive())