From 2e307b519af55b6e6a12eb9f9bcb72d13f8ac5cc Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Sat, 20 Sep 2025 19:18:56 +0200 Subject: [PATCH] lastgenre: Also mock try_write in test_pretend.. and add and original genre instead empty string (clarify intention of test / readability). Remove not really necessary assert items checks. --- test/plugins/test_lastgenre.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/plugins/test_lastgenre.py b/test/plugins/test_lastgenre.py index 273be4b28..d6df42f97 100644 --- a/test/plugins/test_lastgenre.py +++ b/test/plugins/test_lastgenre.py @@ -137,7 +137,7 @@ class LastGenrePluginTest(BeetsTestCase): albumartist="Pretend Artist", artist="Pretend Artist", title="Pretend Track", - genre="", + genre="Original Genre", ) album = self.lib.add_album([item]) @@ -151,7 +151,9 @@ class LastGenrePluginTest(BeetsTestCase): return_value=("Mock Genre", "mock stage"), ) as mock_get_genre: with patch.object(self.plugin._log, "info") as log_info: - command.func(self.lib, opts, args) + # Mock try_write to verify it's never called in pretend mode + with patch.object(item, "try_write") as mock_try_write: + command.func(self.lib, opts, args) mock_get_genre.assert_called_once() @@ -159,12 +161,12 @@ class LastGenrePluginTest(BeetsTestCase): call.args[1] == "Pretend: " for call in log_info.call_args_list ) - stored_album = self.lib.get_album(album.id) - assert stored_album.genre == "" + # Verify that try_write was never called (file operations skipped) + mock_try_write.assert_not_called() - items = list(stored_album.items()) - assert items - assert items[0].genre == "" + stored_album = self.lib.get_album(album.id) + assert stored_album.genre == "Original Genre" + assert stored_album.items()[0].genre == "Original Genre" def test_no_duplicate(self): """Remove duplicated genres."""