<s> import types <EOL> from expects import expect <EOL> from mamba import describe , context , before <EOL> class Command ( object ) : <EOL> def __init__ ( self , key , handler ) : <EOL> self . key = frozenset ( key ) <EOL> self . handler = handler <EOL> @ property <EOL> def handler_args ( self ) : <EOL> function = self . handler <EOL> return function . func_code . co_varnames [ : function . func_code . co_argcount ] <EOL> def call ( self , ** kwargs ) : <EOL> expected_args = { name : kwargs . get ( name ) for name in self . handler_args } <EOL> return self . handler ( ** expected_args ) <EOL> with describe ( Command ) as _ : <EOL> with context ( '<STR_LIT>' ) : <EOL> def should_be_a_frozenset ( ) : <EOL> expect ( _ . command . key ) . to . be . a ( frozenset ) <EOL> def should_contain_the_given_key_words ( ) : <EOL> expect ( _ . command . key ) . to . have ( * _ . key ) <EOL> with context ( '<STR_LIT>' ) : <EOL> def should_be_a_function ( ) : <EOL> expect ( _ . command . handler ) . to . be . a ( types . FunctionType ) <EOL> def should_be_the_given_handler ( ) : <EOL> expect ( _ . command . handler ) . to . be ( _ . handler ) <EOL> with context ( '<STR_LIT>' ) : <EOL> def should_be_the_list_of_argument_names ( ) : <EOL> expect ( _ . command . handler_args ) . to . have ( * _ . handler_args ) <EOL> expect ( _ . command . handler_args ) . to . have . length ( len ( _ . handler_args ) ) <EOL> with context ( '<STR_LIT>' ) : <EOL> def should_call_the_handler_the_given_arguments ( ) : <EOL> call_result = _ . command . call ( ** _ . handler_kwargs ) <EOL> expect ( call_result ) . to . be . equal ( _ . called ) <EOL> def should_call_only_with_arguments_that_the_handler_understands ( ) : <EOL> call_args = { '<STR_LIT>' : None } <EOL> call_args . update ( _ . handler_kwargs ) <EOL> call_result = _ . command . call ( ** call_args ) <EOL> expect ( call_result ) . to . be . equal ( _ . called ) <EOL> def _handler ( first , second , third ) : <EOL> varname1 , varname2 , varname3 = None , None , None <EOL> return [ first , second , third ] <EOL> @ before . all <EOL> def fixture ( ) : <EOL> _ . key = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> _ . handler = _handler <EOL> _ . handler_args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> _ . handler_kwargs = { name : name for name in _ . handler_args } <EOL> _ . called = _ . handler_args <EOL> _ . command = Command ( _ . key , _ . handler ) </s>
