'Test grouping of period events'

def testGrouping(self):

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