@@ -37,12 +37,14 @@ def _get_hook(self, event: str, command: str) -> dict[str, str]:
37
37
38
38
39
39
class HookLogsTest (HookTestCase ):
40
+ HOOK : plugins .EventType = "write"
41
+
40
42
@contextmanager
41
43
def _configure_logs (self , command : str ) -> Iterator [list [str ]]:
42
- config = {"hooks" : [self ._get_hook ("test_event" , command )]}
44
+ config = {"hooks" : [self ._get_hook (self . HOOK , command )]}
43
45
44
46
with self .configure_plugin (config ), capture_log ("beets.hook" ) as logs :
45
- plugins .send ("test_event" )
47
+ plugins .send (self . HOOK )
46
48
yield logs
47
49
48
50
def test_hook_empty_command (self ):
@@ -53,13 +55,13 @@ def test_hook_empty_command(self):
53
55
@unittest .skipIf (sys .platform == "win32" , "win32" )
54
56
def test_hook_non_zero_exit (self ):
55
57
with self ._configure_logs ('sh -c "exit 1"' ) as logs :
56
- assert "hook: hook for test_event exited with status 1" in logs
58
+ assert f "hook: hook for { self . HOOK } exited with status 1" in logs
57
59
58
60
def test_hook_non_existent_command (self ):
59
61
with self ._configure_logs ("non-existent-command" ) as logs :
60
62
logs = "\n " .join (logs )
61
63
62
- assert "hook: hook for test_event failed: " in logs
64
+ assert f "hook: hook for { self . HOOK } failed: " in logs
63
65
# The error message is different for each OS. Unfortunately the text is
64
66
# different in each case, where the only shared text is the string
65
67
# 'file' and substring 'Err'
@@ -68,13 +70,11 @@ def test_hook_non_existent_command(self):
68
70
69
71
70
72
class HookCommandTest (HookTestCase ):
71
- TEST_HOOK_COUNT = 2
72
-
73
- events = [f"test_event_{ i } " for i in range (TEST_HOOK_COUNT )]
73
+ EVENTS : list [plugins .EventType ] = ["write" , "after_write" ]
74
74
75
75
def setUp (self ):
76
76
super ().setUp ()
77
- self .paths = [str (self .temp_dir_path / e ) for e in self .events ]
77
+ self .paths = [str (self .temp_dir_path / e ) for e in self .EVENTS ]
78
78
79
79
def _test_command (
80
80
self ,
@@ -93,13 +93,14 @@ def _test_command(
93
93
2. Assert that a file has been created under the original path, which proves
94
94
that the configured hook command has been executed.
95
95
"""
96
+ events_with_paths = list (zip (self .EVENTS , self .paths ))
96
97
hooks = [
97
98
self ._get_hook (e , f"touch { make_test_path (e , p )} " )
98
- for e , p in zip ( self . events , self . paths )
99
+ for e , p in events_with_paths
99
100
]
100
101
101
102
with self .configure_plugin ({"hooks" : hooks }):
102
- for event , path in zip ( self . events , self . paths ) :
103
+ for event , path in events_with_paths :
103
104
if send_path_kwarg :
104
105
plugins .send (event , path = path )
105
106
else :
0 commit comments