def test_micro_aggregation(self): report1 = { 'avg': AverageMetric(3, 4), 'sum': SumMetric(3), 'fixed': FixedMetric(4), 'global_avg': GlobalAverageMetric(3, 4), } report2 = { 'avg': AverageMetric(1, 3), 'sum': SumMetric(4), 'fixed': FixedMetric(4), 'global_avg': GlobalAverageMetric(1, 3), } agg = aggregate_named_reports({'a': report1, 'b': report2}, micro_average=True) assert agg['avg'] == 4.0 / 7 assert agg['sum'] == 7 assert agg['fixed'] == 4 assert agg['global_avg'] in (report1['global_avg'], report2['global_avg']) # task level metrics assert agg['a/avg'] == 3.0 / 4 assert agg['a/sum'] == 3 assert agg['a/fixed'] == 4 assert 'a/global_avg' not in agg assert agg['b/avg'] == 1.0 / 3 assert agg['b/sum'] == 4 assert agg['b/fixed'] == 4 assert 'b/global_avg' not in agg
def test_unnamed_aggregation(self): report1 = { 'avg': AverageMetric(3, 4), 'sum': SumMetric(3), 'fixed': FixedMetric(4), 'global_avg': GlobalAverageMetric(3, 4), } report2 = { 'avg': AverageMetric(1, 3), 'sum': SumMetric(4), 'fixed': FixedMetric(4), 'global_avg': GlobalAverageMetric(1, 3), } agg = aggregate_unnamed_reports([report1, report2]) assert agg['avg'] == 4.0 / 7 assert agg['sum'] == 7 assert agg['fixed'] == 4 assert agg['global_avg'] == 4.0 / 7
def test_fixedmetric(self): assert (FixedMetric(3) + FixedMetric(3)).value() == 3 with self.assertRaises(ValueError): _ = FixedMetric(3) + FixedMetric(4)