<s> """<STR_LIT>""" <EOL> import unittest <EOL> import louie <EOL> try : <EOL> import qt <EOL> if not hasattr ( qt . qApp , '<STR_LIT>' ) : <EOL> _app = qt . QApplication ( [ ] ) <EOL> _app . for_testing = True <EOL> qt . qApp = _app <EOL> except ImportError : <EOL> qt = None <EOL> class ReceiverBase ( object ) : <EOL> def __init__ ( self ) : <EOL> self . args = [ ] <EOL> self . live = True <EOL> def __call__ ( self , arg ) : <EOL> self . args . append ( arg ) <EOL> class Receiver1 ( ReceiverBase ) : <EOL> pass <EOL> class Receiver2 ( ReceiverBase ) : <EOL> pass <EOL> class Plugin1 ( louie . Plugin ) : <EOL> def is_live ( self , receiver ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( receiver , ReceiverBase ) : <EOL> return receiver . live <EOL> return True <EOL> class Plugin2 ( louie . Plugin ) : <EOL> def is_live ( self , receiver ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( receiver , Receiver2 ) : <EOL> return False <EOL> return True <EOL> def test_only_one_instance ( ) : <EOL> louie . reset ( ) <EOL> plugin1a = Plugin1 ( ) <EOL> plugin1b = Plugin1 ( ) <EOL> louie . install_plugin ( plugin1a ) <EOL> try : <EOL> louie . install_plugin ( plugin1b ) <EOL> except louie . error . PluginTypeError : <EOL> pass <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def test_is_live ( ) : <EOL> louie . reset ( ) <EOL> receiver1a = Receiver1 ( ) <EOL> receiver1b = Receiver1 ( ) <EOL> receiver2a = Receiver2 ( ) <EOL> receiver2b = Receiver2 ( ) <EOL> louie . connect ( receiver1a , '<STR_LIT>' ) <EOL> louie . connect ( receiver1b , '<STR_LIT>' ) <EOL> louie . connect ( receiver2a , '<STR_LIT>' ) <EOL> louie . connect ( receiver2b , '<STR_LIT>' ) <EOL> louie . send ( '<STR_LIT>' , arg = '<STR_LIT:foo>' ) <EOL> assert receiver1a . args == [ '<STR_LIT:foo>' ] <EOL> assert receiver1b . args == [ '<STR_LIT:foo>' ] <EOL> assert receiver2a . args == [ '<STR_LIT:foo>' ] <EOL> assert receiver2b . args == [ '<STR_LIT:foo>' ] <EOL> plugin1 = Plugin1 ( ) <EOL> louie . install_plugin ( plugin1 ) <EOL> receiver1a . live = False <EOL> receiver2b . live = False <EOL> louie . send ( '<STR_LIT>' , arg = '<STR_LIT:bar>' ) <EOL> assert receiver1a . args == [ '<STR_LIT:foo>' ] <EOL> assert receiver1b . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] <EOL> assert receiver2a . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] <EOL> assert receiver2b . args == [ '<STR_LIT:foo>' ] <EOL> plugin2 = Plugin2 ( ) <EOL> louie . remove_plugin ( plugin1 ) <EOL> louie . install_plugin ( plugin2 ) <EOL> louie . send ( '<STR_LIT>' , arg = '<STR_LIT>' ) <EOL> assert receiver1a . args == [ '<STR_LIT:foo>' , '<STR_LIT>' ] <EOL> assert receiver1b . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ] <EOL> assert receiver2a . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] <EOL> assert receiver2b . args == [ '<STR_LIT:foo>' ] <EOL> louie . install_plugin ( plugin1 ) <EOL> louie . send ( '<STR_LIT>' , arg = '<STR_LIT>' ) <EOL> assert receiver1a . args == [ '<STR_LIT:foo>' , '<STR_LIT>' ] <EOL> assert receiver1b . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> assert receiver2a . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] <EOL> assert receiver2b . args == [ '<STR_LIT:foo>' ] <EOL> if qt is not None : <EOL> def test_qt_plugin ( ) : <EOL> louie . reset ( ) <EOL> class Receiver ( qt . QWidget ) : <EOL> def __init__ ( self ) : <EOL> qt . QObject . __init__ ( self ) <EOL> self . args = [ ] <EOL> def receive ( self , arg ) : <EOL> self . args . append ( arg ) <EOL> receiver1 = Receiver ( ) <EOL> receiver2 = Receiver ( ) <EOL> louie . connect ( receiver1 . receive , '<STR_LIT>' ) <EOL> louie . connect ( receiver2 . receive , '<STR_LIT>' ) <EOL> receiver2 . close ( True ) <EOL> louie . send ( '<STR_LIT>' , arg = '<STR_LIT:foo>' ) <EOL> assert receiver1 . args == [ '<STR_LIT:foo>' ] <EOL> assert receiver2 . args == [ '<STR_LIT:foo>' ] <EOL> plugin = louie . QtWidgetPlugin ( ) <EOL> louie . install_plugin ( plugin ) <EOL> louie . send ( '<STR_LIT>' , arg = '<STR_LIT:bar>' ) <EOL> assert receiver1 . args == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] <EOL> assert receiver2 . args == [ '<STR_LIT:foo>' ] </s>
