From cf7a04ea3624f18c3567b022efb892e4753e4d79 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Wed, 16 Oct 2019 21:55:46 +0100 Subject: [PATCH] Add tests for hook errors --- test/test_hook.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/test/test_hook.py b/test/test_hook.py index 81363c73c..2a48a72b1 100644 --- a/test/test_hook.py +++ b/test/test_hook.py @@ -20,7 +20,7 @@ import tempfile import unittest from test import _common -from test.helper import TestHelper +from test.helper import TestHelper, capture_log from beets import config from beets import plugins @@ -37,7 +37,7 @@ class HookTest(_common.TestCase, TestHelper): TEST_HOOK_COUNT = 5 def setUp(self): - self.setup_beets() # Converter is threaded + self.setup_beets() def tearDown(self): self.unload_plugins() @@ -54,6 +54,38 @@ class HookTest(_common.TestCase, TestHelper): config['hook']['hooks'] = hooks + def test_hook_empty_command(self): + self._add_hook('test_event', '') + + self.load_plugins('hook') + + with capture_log('beets.hook') as logs: + plugins.send('test_event') + + self.assertIn('hook: invalid command ""', logs) + + def test_hook_non_zero_exit(self): + self._add_hook('test_event', 'sh -c "exit 1"') + + self.load_plugins('hook') + + with capture_log('beets.hook') as logs: + plugins.send('test_event') + + self.assertIn('hook: hook for test_event exited with status 1', logs) + + def test_hook_non_existent_command(self): + self._add_hook('test_event', 'non-existent-command') + + self.load_plugins('hook') + + with capture_log('beets.hook') as logs: + plugins.send('test_event') + + self.assertTrue(any( + message.startswith("hook: hook for test_event failed: ") + for message in logs)) + def test_hook_no_arguments(self): temporary_paths = [ get_temporary_path() for i in range(self.TEST_HOOK_COUNT)