Show genre change using show_model_changes

This commit is contained in:
Šarūnas Nejus 2025-10-15 11:14:26 +01:00
parent 0aac7315c3
commit 88011a7c65
No known key found for this signature in database
3 changed files with 10 additions and 9 deletions

View file

@ -1078,7 +1078,9 @@ def _field_diff(field, old, old_fmt, new, new_fmt):
return f"{oldstr} -> {newstr}"
def show_model_changes(new, old=None, fields=None, always=False):
def show_model_changes(
new, old=None, fields=None, always=False, print_obj: bool = True
):
"""Given a Model object, print a list of changes from its pristine
version stored in the database. Return a boolean indicating whether
any changes were found.
@ -1117,7 +1119,7 @@ def show_model_changes(new, old=None, fields=None, always=False):
)
# Print changes.
if changes or always:
if print_obj and (changes or always):
print_(format(old))
if changes:
print_("\n".join(changes))

View file

@ -468,7 +468,9 @@ class LastGenrePlugin(plugins.BeetsPlugin):
"""Fetch genre and log it."""
self._log.info(str(obj))
obj.genre, label = self._get_genre(obj)
self._log.info("Resolved ({}): {}", label, obj.genre)
self._log.debug("Resolved ({}): {}", label, obj.genre)
ui.show_model_changes(obj, fields=["genre"], print_obj=False)
@singledispatchmethod
def _process(self, obj: LibModel, write: bool) -> None:

View file

@ -152,13 +152,10 @@ class LastGenrePluginTest(PluginTestCase):
raise AssertionError("Unexpected store call")
# Verify that try_write was never called (file operations skipped)
with (
patch("beetsplug.lastgenre.Item.store", unexpected_store),
self.assertLogs() as logs,
):
self.run_command("lastgenre", "--pretend")
with patch("beetsplug.lastgenre.Item.store", unexpected_store):
output = self.run_with_output("lastgenre", "--pretend")
assert "Mock Genre" in str(logs.output)
assert "Mock Genre" in output
album.load()
assert album.genre == "Original Genre"
assert album.items()[0].genre == "Original Genre"