mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 09:34:23 +01:00
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).
This commit is contained in:
parent
3e35660ff3
commit
af5ce6e7e2
1 changed files with 9 additions and 25 deletions
|
|
@ -33,7 +33,6 @@ def get_temporary_path():
|
||||||
return os.path.join(temporary_directory, temporary_name)
|
return os.path.join(temporary_directory, temporary_name)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Find a good way to test shell option
|
|
||||||
class HookTest(_common.TestCase, TestHelper):
|
class HookTest(_common.TestCase, TestHelper):
|
||||||
TEST_HOOK_COUNT = 5
|
TEST_HOOK_COUNT = 5
|
||||||
|
|
||||||
|
|
@ -44,23 +43,12 @@ class HookTest(_common.TestCase, TestHelper):
|
||||||
self.unload_plugins()
|
self.unload_plugins()
|
||||||
self.teardown_beets()
|
self.teardown_beets()
|
||||||
|
|
||||||
def _add_hook(self, event, command, substitute_event=None, shell=None,
|
def _add_hook(self, event, command):
|
||||||
substitute_args=None):
|
|
||||||
|
|
||||||
hook = {
|
hook = {
|
||||||
'event': event,
|
'event': event,
|
||||||
'command': command
|
'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 = config['hook']['hooks'].get(list) if 'hook' in config else []
|
||||||
hooks.append(hook)
|
hooks.append(hook)
|
||||||
|
|
||||||
|
|
@ -72,29 +60,26 @@ class HookTest(_common.TestCase, TestHelper):
|
||||||
]
|
]
|
||||||
|
|
||||||
for index, path in enumerate(temporary_paths):
|
for index, path in enumerate(temporary_paths):
|
||||||
self._add_hook('test_event_{0}'.format(index),
|
self._add_hook('test_no_argument_event_{0}'.format(index),
|
||||||
'echo > "{0}"'.format(path))
|
'touch "{0}"'.format(path))
|
||||||
|
|
||||||
self.load_plugins('hook')
|
self.load_plugins('hook')
|
||||||
|
|
||||||
for index in range(len(temporary_paths)):
|
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:
|
for path in temporary_paths:
|
||||||
self.assertTrue(os.path.isfile(path))
|
self.assertTrue(os.path.isfile(path))
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
def test_hook_event_substitution(self):
|
def test_hook_event_substitution(self):
|
||||||
|
|
||||||
temporary_directory = tempfile._get_default_tempdir()
|
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)]
|
range(self.TEST_HOOK_COUNT)]
|
||||||
|
|
||||||
for event in event_names:
|
for event in event_names:
|
||||||
self._add_hook(event,
|
self._add_hook(event,
|
||||||
'echo > "{0}"'.format(
|
'touch "{0}/{{event}}"'.format(temporary_directory))
|
||||||
os.path.join(temporary_directory, '%EVENT%')
|
|
||||||
))
|
|
||||||
|
|
||||||
self.load_plugins('hook')
|
self.load_plugins('hook')
|
||||||
|
|
||||||
|
|
@ -113,14 +98,13 @@ class HookTest(_common.TestCase, TestHelper):
|
||||||
]
|
]
|
||||||
|
|
||||||
for index, path in enumerate(temporary_paths):
|
for index, path in enumerate(temporary_paths):
|
||||||
self._add_hook('test_event_{0}'.format(index),
|
self._add_hook('test_argument_event_{0}'.format(index),
|
||||||
'echo > "%PATH%"'.format(path),
|
'touch "{path}"')
|
||||||
substitute_args={'path': '%PATH%'})
|
|
||||||
|
|
||||||
self.load_plugins('hook')
|
self.load_plugins('hook')
|
||||||
|
|
||||||
for index, path in enumerate(temporary_paths):
|
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:
|
for path in temporary_paths:
|
||||||
self.assertTrue(os.path.isfile(path))
|
self.assertTrue(os.path.isfile(path))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue