#NEWLINE# def test_plugin_callback( self ) : #NEWLINE# #INDENT# 'Test that plugin callbacks are being called upon user choice.' #NEWLINE# class DummyPlugin ( plugins . BeetsPlugin ) : #NEWLINE# #INDENT# def __init__( self ) : #NEWLINE# #INDENT# super ( DummyPlugin , self ) . __init__ ( ) #NEWLINE# self . register_listener ( 'before_choose_candidate' , self . return_choices ) #NEWLINE# #UNINDENT# def return_choices( self , session , task ) : #NEWLINE# #INDENT# return [ ui . commands . PromptChoice ( 'f' , 'Foo' , self . foo ) ] #NEWLINE# #UNINDENT# def foo( self , session , task ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# self . register_plugin ( DummyPlugin ) #NEWLINE# opts = ( ( 'Apply' , 'More candidates' , 'Skip' , 'Use as-is' , 'as Tracks' , 'Group albums' , 'Enter search' , 'enter Id' , 'aBort' ) + ( 'Foo' , ) ) #NEWLINE# with patch . object ( DummyPlugin , 'foo' , autospec = True ) as mock_foo : #NEWLINE# #INDENT# with helper . control_stdin ( '\n' . join ( [ 'f' , 's' ] ) ) : #NEWLINE# #INDENT# self . importer . run ( ) #NEWLINE# #UNINDENT# self . assertEqual ( mock_foo . call_count , 1 ) #NEWLINE# #UNINDENT# self . assertEqual ( opts . mock_input_options . call_count , 2 ) #NEWLINE# self . mock_input_options . assert_called_with ( opts , default = 'a' , require = ANY )