Skip to content

check_composite_weights_length_validation

yohou.testing.check_composite_weights_length_validation(compositor, descriptor, operate)

Check a weights list of the wrong length raises.

Parameters

Name Type Description Default
compositor BaseEstimator

A {multiply, mean} compositor instance (for its type).

required
descriptor dict

Carries "attr" and "components".

required
operate callable

Invoked with a freshly-built compositor to trigger validation.

required

Raises

Type Description
AssertionError

If the mismatched-length weights are accepted.

Source Code

Source code in src/yohou/testing/composite.py
def check_composite_weights_length_validation(compositor, descriptor: dict, operate: Callable) -> None:
    """Check a ``weights`` list of the wrong length raises.

    Parameters
    ----------
    compositor : BaseEstimator
        A ``{multiply, mean}`` compositor instance (for its type).
    descriptor : dict
        Carries ``"attr"`` and ``"components"``.
    operate : callable
        Invoked with a freshly-built compositor to trigger validation.

    Raises
    ------
    AssertionError
        If the mismatched-length weights are accepted.

    """
    name = type(compositor).__name__
    attr = descriptor["attr"]
    components = descriptor["components"]
    bad = type(compositor)(**{attr: components, "weights": [1.0] * (len(components) + 1)})
    try:
        operate(bad)
    except ValueError:
        return
    raise AssertionError(f"{name}: weights of wrong length were accepted; expected ValueError")