<s> import os <EOL> import sys <EOL> import unittest <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> from response_router import ResponseRouter <EOL> class TestResponseRouter ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . router = ResponseRouter ( ) <EOL> self . router . append_read_rule ( "<STR_LIT>" , lambda x , y , z : "<STR_LIT:1>" ) <EOL> self . router . append_read_rule ( "<STR_LIT>" , lambda x , y , z : "<STR_LIT:2>" ) <EOL> self . router . append_read_rule ( "<STR_LIT>" , lambda x , y , z : "<STR_LIT:3>" ) <EOL> self . write_action_one = lambda x , y , z , data : "<STR_LIT>" % data <EOL> self . write_action_two = lambda x , y , z , data : "<STR_LIT>" % data <EOL> self . write_action_three = lambda x , y , z , data : "<STR_LIT>" % data <EOL> self . router . append_write_rule ( "<STR_LIT>" , self . write_action_one ) <EOL> self . router . append_write_rule ( "<STR_LIT>" , self . write_action_two ) <EOL> self . router . append_write_rule ( "<STR_LIT>" , self . write_action_three ) <EOL> def test_initialize_read ( self ) : <EOL> read_buffer = self . router . initialize_read ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( read_buffer . data , "<STR_LIT:1>" ) <EOL> read_buffer = self . router . initialize_read ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( read_buffer . data , "<STR_LIT:2>" ) <EOL> read_buffer = self . router . initialize_read ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( read_buffer . data , "<STR_LIT:3>" ) <EOL> read_buffer = self . router . initialize_read ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( read_buffer . data , "<STR_LIT:3>" ) <EOL> def test_initialize_read_for_no_action ( self ) : <EOL> read_buffer = self . router . initialize_read ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( read_buffer , None ) <EOL> def test_initialize_write ( self ) : <EOL> write_action = self . router . initialize_write ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( write_action ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" ) , "<STR_LIT>" ) <EOL> write_action = self . router . initialize_write ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( write_action ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" ) , "<STR_LIT>" ) <EOL> write_action = self . router . initialize_write ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( write_action ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" ) , "<STR_LIT>" ) <EOL> def test_initialize_write_for_no_action ( self ) : <EOL> write_action = self . router . initialize_write ( "<STR_LIT>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) <EOL> self . assertEqual ( write_action , None ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
