'Test parsing of fact expressions'

def testFactExpressionParsing(self):

    parse = S3TimeSeriesFact.parse
    expressions = (('id', ((None, 'count', 'id', None, None),)), ('count(id)', ((None, 'count', 'id', None, None),)), ('cumulate(value,delta,3weeks)', ((None, 'cumulate', 'value', 'delta', '3weeks'),)), ('cumulate(delta,3weeks)', ((None, 'cumulate', None, 'delta', '3weeks'),)), ('cumulate(value)', ((None, 'cumulate', 'value', None, None),)), ('sum(~.value)', ((None, 'sum', '~.value', None, None),)), (('Number    of    Records', 'count(id)'), (('Number    of    Records', 'count', 'id', None, None),)), (['count(id)', 'sum(value)'], ((None, 'count', 'id', None, None), (None, 'sum', 'value', None, None))), (['count(id)', ('Example', 'min(example)')], ((None, 'count', 'id', None, None), ('Example', 'min', 'example', None, None))), ('min(other),avg(other)', ((None, 'min', 'other', None, None), (None, 'avg', 'other', None, None))), (('Test', 'min(other),avg(other)'), (('Test', 'min', 'other', None, None), ('Test', 'avg', 'other', None, None))), (['count(id)', 'sum(value),avg(other)'], ((None, 'count', 'id', None, None), (None, 'sum', 'value', None, None), (None, 'avg', 'other', None, None))), ([], None), (['count(id)', 'invalid(value)'], None), ('count(id),count()', None))
    assertRaises = self.assertRaises
    assertEqual = self.assertEqual
    i = 0
    for (i, (expression, expected)) in enumerate(expressions):
        if (expected is None):
            with assertRaises(SyntaxError):
                facts = parse(expression)
        else:
            facts = parse(expression)
            assertEqual(len(facts), len(expected))
            for (j, fact) in enumerate(facts):
                (label, method, base, slope, interval) = expected[j]
                assertEqual(fact.label, label, msg=('Expression    %s/%s    -    incorrect    label:    %s    !=    %s' % (i, j, fact.label, label)))
                assertEqual(fact.method, method, msg=('Expression    %s/%s    -    incorrect    method:    %s    !=    %s' % (i, j, fact.method, method)))
                assertEqual(fact.base, base, msg=('Expression    %s/%s    -    incorrect    base:    %s    !=    %s' % (i, j, fact.base, base)))
                assertEqual(fact.slope, slope, msg=('Expression    %s/%s    -    incorrect    slope:    %s    !=    %s' % (i, j, fact.slope, slope)))
                assertEqual(fact.interval, interval, msg=('Expression    %s/%s    -    incorrect    interval:    %s    !=    %s' % (i, j, fact.interval, interval)))
