Example #1
0
def test_send_report_in_special_order_receive_right_pair(
        procfs_timeline, power_timeline):
    timedet = datetime.timedelta(250)
    sync = Sync(lambda x: isinstance(x, PowerReport),
                lambda x: isinstance(x, ProcfsReport), timedet)

    sum = 0

    r = power_timeline[0]
    sync.add_report(PowerReport.from_json(r))
    r = power_timeline[1]
    sync.add_report(PowerReport.from_json(r))

    for i in range(len(power_timeline) - 2):
        r = power_timeline[i + 2]
        sync.add_report(PowerReport.from_json(r))

        r = procfs_timeline[i]
        sync.add_report(ProcfsReport.from_json(r))

        r = sync.request()
        assert r is not None
        report1, report2 = r
        assert abs(report1.timestamp - report2.timestamp) <= timedet
        sum += 1

    r = procfs_timeline[-2]
    sync.add_report(ProcfsReport.from_json(r))

    r = procfs_timeline[-1]
    sync.add_report(ProcfsReport.from_json(r))

    assert sum == len(power_timeline) - 2
Example #2
0
def test_create_power_report_from_json_without_sensor_field_raise_BadInputData():
    json_input = gen_json_power_report(1)[0]
    del json_input['sensor']
    with pytest.raises(BadInputData):
        report = PowerReport.from_json(json_input)
Example #3
0
def test_create_power_report_from_json_with_str_timestamp_with_bad_format_raise_BadInputData():
    json_input = gen_json_power_report(1)[0]
    json_input['timestamp'] = '1970-09-01T090909.543'
    with pytest.raises(BadInputData):
        report = PowerReport.from_json(json_input)
Example #4
0
def test_create_power_report_from_json_with_datetime_timestamp_format_create_a_PowerReport():
    json_input = gen_json_power_report(1)[0]
    json_input['timestamp'] = datetime.strptime(json_input['timestamp'], "%Y-%m-%dT%H:%M:%S.%f")
    report = PowerReport.from_json(json_input)
    assert isinstance(report, PowerReport)
Example #5
0
def test_create_power_report_from_json_wit_str_timestamp_create_a_PowerReport():
    json_input = gen_json_power_report(1)[0]
    report = PowerReport.from_json(json_input)
    assert isinstance(report, PowerReport)
Example #6
0
def test_create_report_from_json_with_metadata():
    json_input = gen_json_power_report(1)[0]
    json_input["metadata"] = {}
    json_input["metadata"]["tag"] = 1
    report = PowerReport.from_json(json_input)
    assert report.metadata["tag"] == 1