#NEWLINE# def testGrouping( self ) : #NEWLINE# #INDENT# ' Test grouping of period events ' #NEWLINE# period = self . period #NEWLINE# period . group ( ) #NEWLINE# assertTrue = self . assertTrue #NEWLINE# assertEqual = self . assertEqual #NEWLINE# expected_rows = { #NEWLINE# #INDENT# 'A' : ( ( 1 , 2 , 7 , 8 ) , ( ) ) , #NEWLINE# 'B' : ( ( 3 , 4 , 9 , 10 ) , ( ) ) , #NEWLINE# 'C' : ( ( 5 , 6 , 11 , 12 ) , ( ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# rows = period . _rows #NEWLINE# assertEqual ( set ( rows . keys ( ) ) , set ( expected_rows . keys ( ) ) ) #NEWLINE# for ( k , v ) in rows . items ( ) : #NEWLINE# #INDENT# expected_current = set ( expected_rows . get ( k ) [ 0 ] ) #NEWLINE# assertEqual ( v [ 0 ] , expected_current , msg = ( 'Row %s current events: %s != %s' % ( k , v [ 0 ] , expected_current ) ) ) #NEWLINE# expected_previous = set ( expected_rows . get ( k ) [ 1 ] ) #NEWLINE# assertEqual ( v [ 1 ] , expected_previous , msg = ( 'Row %s previous events: %s != %s' % ( k , v [ 1 ] , expected_previous ) ) ) #NEWLINE# #UNINDENT# expected_cols = { #NEWLINE# #INDENT# 1 : ( ( 1 , 5 , 7 , 11 ) , ( ) ) , #NEWLINE# 2 : ( ( 2 , 3 , 6 , 8 , 9 ) , ( ) ) , #NEWLINE# 3 : ( ( 4 , 10 , 12 ) , ( ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# cols = period . _cols #NEWLINE# assertEqual ( set ( cols . keys ( ) ) , set ( expected_cols . keys ( ) ) ) #NEWLINE# for ( k , v ) in cols . items ( ) : #NEWLINE# #INDENT# expected_current = set ( expected_cols . get ( k ) [ 0 ] ) #NEWLINE# assertEqual ( v [ 0 ] , expected_current , msg = ( 'Row %s current events: %s != %s' % ( k , v [ 0 ] , expected_current ) ) ) #NEWLINE# expected_previous = set ( expected_cols . get ( k ) [ 1 ] ) #NEWLINE# assertEqual ( v [ 1 ] , expected_previous , msg = ( 'Row %s previous events: %s != %s' % ( k , v [ 1 ] , expected_previous ) ) ) #NEWLINE# #UNINDENT# expected_matrix = { #NEWLINE# #INDENT# ( 'A' , 1 ) : ( ( 1 , 7 ) , ( ) ) , #NEWLINE# ( 'A' , 2 ) : ( ( 2 , 8 ) , ( ) ) , #NEWLINE# ( 'B' , 2 ) : ( ( 3 , 9 ) , ( ) ) , #NEWLINE# ( 'B' , 3 ) : ( ( 4 , 10 ) , ( ) ) , #NEWLINE# ( 'C' , 1 ) : ( ( 5 , 11 ) , ( ) ) , #NEWLINE# ( 'C' , 2 ) : ( ( 6 , ) , ( ) ) , #NEWLINE# ( 'C' , 3 ) : ( ( 12 , ) , ( ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# matrix = period . _matrix #NEWLINE# assertEqual ( set ( matrix . keys ( ) ) , set ( expected_matrix . keys ( ) ) ) #NEWLINE# for ( k , v ) in matrix . items ( ) : #NEWLINE# #INDENT# expected_current = set ( expected_matrix . get ( k ) [ 0 ] ) #NEWLINE# assertEqual ( v [ 0 ] , expected_current , msg = ( 'Row %s current events: %s != %s' % ( k , v [ 0 ] , expected_current ) ) ) #NEWLINE# expected_previous = set ( expected_matrix . get ( k ) [ 1 ] ) #NEWLINE# assertEqual ( v [ 1 ] , expected_previous , msg = ( 'Row %s previous events: %s != %s' % ( k , v [ 1 ] , expected_previous ) ) )