-
Notifications
You must be signed in to change notification settings - Fork 2k
Support multi-valued fields in rewrite and advancedrewrite plugins #6518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b6b7d3
Add tests for rewrite plugin
snejus bfd20b2
Add a failing test for list fields
snejus c81cfeb
Handle list fields in rewrite
snejus e21f56f
Update docs
snejus c906401
Show that only the first pattern applied currently
snejus 2ff7887
Apply all matching rules to a field
snejus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,75 @@ | ||
| import pytest | ||
|
|
||
| from beets.test.helper import PluginTestCase | ||
| from beets.ui import UserError | ||
| from beetsplug.rewrite import RewritePlugin | ||
|
|
||
|
|
||
| class RewritePluginTest(PluginTestCase): | ||
| plugin = "rewrite" | ||
| preload_plugin = False | ||
|
|
||
| def test_artist_rewrite_applies_to_artist_albumartist_and_album_fields( | ||
| self, | ||
| ): | ||
| with self.configure_plugin({"artist .*jimi hendrix.*": "Jimi Hendrix"}): | ||
| item = self.add_item( | ||
| artist="The Jimi Hendrix Experience", | ||
| albumartist="The Jimi Hendrix Experience", | ||
| ) | ||
| album = self.lib.add_album([item]) | ||
|
|
||
| assert item.artist == "Jimi Hendrix" | ||
| assert item.albumartist == "Jimi Hendrix" | ||
| assert album.evaluate_template("$albumartist") == "Jimi Hendrix" | ||
|
|
||
| def test_rewrite_all_matching_rules(self): | ||
| with self.configure_plugin( | ||
| { | ||
| "artist .*hendrix.*": "hendrix catalog", | ||
| "artist .*catalog.*": "Experience catalog", | ||
| } | ||
| ): | ||
| item = self.add_item( | ||
| artist="The Jimi Hendrix Experience", | ||
| albumartist="The Jimi Hendrix Experience", | ||
| ) | ||
|
|
||
| assert item.artist == "Experience catalog" | ||
|
|
||
| def test_rewrite_is_case_insensitive_and_leaves_non_matches_unchanged( | ||
| self, | ||
| ): | ||
| with self.configure_plugin( | ||
| {"artist odd eye circle": "LOONA / ODD EYE CIRCLE"} | ||
| ): | ||
| matching_item = self.add_item( | ||
| artist="ODD EYE CIRCLE", | ||
| albumartist="ODD EYE CIRCLE", | ||
| ) | ||
| other_item = self.add_item(artist="ARTMS", albumartist="ARTMS") | ||
|
|
||
| assert matching_item.artist == "LOONA / ODD EYE CIRCLE" | ||
| assert other_item.artist == "ARTMS" | ||
|
|
||
| def test_rewrite_applied_to_all_list_values(self): | ||
| with self.configure_plugin( | ||
| {"genres rock": "Classic Rock", "genres pop": "Pop"} | ||
| ): | ||
| item = self.add_item(genres=["rock", "pop", "techno"]) | ||
|
|
||
| assert item.genres == ["Classic Rock", "Pop", "techno"] | ||
|
|
||
|
snejus marked this conversation as resolved.
|
||
| def test_invalid_rewrite_spec_raises_user_error(self): | ||
| self.config[self.plugin].set({"artist": "Jimi Hendrix"}) | ||
|
|
||
| with pytest.raises(UserError, match="invalid rewrite specification"): | ||
| RewritePlugin() | ||
|
|
||
| def test_invalid_field_name_raises_user_error(self): | ||
| self.config[self.plugin].set({"not_a_field rock": "Classic Rock"}) | ||
|
|
||
| with pytest.raises( | ||
| UserError, match="invalid field name \\(not_a_field\\) in rewriter" | ||
| ): | ||
| RewritePlugin() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.