<s> from unittest import TestCase <EOL> from spockbot . plugins . helpers . chat import ChatCore , ChatPlugin <EOL> class DataDict ( dict ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( DataDict , self ) . __init__ ( ** kwargs ) <EOL> self . __dict__ . update ( kwargs ) <EOL> class PluginLoaderMock ( object ) : <EOL> events = { } <EOL> def provides ( self , ident , obj ) : <EOL> self . provides_ident = ident <EOL> self . provides_obj = obj <EOL> def requires ( self , requirement ) : <EOL> if requirement == '<STR_LIT>' : <EOL> return NetMock ( ) <EOL> if requirement == '<STR_LIT>' : <EOL> return EventMock ( ) <EOL> else : <EOL> raise AssertionError ( '<STR_LIT>' % requirement ) <EOL> def reg_event_handler ( self , event , handler ) : <EOL> self . events [ event ] = [ ] if event not in self . events else self . events [ <EOL> event ] <EOL> self . events [ event ] . append ( handler ) <EOL> class NetMock ( object ) : <EOL> idents = [ ] <EOL> datas = [ ] <EOL> def push_packet ( self , ident , data ) : <EOL> data_dict = DataDict ( ** data ) <EOL> self . idents . append ( ident ) <EOL> self . datas . append ( data_dict ) <EOL> class EventMock ( object ) : <EOL> def emit ( self , name , data ) : <EOL> return True <EOL> class ChatPluginTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> ploader = PluginLoaderMock ( ) <EOL> self . plug = ChatPlugin ( ploader , { } ) <EOL> assert ploader . provides_ident == '<STR_LIT>' <EOL> assert isinstance ( ploader . provides_obj , ChatCore ) <EOL> def test_chat ( self ) : <EOL> self . plug . chatcore . chat ( '<STR_LIT>' ) <EOL> self . assertEqual ( NetMock . datas [ - <NUM_LIT:1> ] . message , '<STR_LIT>' ) <EOL> def test_whisper ( self ) : <EOL> self . plug . chatcore . whisper ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( NetMock . datas [ - <NUM_LIT:1> ] . message , '<STR_LIT>' ) </s>
