trackdb: Move the LibraryStore into the trackdb/__init__.py file

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-06-25 13:32:36 -04:00
parent 647a1955e5
commit fc647cd9b1
4 changed files with 32 additions and 28 deletions

View File

@ -9,6 +9,21 @@ import unittest
test_tracks = pathlib.Path("./trier/Test Album")
class TestLibraryStore(unittest.TestCase):
def test_library_store(self):
store = trackdb.LibraryStore()
lib = store.add(test_tracks)
self.assertIsInstance(lib, trackdb.library.LibraryPath)
lib.scan().join()
self.assertEqual(len(lib), 12)
store.remove(lib)
lib.clear.join()
self.assertEqual(len(lib), 0)
class TestTrackDB(unittest.TestCase):
def setUp(self):
trackdb.Library.Added.register(self.on_library_added)
@ -27,7 +42,7 @@ class TestTrackDB(unittest.TestCase):
def test_trackdb_init(self):
self.assertIsInstance(trackdb.save_bus, bus.Bus)
self.assertIsInstance(trackdb.Library, trackdb.library.LibraryStore)
self.assertIsInstance(trackdb.Library, trackdb.LibraryStore)
self.assertEqual(trackdb.db_file, "trackdb.pickle")
self.assertEqual(trackdb.save_bus.timeout, 500)

View File

@ -2,6 +2,7 @@
from lib import bus
from lib import data
from lib import publisher
from lib import tagstore
from . import library
from . import tags
from . import track
@ -10,7 +11,21 @@ import threading
db_file = "trackdb.pickle"
save_bus = bus.Bus(500)
Library = library.LibraryStore()
class LibraryStore(tagstore.TagStore):
def __alloc_tag__(self, name, sort):
return library.LibraryPath(name)
def add(self, name):
return super().__add_tag__(name, None, None)
def remove(self, lib):
lib.clear()
super().remove(lib)
Library = LibraryStore()
def _do_save():
with data.DataFile(db_file, data.WRITE) as f:

View File

@ -37,17 +37,5 @@ class LibraryPath(tag.Tag):
self.tracks.clear()
class LibraryStore(tagstore.TagStore):
def __alloc_tag__(self, name, sort):
return LibraryPath(name)
def add(self, name):
return super().__add_tag__(name, None, None)
def remove(self, lib):
lib.clear()
super().remove(lib)
def reset():
Tracks.reset()

View File

@ -91,17 +91,3 @@ class TestLibraryPath(unittest.TestCase):
lib.clear().join()
self.assertEqual(len(lib), 0)
self.assertEqual(len(library.Tracks), 0)
class TestLibraryStore(unittest.TestCase):
def test_library_store(self):
store = library.LibraryStore()
lib = store.add(test_tracks)
self.assertIsInstance(lib, library.LibraryPath)
lib.scan().join()
self.assertEqual(len(lib), 12)
store.remove(lib)
lib.clear.join()
self.assertEqual(len(lib), 0)