def test_metrics_stats_frame_can_add_values():
    events_transport_batch_size = [10, 2, 54]
    events_looper_run_time_spent = [0.1, 3.4, 0.01, 0.5]

    events = []
    for v in events_transport_batch_size:
        events.append((MetricsName.TRANSPORT_BATCH_SIZE, v))
    for v in events_looper_run_time_spent:
        events.append((MetricsName.LOOPER_RUN_TIME_SPENT, v))
    shuffle(events)

    frame = MetricsStatsFrame()
    for id, value in events:
        frame.add(id, value)

    assert frame.get(MetricsName.TRANSPORT_BATCH_SIZE) == ValueAccumulator(events_transport_batch_size)
    assert frame.get(MetricsName.LOOPER_RUN_TIME_SPENT) == ValueAccumulator(events_looper_run_time_spent)
    assert frame.get(MetricsName.BACKUP_THREE_PC_BATCH_SIZE) == ValueAccumulator()
def test_metrics_stats_frame_eq_has_value_semantics():
    a = MetricsStatsFrame()
    b = MetricsStatsFrame()
    assert a == b

    a.add(MetricsName.LOOPER_RUN_TIME_SPENT, 2.0)
    assert a != b

    b.add(MetricsName.LOOPER_RUN_TIME_SPENT, 2.0)
    assert a == b

    a.add(MetricsName.BACKUP_THREE_PC_BATCH_SIZE, 1)
    b.add(MetricsName.TRANSPORT_BATCH_SIZE, 2)
    assert a != b
def _metrics_stats_frame(events):
    frame = MetricsStatsFrame()
    for ev in events:
        frame.add(ev.name, ev.value)
    return frame