'Test aggregation: sum'

def testAggregateSum(self):

    period = self.period
    assertEqual = self.assertEqual
    totals = period.aggregate(S3TimeSeriesFact('sum', 'base'))
    expected_rows = {'A': [180], 'B': [370], 'C': [810]}
    rows = period.rows
    assertEqual(set(rows.keys()), set(expected_rows.keys()))
    for (k, v) in rows.items():
        assertEqual(v, expected_rows.get(k), msg=('Row    %s:    %s    !=    %s' % (k, v, expected_rows.get(k))))
    expected_cols = {1: [430], 2: [290], 3: [640]}
    cols = period.cols
    assertEqual(set(cols.keys()), set(expected_cols.keys()))
    for (k, v) in cols.items():
        assertEqual(v, expected_cols.get(k), msg=('Column    %s:    %s    !=    %s' % (k, v, expected_cols.get(k))))
    expected_matrix = {('A', 1): [80], ('A', 2): [100], ('B', 2): [130], ('B', 3): [240], ('C', 1): [350], ('C', 2): [60], ('C', 3): [400]}
    matrix = period.matrix
    assertEqual(set(matrix.keys()), set(expected_matrix.keys()))
    for (k, v) in matrix.items():
        assertEqual(v, expected_matrix.get(k), msg=('Cell    %s:    %s    !=    %s' % (k, v, expected_matrix.get(k))))
    expected_totals = [1360]
    assertEqual(period.totals, expected_totals)
    assertEqual(totals, expected_totals)
