def test_good_parsing(): n, fx, measures = aggregators.parse_expr("sum(foo)") assert n == 'sum' assert fx == aggregators.ag_sum assert measures == ['foo'] n, fx, measures = aggregators.parse_expr("MEAN(foo, bar)") assert n == 'mean' assert fx == aggregators.ag_mean assert measures == ['foo', 'bar'] n, fx, measures = aggregators.parse_expr('join(foo, bar)') assert n == 'join' assert fx == aggregators.ag_join assert measures == ['foo', 'bar'] n, fx, measures = aggregators.parse_expr('ratio(foo, bar)') assert n == 'ratio' assert fx == aggregators.ag_ratio assert measures == ['foo', 'bar'] n, fx, measures = aggregators.parse_expr('max(foo, bar)') assert fx == aggregators.ag_max assert measures == ['foo', 'bar'] n, fx, measures = aggregators.parse_expr('min(foo, bar)') assert fx == aggregators.ag_min assert measures == ['foo', 'bar'] n, fx, measures = aggregators.parse_expr('sum_imputed(foo)') assert n == 'sum_imputed' assert fx == aggregators.ag_sum_imputed assert measures == ['foo'] n, fx, measures = aggregators.parse_expr('mean_imputed(foo)') assert n == 'mean_imputed' assert fx == aggregators.ag_mean_imputed assert measures == ['foo'] n, fx, measures = aggregators.parse_expr('imputed_fraction(foo)') assert n == 'imputed_fraction' assert fx == aggregators.ag_imputed_fraction assert measures == ['foo']
def test_good_parsing(): n, fx, measures = aggregators.parse_expr("sum(foo)") assert n == 'sum' assert fx == aggregators.ag_sum assert measures == ['foo'] n, fx, measures = aggregators.parse_expr("MEAN(foo, bar)") assert n == 'mean' assert fx == aggregators.ag_mean assert measures == ['foo', 'bar'] n, fx, measures = aggregators.parse_expr('join(foo, bar)') assert n == 'join' assert fx == aggregators.ag_join assert measures == ['foo', 'bar']
def __init__(self, name, aggregation_expr): self.name = name self.aggregation_expr = aggregation_expr try: fname, fx, to_use = aggregators.parse_expr(aggregation_expr) self.agg_fx = fx self.to_use = to_use except aggregators.AggregatorError as exc: raise DirectiveError(str(exc)) super(Measure, self).__init__()
def test_bad_parses(): with pytest.raises(aggregators.AggregatorError): aggregators.parse_expr("dkjaskdj") with pytest.raises(aggregators.AggregatorError): aggregators.parse_expr("bogus(foo)")