'Test correct grouping of events into periods'

def testExtend(self):

    ef = S3TimeSeriesEventFrame(tp_datetime(2012, 1, 1), tp_datetime(2012, 12, 15), slots='3    months')
    ef.extend(self.events)
    expected = [((2012, 1, 1), (2012, 4, 1), [8], [1, 2, 4], [10, 5, 117]), ((2012, 4, 1), (2012, 7, 1), [8], [1, 2, 3, 4, 5], [20, 8, 150]), ((2012, 7, 1), (2012, 10, 1), [8, 2, 4], [1, 3, 5, 6], [13, 8, 176]), ((2012, 10, 1), (2012, 12, 15), [8, 2, 4, 5], [1, 3, 6, 7], [20, 9, 211])]
    assertEqual = self.assertEqual
    for (i, period) in enumerate(ef):
        (start, end, previous, current, expected_result) = expected[i]
        assertEqual(period.start, tp_datetime(*start))
        assertEqual(period.end, tp_datetime(*end))
        event_ids = period.cevents.keys()
        assertEqual(set(event_ids), set(current))
        event_ids = period.pevents.keys()
        assertEqual(set(event_ids), set(previous))
        result = period.aggregate([S3TimeSeriesFact('sum', 'test'), S3TimeSeriesFact('max', 'test'), S3TimeSeriesFact('cumulate', None, slope='test', interval='months')])
        assertEqual(result, expected_result)
