@pytest.mark.parametrize("regres", [KNearestNeighborRegressor]) @pytest.mark.parametrize("mean", ["faulty", 42]) @pytest.mark.parametrize("dist", ["not_real", 27]) def test_metric_dict_error(regres, mean, dist, get_covmats, get_targets): with pytest.raises((TypeError, KeyError)): n_matrices, n_channels = 6, 3 targets = get_targets(n_matrices) covmats = get_covmats(n_matrices, n_channels) clf = regres(metric={"mean": mean, "distance": dist}) clf.fit(covmats, targets).predict(covmats) @pytest.mark.parametrize("regres", [KNearestNeighborRegressor]) @pytest.mark.parametrize("mean", get_means()) @pytest.mark.parametrize("dist", get_distances()) def test_metric_dist(regres, mean, dist, get_covmats, get_targets): n_matrices, n_channels = 4, 3 targets = get_targets(n_matrices) covmats = get_covmats(n_matrices, n_channels) clf = regres(metric={"mean": mean, "distance": dist}) clf.fit(covmats, targets).predict(covmats) @pytest.mark.parametrize("regres", regs) @pytest.mark.parametrize("metric", [42, "faulty", {"foo": "bar"}]) def test_metric_wrong_keys(regres, metric, get_covmats, get_targets): with pytest.raises((TypeError, KeyError, ValueError)): n_matrices, n_channels = 6, 3 targets = get_targets(n_matrices) covmats = get_covmats(n_matrices, n_channels)
def get_dist_func(): dist_func = [ distance_riemann, distance_logeuclid, distance_euclid, distance_logdet, distance_kullback, distance_kullback_right, distance_kullback_sym, distance_wasserstein, ] for df in dist_func: yield df @pytest.mark.parametrize("dist", get_distances()) def test_check_distance_str(dist): _check_distance_method(dist) @pytest.mark.parametrize("dist", get_dist_func()) def test_check_distance_func(dist): _check_distance_method(dist) def test_check_distance_error(): with pytest.raises(ValueError): _check_distance_method("universe") with pytest.raises(ValueError): _check_distance_method(42)