From cefb4bfe225459c4d36c72f82af6e26b5371097b Mon Sep 17 00:00:00 2001 From: Gabriel Push Date: Tue, 9 Dec 2025 12:12:53 -0500 Subject: [PATCH] Fix verbose comments and add e,c test --- beetsplug/edit.py | 15 ++------------- test/plugins/test_edit.py | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/beetsplug/edit.py b/beetsplug/edit.py index 168f72da1..46e756122 100644 --- a/beetsplug/edit.py +++ b/beetsplug/edit.py @@ -275,24 +275,17 @@ class EditPlugin(plugins.BeetsPlugin): ui.print_("No changes to apply.") return False - # Confirm the changes. + # For cancel/keep-editing, restore objects to their original + # in-memory state so temp edits don't leak into the session choice = ui.input_options( ("continue Editing", "apply", "cancel") ) if choice == "a": # Apply. return True elif choice == "c": # Cancel. - # Revert all temporary changes made in this edit session - # so that objects return to their original in-memory - # state (including tags provided by other plugins such as - # `fromfilename`). self.apply_data(objs, new_data, old_data) return False elif choice == "e": # Keep editing. - # Revert changes on the objects, but keep the edited YAML - # file so the user can continue editing from their last - # version. On the next iteration, differences will again - # be computed against the original state (`old_data`). self.apply_data(objs, new_data, old_data) continue @@ -382,10 +375,6 @@ class EditPlugin(plugins.BeetsPlugin): # to the files if needed without re-applying metadata. return Action.RETAG else: - # Edit cancelled / no edits made. `edit_objects` has already - # restored each object to its original in-memory state, so there - # is nothing more to do here. Returning None lets the importer - # resume the candidate prompt. return None def importer_edit_candidate(self, session, task): diff --git a/test/plugins/test_edit.py b/test/plugins/test_edit.py index 8be4c29b8..d0e03d0e5 100644 --- a/test/plugins/test_edit.py +++ b/test/plugins/test_edit.py @@ -178,23 +178,34 @@ class EditCommandTest(EditMixin, BeetsTestCase): def test_title_edit_keep_editing_then_apply(self, mock_write): """Edit titles, keep editing once, then apply changes.""" - # First, choose "keep editing" so changes are reverted in memory but - # kept in the YAML file; then choose "apply" to commit them. self.run_mocked_command( {"replacements": {"t\u00eftle": "modified t\u00eftle"}}, # keep Editing, then Apply ["e", "a"], ) - # Writes should only happen once per track, when we finally apply. assert mock_write.call_count == self.TRACK_COUNT - # All item titles (and mtimes) should now reflect the modified values. self.assertItemFieldsModified( self.album.items(), self.items_orig, ["title", "mtime"], ) + def test_title_edit_keep_editing_then_cancel(self, mock_write): + """Edit titles, keep editing once, then cancel.""" + self.run_mocked_command( + {"replacements": {"t\u00eftle": "modified t\u00eftle"}}, + # keep Editing, then Cancel + ["e", "c"], + ) + + assert mock_write.call_count == 0 + self.assertItemFieldsModified( + self.album.items(), + self.items_orig, + [], + ) + def test_noedit(self, mock_write): """Do not edit anything.""" # Do not edit anything.