#NEWLINE# def test_register_target_macro_facory( self ) : #NEWLINE# #INDENT# class Fred ( Target ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# class FredMacro ( TargetMacro ) : #NEWLINE# #INDENT# def __init__( self , parse_context ) : #NEWLINE# #INDENT# self . _parse_context = parse_context #NEWLINE# #UNINDENT# def expand( self , * args , **kwargs ) : #NEWLINE# #INDENT# return self . _parse_context . create_object ( Fred , name = 'frog' , dependencies = [ kwargs [ 'name' ] ] ) #NEWLINE# #UNINDENT# #UNINDENT# class FredFactory ( TargetMacro . Factory ) : #NEWLINE# #INDENT# @ property #NEWLINE# def target_types( self ) : #NEWLINE# #INDENT# return { Fred } #NEWLINE# #UNINDENT# def macro( self , parse_context ) : #NEWLINE# #INDENT# return FredMacro ( parse_context ) #NEWLINE# #UNINDENT# #UNINDENT# factory = FredFactory ( ) #NEWLINE# self . _register_aliases ( targets = { #NEWLINE# #INDENT# 'fred' : factory , #NEWLINE# #UNINDENT# } ) #NEWLINE# aliases = self . build_configuration . registered_aliases ( ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , aliases . target_types ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , aliases . objects ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , aliases . context_aware_object_factories ) #NEWLINE# self . assertEqual ( dict ( fred = factory ) , aliases . target_macro_factories ) #NEWLINE# with self . _create_mock_build_file ( 'fred' ) as build_file : #NEWLINE# #INDENT# parse_state = self . build_configuration . initialize_parse_state ( build_file ) #NEWLINE# self . assertEqual ( 0 , len ( parse_state . registered_addressable_instances ) ) #NEWLINE# self . assertEqual ( 1 , len ( parse_state . parse_globals ) ) #NEWLINE# target_call_proxy = parse_state . parse_globals [ 'fred' ] #NEWLINE# target_call_proxy ( name = 'jake' ) #NEWLINE# self . assertEqual ( 1 , len ( parse_state . registered_addressable_instances ) ) #NEWLINE# ( name , target_proxy ) = parse_state . registered_addressable_instances . pop ( ) #NEWLINE# self . assertEqual ( 'frog' , self . addressed_name ) #NEWLINE# self . assertEqual ( Fred , target_proxy . addressed_type ) #NEWLINE# self . assertEqual ( [ 'jake' ] , target_proxy . dependency_specs )