From 4acd16bdde2f996a1b9922f9dcca32279804a8f8 Mon Sep 17 00:00:00 2001 From: evilchili Date: Wed, 30 Nov 2022 23:42:06 -0800 Subject: [PATCH] fix scanner tests --- groove/db/scanner.py | 13 ++++++++----- test/test_scanner.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/groove/db/scanner.py b/groove/db/scanner.py index c3b2463..7884273 100644 --- a/groove/db/scanner.py +++ b/groove/db/scanner.py @@ -49,14 +49,17 @@ class MediaScanner: asyncio.run(_do_import()) self.db.commit() - async def _import_one_track(self, path): + def _get_tags(self, path): # pragma: no cover tags = music_tag.load_file(path) - relpath = str(path.relative_to(self.root)) - stmt = groove.db.track.insert({ - 'relpath': relpath, + return { 'artist': str(tags.resolve('album_artist')), 'title': str(tags['title']), - }).prefix_with('OR IGNORE') + } + + async def _import_one_track(self, path): + tags = self._get_tags(path) + tags['relpath'] = str(path.relative_to(self.root)) + stmt = groove.db.track.insert(tags).prefix_with('OR IGNORE') logging.debug(f"{tags['artist']} - {tags['title']}") self.db.execute(stmt) diff --git a/test/test_scanner.py b/test/test_scanner.py index 7e45274..384a1ae 100644 --- a/test/test_scanner.py +++ b/test/test_scanner.py @@ -35,6 +35,16 @@ def test_scanner(monkeypatch, in_memory_db, media): # replace the filesystem glob with the test fixture generator monkeypatch.setattr(scanner.MediaScanner, 'find_sources', MagicMock(return_value=media())) + + def mock_loader(path): + return { + 'artist': 'foo', + 'title': 'bar', + } + + # replace music_tag so it doesn't try to read things + monkeypatch.setattr(scanner.MediaScanner, '_get_tags', MagicMock(side_effect=mock_loader)) + test_scanner = scanner.media_scanner(root=Path('/test'), db=in_memory_db) expected = len(fixture_tracks)