Exemple #1
0
def test_metric_invert(retval):
    """Test metric invert computation."""

    from foreshadow.metrics import MetricWrapper

    def test(X):
        return retval

    metric_wrapper = MetricWrapper(test, 0, invert=True)
    assert (1 - retval) == metric_wrapper.calculate([1, 2, 3])
Exemple #2
0
def test_metric_default_return():
    """Test metric default return value when a function errors."""

    from foreshadow.metrics import MetricWrapper

    def test(X):
        raise Exception

    metric_wrapper = MetricWrapper(test, 0)
    assert 0 == metric_wrapper.calculate([1, 2, 3])
Exemple #3
0
def test_metric_last_call(metric_fn, arg, kwargs):
    """Test arbitrary function reroutes from call to last_call

    Args:
        metric_fn: arbitrary metric function
        arg: arg to metric call
        kwargs: any kwargs to metric call

    """
    from foreshadow.metrics import MetricWrapper

    metric_wrapper = MetricWrapper(metric_fn)
    _ = metric_wrapper.calculate(arg, **kwargs)
    assert metric_wrapper.last_call() == 1