<s> import unittest <EOL> from chalmers . event_dispatcher import EventDispatcher <EOL> from chalmers import config , errors <EOL> from os . path import join <EOL> import tempfile <EOL> import os <EOL> class TestEventDispatcher ( EventDispatcher ) : <EOL> @ property <EOL> def name ( self ) : <EOL> return '<STR_LIT:test>' <EOL> def dispatch_foo ( self , value ) : <EOL> self . foo = value <EOL> def dispatch_error ( self , value ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> class Test ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . root_config = join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> config . set_relative_dirs ( self . root_config ) <EOL> unittest . TestCase . setUp ( self ) <EOL> def test_init ( self ) : <EOL> dispatcher = TestEventDispatcher ( ) <EOL> self . assertFalse ( dispatcher . is_listening ) <EOL> def test_listen ( self ) : <EOL> d = TestEventDispatcher ( ) <EOL> if os . path . exists ( d . addr ) : <EOL> os . unlink ( d . addr ) <EOL> self . assertFalse ( d . is_listening ) <EOL> d . start_listener ( ) <EOL> self . assertTrue ( d . is_listening ) <EOL> if os . name != '<STR_LIT>' : <EOL> self . assertTrue ( os . path . exists ( d . addr ) ) <EOL> d . send ( '<STR_LIT:foo>' , <NUM_LIT:1> ) <EOL> d . send ( '<STR_LIT>' ) <EOL> d . _listener_thread . join ( ) <EOL> self . assertFalse ( d . is_listening ) <EOL> self . assertEqual ( d . foo , <NUM_LIT:1> ) <EOL> def test_exception ( self ) : <EOL> d = TestEventDispatcher ( ) <EOL> if os . path . exists ( d . addr ) : <EOL> os . unlink ( d . addr ) <EOL> self . assertFalse ( d . is_listening ) <EOL> d . start_listener ( ) <EOL> with self . assertRaises ( errors . ChalmersError ) : <EOL> d . send ( '<STR_LIT:error>' , <NUM_LIT:1> ) <EOL> self . assertTrue ( d . is_listening ) <EOL> d . send ( '<STR_LIT>' ) <EOL> d . _listener_thread . join ( ) <EOL> self . assertFalse ( d . is_listening ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
