From e31680123bd27f46dadaa297a792057c74d1d34e Mon Sep 17 00:00:00 2001 From: Diego Moreda Date: Mon, 16 Nov 2015 14:46:13 +0100 Subject: [PATCH 1/2] edit: update extra fields in yaml test * Update test for extra fields in edited yaml, allowing the user to add fields while editing. Rename the test to test_single_edit_add_field to reflect its purpose more accurately. --- test/test_edit.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/test_edit.py b/test/test_edit.py index d3a38e7e5..c72eeee73 100644 --- a/test/test_edit.py +++ b/test/test_edit.py @@ -189,6 +189,19 @@ class EditCommandTest(unittest.TestCase, TestHelper): self.album.load() self.assertEqual(self.album.album, u'\u00e4lbum') + def test_single_edit_add_field(self): + """Edit the yaml file appending an extra field to the first item, then + apply changes.""" + # append "foo: bar" to item with id == 1 + self.run_mocked_command({'replacements': {u'id: 1': + u'id: 1\nfoo: bar'}}, + # Apply changes? y + ['y']) + + self.assertEqual(self.lib.items('id:1')[0].foo, 'bar') + self.assertCounts(write_call_count=1, + title_starts_with=u't\u00eftle') + def test_a_album_edit_apply(self): """Album query (-a), edit album field, apply changes.""" self.run_mocked_command({'replacements': {u'\u00e4lbum': @@ -239,18 +252,6 @@ class EditCommandTest(unittest.TestCase, TestHelper): self.assertCounts(write_call_count=0, title_starts_with=u't\u00eftle') - def test_invalid_yaml_extra_field(self): - """Edit the yaml file incorrectly (resulting in a well-formed but - invalid yaml document), appending an extra field to the first item.""" - # append "foo: bar" to item with id == 1 - self.run_mocked_command({'replacements': {u'id: 1': - u'id: 1\nfoo: bar'}}, - # no stdin - []) - - self.assertCounts(write_call_count=0, - title_starts_with=u't\u00eftle') - def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 917628340e1abf92cd8f27171c7c48fba2f0b875 Mon Sep 17 00:00:00 2001 From: Diego Moreda Date: Mon, 16 Nov 2015 14:48:05 +0100 Subject: [PATCH 2/2] edit: save only items with changes * Modify save_write() so only the items that do have pending changes (ie. dirty items) are saved to the database. --- beetsplug/edit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/edit.py b/beetsplug/edit.py index 3a22d014e..292d606f6 100644 --- a/beetsplug/edit.py +++ b/beetsplug/edit.py @@ -232,5 +232,6 @@ class EditPlugin(plugins.BeetsPlugin): # Save to the database and possibly write tags. for ob in objs: - self._log.debug('saving changes to {}', ob) - ob.try_sync(ui.should_write()) + if ob._dirty: + self._log.debug('saving changes to {}', ob) + ob.try_sync(ui.should_write())