#NEWLINE# def test_custom_sharing_key( container_factory ) : #NEWLINE# #INDENT# class CustomSharedExtension ( CallCollectorMixin , SharedExtension ) : #NEWLINE# #INDENT# def __init__( self , arg ) : #NEWLINE# #INDENT# self . arg = arg #NEWLINE# #UNINDENT# @ property #NEWLINE# def sharing_key( self ) : #NEWLINE# #INDENT# return ( type ( self ) , self . arg ) #NEWLINE# #UNINDENT# #UNINDENT# class SimpleDependencyProvider ( CallCollectorMixin , DependencyProvider ) : #NEWLINE# #INDENT# ext_a = CustomSharedExtension ( 'a' ) #NEWLINE# ext_b = CustomSharedExtension ( 'b' ) #NEWLINE# #UNINDENT# class Service ( object ) : #NEWLINE# #INDENT# name = 'service' #NEWLINE# dep_1 = SimpleDependencyProvider ( ) #NEWLINE# dep_2 = SimpleDependencyProvider ( ) #NEWLINE# #UNINDENT# container = container_factory ( Service , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# container . start ( ) #NEWLINE# assert ( len ( dep_2 . extensions ) == 4 ) #NEWLINE# calls = CallCollectorMixin . calls #NEWLINE# assert ( len ( calls [ SimpleDependencyProvider ] [ 'start' ] ) == 2 ) #NEWLINE# assert ( len ( calls [ CustomSharedExtension ] [ 'start' ] ) == 2 ) #NEWLINE# dep_1 = get_extension ( container , SimpleDependencyProvider , attr_name = 'dep_1' ) #NEWLINE# dep_2 = get_extension ( container , SimpleDependencyProvider , attr_name = 'dep_2' ) #NEWLINE# assert ( dep_1 . ext_a is not dep_2 . ext_b ) #NEWLINE# assert ( dep_1 . ext_a is dep_2 . ext_a ) #NEWLINE# assert ( dep_1 . ext_b is dep_2 . ext_b )