-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing tests for LocalCollection and LocalLibrary methods (#94)
- Loading branch information
1 parent
e712516
commit 42a87e0
Showing
16 changed files
with
160 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,61 @@ | ||
from abc import ABCMeta | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
from musify.libraries.local.library import LocalLibrary | ||
from musify.libraries.local.playlist.m3u import SyncResultM3U | ||
from musify.libraries.local.playlist.xautopf import SyncResultXAutoPF | ||
from tests.libraries.core.collection import LibraryTester | ||
from tests.libraries.local.track.testers import LocalCollectionTester | ||
|
||
|
||
class LocalLibraryTester(LibraryTester, LocalCollectionTester, metaclass=ABCMeta): | ||
pass | ||
|
||
@staticmethod | ||
async def test_save_playlists(library: LocalLibrary): | ||
playlists = [pl for pl in library.playlists.values() if len(pl) > 0] | ||
for playlist in playlists: | ||
playlist.pop() | ||
|
||
results = await library.save_playlists(dry_run=True) | ||
|
||
for pl, result in results.items(): | ||
print(pl.name, result) | ||
for pl in playlists: | ||
print(pl.name, len(pl)) | ||
|
||
assert len(results) == len(library.playlists) | ||
for pl, result in results.items(): | ||
if pl not in playlists: | ||
continue | ||
|
||
if isinstance(result, SyncResultM3U): | ||
assert result.removed == 1 | ||
elif isinstance(result, SyncResultXAutoPF): | ||
assert result.start - result.final == 1 | ||
|
||
@staticmethod | ||
def test_restore_tracks(library: LocalLibrary): | ||
new_title = "brand new title" | ||
new_artist = "brand new artist" | ||
|
||
for track in library: | ||
assert track.title != "brand new title" | ||
assert track.artist != new_artist | ||
|
||
backup: list[dict[str, Any]] = library.json()["tracks"] | ||
for track in backup: | ||
track["title"] = new_title | ||
|
||
library.restore_tracks(backup) | ||
for track in library: | ||
assert track.title == "brand new title" | ||
assert track.artist != new_artist | ||
|
||
for track in backup: | ||
track["artist"] = new_artist | ||
|
||
library.restore_tracks({Path(track["path"]): track for track in backup}) | ||
for track in library: | ||
assert track.title == "brand new title" | ||
assert track.artist == new_artist |
Oops, something went wrong.