fix scanner tests
This commit is contained in:
parent
26b7fde93d
commit
4acd16bdde
|
@ -49,14 +49,17 @@ class MediaScanner:
|
||||||
asyncio.run(_do_import())
|
asyncio.run(_do_import())
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
async def _import_one_track(self, path):
|
def _get_tags(self, path): # pragma: no cover
|
||||||
tags = music_tag.load_file(path)
|
tags = music_tag.load_file(path)
|
||||||
relpath = str(path.relative_to(self.root))
|
return {
|
||||||
stmt = groove.db.track.insert({
|
|
||||||
'relpath': relpath,
|
|
||||||
'artist': str(tags.resolve('album_artist')),
|
'artist': str(tags.resolve('album_artist')),
|
||||||
'title': str(tags['title']),
|
'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']}")
|
logging.debug(f"{tags['artist']} - {tags['title']}")
|
||||||
self.db.execute(stmt)
|
self.db.execute(stmt)
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,16 @@ def test_scanner(monkeypatch, in_memory_db, media):
|
||||||
|
|
||||||
# replace the filesystem glob with the test fixture generator
|
# replace the filesystem glob with the test fixture generator
|
||||||
monkeypatch.setattr(scanner.MediaScanner, 'find_sources', MagicMock(return_value=media()))
|
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)
|
test_scanner = scanner.media_scanner(root=Path('/test'), db=in_memory_db)
|
||||||
expected = len(fixture_tracks)
|
expected = len(fixture_tracks)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user