From af5ce6e7e2cbad8250fa0a87618c79d80f2bc65c Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Mon, 18 Apr 2016 15:36:25 +0100 Subject: [PATCH] Fix event name collision in tests and update tests - Fix `test_event_X` name collision between tests causing tests to fail unexpectedly. - Update tests to match new hook plugin design (i.e. remove shell and subtitution option testing). --- test/test_hook.py | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/test/test_hook.py b/test/test_hook.py index f6b8b4941..6b046e8ef 100644 --- a/test/test_hook.py +++ b/test/test_hook.py @@ -33,7 +33,6 @@ def get_temporary_path(): return os.path.join(temporary_directory, temporary_name) -# TODO: Find a good way to test shell option class HookTest(_common.TestCase, TestHelper): TEST_HOOK_COUNT = 5 @@ -44,23 +43,12 @@ class HookTest(_common.TestCase, TestHelper): self.unload_plugins() self.teardown_beets() - def _add_hook(self, event, command, substitute_event=None, shell=None, - substitute_args=None): - + def _add_hook(self, event, command): hook = { 'event': event, 'command': command } - if substitute_event is not None: - hook['substitute_event'] = substitute_event - - if shell is not None: - hook['shell'] = shell - - if substitute_args is not None: - hook['substitute_args'] = substitute_args - hooks = config['hook']['hooks'].get(list) if 'hook' in config else [] hooks.append(hook) @@ -72,29 +60,26 @@ class HookTest(_common.TestCase, TestHelper): ] for index, path in enumerate(temporary_paths): - self._add_hook('test_event_{0}'.format(index), - 'echo > "{0}"'.format(path)) + self._add_hook('test_no_argument_event_{0}'.format(index), + 'touch "{0}"'.format(path)) self.load_plugins('hook') for index in range(len(temporary_paths)): - plugins.send('test_event_{0}'.format(index)) + plugins.send('test_no_argument_event_{0}'.format(index)) for path in temporary_paths: self.assertTrue(os.path.isfile(path)) os.remove(path) def test_hook_event_substitution(self): - temporary_directory = tempfile._get_default_tempdir() - event_names = ['test_event_{0}'.format(i) for i in + event_names = ['test_event_event_{0}'.format(i) for i in range(self.TEST_HOOK_COUNT)] for event in event_names: self._add_hook(event, - 'echo > "{0}"'.format( - os.path.join(temporary_directory, '%EVENT%') - )) + 'touch "{0}/{{event}}"'.format(temporary_directory)) self.load_plugins('hook') @@ -113,14 +98,13 @@ class HookTest(_common.TestCase, TestHelper): ] for index, path in enumerate(temporary_paths): - self._add_hook('test_event_{0}'.format(index), - 'echo > "%PATH%"'.format(path), - substitute_args={'path': '%PATH%'}) + self._add_hook('test_argument_event_{0}'.format(index), + 'touch "{path}"') self.load_plugins('hook') for index, path in enumerate(temporary_paths): - plugins.send('test_event_{0}'.format(index), path=path) + plugins.send('test_argument_event_{0}'.format(index), path=path) for path in temporary_paths: self.assertTrue(os.path.isfile(path))