#NEWLINE# def test_message_buffer( ) : #NEWLINE# #INDENT# subject_template = Mock ( ) #NEWLINE# body_template = Mock ( ) #NEWLINE# buf = MessageBuffer ( subject_template , body_template ) #NEWLINE# msg1 = UniqueMessage ( 'test' , 'test' , 'test' , 'message1' , 'test.py' , 1 , 'exception text' , 'app' ) #NEWLINE# msg2 = UniqueMessage ( 'test' , 'test' , 'test' , 'message2' , 'test.py' , 1 , 'exception text' , 'app' ) #NEWLINE# buf . add ( msg1 , 'host1' ) #NEWLINE# buf . add ( msg1 , 'host1' ) #NEWLINE# buf . add ( msg1 , 'host2' ) #NEWLINE# buf . add ( msg2 , 'host2' ) #NEWLINE# eq_ ( 4 , buf . total ) #NEWLINE# eq_ ( 2 , buf . total_unique ) #NEWLINE# eq_ ( { 'app' } , buf . kinds ) #NEWLINE# eq_ ( 2 , len ( buf . sorted_counts ) ) #NEWLINE# eq_ ( 'message1' , buf . sorted_counts [ 0 ] [ 0 ] . message ) #NEWLINE# eq_ ( 3 , buf . sorted_counts [ 0 ] [ 1 ] . total ) #NEWLINE# eq_ ( 3 , buf . total_matching ( ( lambda m : ( m . message == 'message1' ) ) ) ) #NEWLINE# subject_template . render . return_value = 'subj' #NEWLINE# body_template . render . return_value = 'body' #NEWLINE# ( subj , body , uniq_messages ) = buf . flush ( ) #NEWLINE# eq_ ( 'subj' , subj ) #NEWLINE# eq_ ( 'body' , body ) #NEWLINE# eq_ ( 2 , len ( uniq_messages ) ) #NEWLINE# eq_ ( 1 , subject_template . render . call_count ) #NEWLINE# eq_ ( 4 , body_template . render . call_args [ 0 ] [ 0 ] [ 'total' ] ) #NEWLINE# eq_ ( 2 , body_template . render . call_args [ 0 ] [ 0 ] [ 'total_unique' ] ) #NEWLINE# eq_ ( 2 , len ( body_template . render . call_args [ 0 ] [ 0 ] [ 'sorted_counts' ] ) ) #NEWLINE# eq_ ( 'message1' , body_template . render . call_args [ 0 ] [ 0 ] [ 'sorted_counts' ] [ 0 ] [ 0 ] . message ) #NEWLINE# eq_ ( { 'app' } , body_template . render . call_args [ 0 ] [ 0 ] [ 'kinds' ] )