Skip to content

Commit

Permalink
Add tests for hook errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Wilsdon committed Oct 17, 2019
1 parent 648f230 commit 532c3da
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions test/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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
Expand All @@ -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()
Expand All @@ -54,6 +54,36 @@ def _add_hook(self, event, command):

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.assertIn("hook: hook for test_event failed: [Errno 2] No such file or directory: 'non-existent-command': 'non-existent-command'", logs)

def test_hook_no_arguments(self):
temporary_paths = [
get_temporary_path() for i in range(self.TEST_HOOK_COUNT)
Expand Down

0 comments on commit 532c3da

Please sign in to comment.