<s> import unittest <EOL> import louie <EOL> from louie import dispatcher <EOL> def x ( a ) : <EOL> return a <EOL> class Dummy ( object ) : <EOL> pass <EOL> class Callable ( object ) : <EOL> def __call__ ( self , a ) : <EOL> return a <EOL> def a ( self , a ) : <EOL> return a <EOL> class TestDispatcher ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> louie . reset ( ) <EOL> def _isclean ( self ) : <EOL> """<STR_LIT>""" <EOL> assert len ( dispatcher . senders_back ) == <NUM_LIT:0> , dispatcher . senders_back <EOL> assert len ( dispatcher . connections ) == <NUM_LIT:0> , dispatcher . connections <EOL> assert len ( dispatcher . senders ) == <NUM_LIT:0> , dispatcher . senders <EOL> def test_Exact ( self ) : <EOL> a = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( x , signal , a ) <EOL> expected = [ ( x , a ) ] <EOL> result = louie . send ( '<STR_LIT>' , a , a = a ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> louie . disconnect ( x , signal , a ) <EOL> assert len ( list ( louie . get_all_receivers ( a , signal ) ) ) == <NUM_LIT:0> <EOL> self . _isclean ( ) <EOL> def test_AnonymousSend ( self ) : <EOL> a = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( x , signal ) <EOL> expected = [ ( x , a ) ] <EOL> result = louie . send ( signal , None , a = a ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> louie . disconnect ( x , signal ) <EOL> assert len ( list ( louie . get_all_receivers ( None , signal ) ) ) == <NUM_LIT:0> <EOL> self . _isclean ( ) <EOL> def test_AnyRegistration ( self ) : <EOL> a = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( x , signal , louie . Any ) <EOL> expected = [ ( x , a ) ] <EOL> result = louie . send ( '<STR_LIT>' , object ( ) , a = a ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> louie . disconnect ( x , signal , louie . Any ) <EOL> expected = [ ] <EOL> result = louie . send ( '<STR_LIT>' , object ( ) , a = a ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> assert len ( list ( louie . get_all_receivers ( louie . Any , signal ) ) ) == <NUM_LIT:0> <EOL> self . _isclean ( ) <EOL> def test_AllRegistration ( self ) : <EOL> a = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( x , louie . All , a ) <EOL> expected = [ ( x , a ) ] <EOL> result = louie . send ( '<STR_LIT>' , a , a = a ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> louie . disconnect ( x , louie . All , a ) <EOL> assert len ( list ( louie . get_all_receivers ( a , louie . All ) ) ) == <NUM_LIT:0> <EOL> self . _isclean ( ) <EOL> def test_GarbageCollected ( self ) : <EOL> a = Callable ( ) <EOL> b = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( a . a , signal , b ) <EOL> expected = [ ] <EOL> del a <EOL> result = louie . send ( '<STR_LIT>' , b , a = b ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> assert len ( list ( louie . get_all_receivers ( b , signal ) ) ) == <NUM_LIT:0> , ( <EOL> "<STR_LIT>" % ( louie . get_all_receivers ( b , signal ) , ) ) <EOL> self . _isclean ( ) <EOL> def test_GarbageCollectedObj ( self ) : <EOL> class x : <EOL> def __call__ ( self , a ) : <EOL> return a <EOL> a = Callable ( ) <EOL> b = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( a , signal , b ) <EOL> expected = [ ] <EOL> del a <EOL> result = louie . send ( '<STR_LIT>' , b , a = b ) <EOL> assert result == expected , ( <EOL> "<STR_LIT>" <EOL> % ( expected , result ) ) <EOL> assert len ( list ( louie . get_all_receivers ( b , signal ) ) ) == <NUM_LIT:0> , ( <EOL> "<STR_LIT>" % ( louie . get_all_receivers ( b , signal ) , ) ) <EOL> self . _isclean ( ) <EOL> def test_MultipleRegistration ( self ) : <EOL> a = Callable ( ) <EOL> b = Dummy ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( a , signal , b ) <EOL> louie . connect ( a , signal , b ) <EOL> louie . connect ( a , signal , b ) <EOL> louie . connect ( a , signal , b ) <EOL> louie . connect ( a , signal , b ) <EOL> louie . connect ( a , signal , b ) <EOL> result = louie . send ( '<STR_LIT>' , b , a = b ) <EOL> assert len ( result ) == <NUM_LIT:1> , result <EOL> assert len ( list ( louie . get_all_receivers ( b , signal ) ) ) == <NUM_LIT:1> , ( <EOL> "<STR_LIT>" % ( louie . get_all_receivers ( b , signal ) , ) ) <EOL> del a <EOL> del b <EOL> del result <EOL> self . _isclean ( ) <EOL> def test_robust ( self ) : <EOL> """<STR_LIT>""" <EOL> def fails ( ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> a = object ( ) <EOL> signal = '<STR_LIT>' <EOL> louie . connect ( fails , louie . All , a ) <EOL> result = louie . send_robust ( '<STR_LIT>' , a , a = a ) <EOL> err = result [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> assert isinstance ( err , ValueError ) <EOL> assert err . args == ( '<STR_LIT>' , ) </s>
