-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error when replaceable field missing
- Loading branch information
1 parent
894681c
commit 0f6e78b
Showing
5 changed files
with
91 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
### 0.1.1 (2021-09-09) | ||
|
||
* Fixed issue when attempting to replace a missing field. | ||
|
||
### 0.1 (2021-09-08) | ||
|
||
* Initial release. |
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,2 +1,2 @@ | ||
from pkgutil import extend_path | ||
__path__ = extend_path(__path__, __name__) | ||
__path__ = extend_path(__path__, __name__) |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import unittest | ||
|
||
import beets as beets | ||
from beets.autotag.hooks import AlbumInfo | ||
from beets.autotag.hooks import TrackInfo | ||
from beetsplug.importreplace import ImportReplace | ||
|
||
|
||
class ImportReplaceTest(unittest.TestCase): | ||
|
||
def _create_track_info(self, title: str = None, artist: str = None, | ||
artist_sort: str = None, artist_credit: str = None): | ||
return TrackInfo(title=title, artist=artist, artist_sort=artist_sort, | ||
artist_credit=artist_credit) | ||
|
||
def _create_album_info(self, tracks: [TrackInfo] = None, album: str = None, | ||
artist: str = None, artist_sort: str = None, | ||
artist_credit: str = None): | ||
return AlbumInfo(tracks=tracks or [], album=album, artist=artist, | ||
artist_sort=artist_sort, artist_credit=artist_credit) | ||
|
||
def _set_config(self, item_fields: [str], album_fields: [str], | ||
replace: {str: str}): | ||
beets.config['importreplace']['item_fields'] = item_fields | ||
beets.config['importreplace']['album_fields'] = album_fields | ||
beets.config['importreplace']['replace'] = replace | ||
|
||
def test_replaces_only_config_fields(self): | ||
"""Check if plugin replaces text in only the specified fields""" | ||
self._set_config(item_fields=['title'], album_fields=['album'], | ||
replace={'a': 'x'}) | ||
tracks = [self._create_track_info(title='Fao', artist='Bar')] | ||
album_info = self._create_album_info(tracks=tracks, album='albumTest', | ||
artist='Bar') | ||
subject = ImportReplace() | ||
subject._albuminfo_received(album_info) | ||
self.assertEqual(album_info.album, 'xlbumTest') | ||
self.assertEqual(album_info.artist, 'Bar') | ||
self.assertEqual(album_info.tracks[0].title, 'Fxo') | ||
self.assertEqual(album_info.tracks[0].artist, 'Bar') | ||
|
||
def test_handles_empty_fields(self): | ||
"""Verify that plugin works when field marked for replacement | ||
is absent""" | ||
self._set_config(item_fields=['title', 'artist'], | ||
album_fields=['album', 'artist'], | ||
replace={'a': 'x'}) | ||
tracks = [self._create_track_info(title='Fao', artist=None)] | ||
album_info = self._create_album_info(tracks=tracks, album='albumTest', | ||
artist=None) | ||
subject = ImportReplace() | ||
subject._albuminfo_received(album_info) | ||
self.assertEqual(album_info.album, 'xlbumTest') | ||
self.assertEqual(album_info.artist, None) | ||
self.assertEqual(album_info.tracks[0].title, 'Fxo') | ||
self.assertEqual(album_info.tracks[0].artist, None) |