@@ -37,12 +37,14 @@ def _get_hook(self, event: str, command: str) -> dict[str, str]:
3737
3838
3939class HookLogsTest (HookTestCase ):
40+ HOOK : plugins .EventType = "write"
41+
4042 @contextmanager
4143 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 )]}
4345
4446 with self .configure_plugin (config ), capture_log ("beets.hook" ) as logs :
45- plugins .send ("test_event" )
47+ plugins .send (self . HOOK )
4648 yield logs
4749
4850 def test_hook_empty_command (self ):
@@ -53,13 +55,13 @@ def test_hook_empty_command(self):
5355 @unittest .skipIf (sys .platform == "win32" , "win32" )
5456 def test_hook_non_zero_exit (self ):
5557 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
5759
5860 def test_hook_non_existent_command (self ):
5961 with self ._configure_logs ("non-existent-command" ) as logs :
6062 logs = "\n " .join (logs )
6163
62- assert "hook: hook for test_event failed: " in logs
64+ assert f "hook: hook for { self . HOOK } failed: " in logs
6365 # The error message is different for each OS. Unfortunately the text is
6466 # different in each case, where the only shared text is the string
6567 # 'file' and substring 'Err'
@@ -68,13 +70,11 @@ def test_hook_non_existent_command(self):
6870
6971
7072class 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" ]
7474
7575 def setUp (self ):
7676 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 ]
7878
7979 def _test_command (
8080 self ,
@@ -93,13 +93,14 @@ def _test_command(
9393 2. Assert that a file has been created under the original path, which proves
9494 that the configured hook command has been executed.
9595 """
96+ events_with_paths = list (zip (self .EVENTS , self .paths ))
9697 hooks = [
9798 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
99100 ]
100101
101102 with self .configure_plugin ({"hooks" : hooks }):
102- for event , path in zip ( self . events , self . paths ) :
103+ for event , path in events_with_paths :
103104 if send_path_kwarg :
104105 plugins .send (event , path = path )
105106 else :
0 commit comments