#NEWLINE# def test_dynamically_added_service_offer( self ) : #NEWLINE# #INDENT# ' dynamically added service offer ' #NEWLINE# from envisage.core_plugin import CorePlugin #NEWLINE# class IMyService ( Interface ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# class PluginA ( Plugin ) : #NEWLINE# #INDENT# id = 'A' #NEWLINE# service_offers = List ( contributes_to = 'envisage.service_offers' ) #NEWLINE# def _service_offers_default( self ) : #NEWLINE# #INDENT# ' Trait initializer. ' #NEWLINE# service_offers = [ ServiceOffer ( protocol = IMyService , factory = self . _my_service_factory ) ] #NEWLINE# return service_offers #NEWLINE# #UNINDENT# def _my_service_factory( self , **properties ) : #NEWLINE# #INDENT# ' Service factory. ' #NEWLINE# return 42 #NEWLINE# #UNINDENT# #UNINDENT# core = CorePlugin ( ) #NEWLINE# a = PluginA ( ) #NEWLINE# application = TestApplication ( plugins = [ core ] ) #NEWLINE# application . start ( ) #NEWLINE# service = application . get_service ( IMyService ) #NEWLINE# self . assertIsNone ( service ) #NEWLINE# extensions = application . get_extensions ( 'envisage.service_offers' ) #NEWLINE# self . assertEqual ( 0 , len ( extensions ) ) #NEWLINE# application . add_plugin ( a ) #NEWLINE# extensions = application . get_extensions ( 'envisage.service_offers' ) #NEWLINE# self . assertEqual ( 1 , len ( a ) ) #NEWLINE# service = application . get_service ( IMyService ) #NEWLINE# self . assertEqual ( 42 , service ) #NEWLINE# return