Example #1
0
def test_add_metric_obj():
    check = Check()
    check.add_metric_obj(Metric('Memory', 4500000, 'bytes', '4M:', '6M:'))
    check.add_metric_obj(Metric('CPU', 7, '%', '20:', '50:'))
    assert len(check.metrics) == 2
    for metric in check.metrics:
        assert isinstance(metric, Metric)
Example #2
0
def test_final_with_obj(capsys):
    check = Check()
    check.add_metric_obj(
        Metric('Memory', 4500000, 'B', '4M:', '6M:', convert_metric=True))
    check.add_metric_obj(Metric('CPU', 7, '%', '20:', '50:'))
    with pytest.raises(SystemExit) as e:
        check.final()
    assert e.value.code == 2
    assert capsys.readouterr().out == (
        'METRIC CRITICAL - Memory is 4.29MB, CPU is 7% | Memory=4500000B;4M:;6M: CPU=7%;20:;50:{0}'
        .format(os.linesep))