예제 #1
0
def test_inference_report_run_iterations():
    model = MockModel()

    report = InferenceReport(model.infer_callable, 1, n_iterations=30)
    results = report.run(print_report=False)
    assert isinstance(results, dict)
    for expected in EXPECTED_METRICS:
        assert expected in results.keys()
예제 #2
0
def test_plot_savefig(plt, plt1):
    model = MockModel()

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             drop_stats=[])
    results = report.run(print_report=False)
    report.plot(show=True, save_location="test.jpg")
예제 #3
0
def test_plot_show(plt):
    model = MockModel()

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             drop_stats=[])
    results = report.run(print_report=False)
    report.plot(show=True)
예제 #4
0
def test_plot_report_not_run_raises_value_error():
    model = MockModel()

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             drop_stats=[])
    with pytest.raises(ValueError):
        report.plot(show=False)
예제 #5
0
def test_report_drop_stats_empty():
    model = MockModel()

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             drop_stats=[])
    results = report.run(print_report=False)
    report.report(results)
    assert list(results.keys()) == EXPECTED_METRICS
예제 #6
0
def test_report_drop_stats_removes_key_from_dict():
    model = MockModel(delay=0.48)

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             drop_stats=["Took"])
    results = report.run(print_report=False)
    report.report(results)
    assert "Took" not in results.keys()
예제 #7
0
def test_plot_matplotlib_not_installed():
    model = MockModel()

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             drop_stats=[])
    results = report.run(print_report=False)
    with patch.dict(sys.modules, {"matplotlib": None}):
        with pytest.raises(MatplotlibNotInstalledError):
            report.plot()
예제 #8
0
def test_run_iterations_failure_point_does_not_trigger_failure():
    model = MockModel(delay=0.48)

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             infer_failure_point=0.50)
    results = report.run(print_report=False)
    assert results["Fail"] == 0
    assert results["Success"] == 1
    assert report.n_iterations == 1
예제 #9
0
def test_init_model_name_given():
    model = MockModel()
    name = "my_test_model"
    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=1,
                             model_name=name)
    assert report.model_name == name
예제 #10
0
def test_two_intervals_given_defaults_to_seconds():
    model = MockModel()

    report = InferenceReport(model.infer_callable,
                             1,
                             n_iterations=10,
                             n_seconds=1)
    assert report.n_iterations == None
    assert report.n_seconds == 1
예제 #11
0
def test_init_seconds():
    model = MockModel()
    report = InferenceReport(
        model.infer_callable,
        1,
        n_seconds=10,
    )
    assert report.n_iterations == None
    assert report.n_seconds == 10
예제 #12
0
def test_assert_longer_report_takes_more_time_than_shorter_report():
    model = MockModel()

    report = InferenceReport(model.infer_callable, 1, n_seconds=1)
    report1 = InferenceReport(model.infer_callable, 1, n_seconds=2)

    results = report.run(print_report=False)
    results1 = report1.run(print_report=False)

    assert results1["Took"] > results["Took"]
예제 #13
0
import time

from pyinfer import InferenceReport


class DummyModel:
    def infer(self, input):
        time.sleep(0.1)
        return input * pow(input, 2)


dummy = DummyModel()
report = InferenceReport(
    model=dummy.infer,
    inputs=7,
    n_iterations=2,
    infer_failure_point=2,
)
report.run()
예제 #14
0
def test_init_no_interval_given():
    model = MockModel()
    with pytest.raises(MeasurementIntervalNotSetError):
        report = InferenceReport(model.infer_callable, 1)
예제 #15
0
def test_init_model_not_callable():
    model = MockModel()
    with pytest.raises(ModelIsNotCallableError):
        report = InferenceReport(model, 1, n_iterations=1)
예제 #16
0
def test_run_print_report_param_true(ir):
    model = MockModel(delay=0.48)

    report = InferenceReport(model.infer_callable, 1, n_iterations=1)
    results = report.run()