Skip to content

assert_request_equal

yohou.testing.metadata_routing.assert_request_equal(request, dictionary)

Assert metadata request matches expected dictionary.

Parameters

Name Type Description Default
request MetadataRequest

The request object to check

required
dictionary dict

Expected requests in the form {"method": {"param": value}}

required

Raises

Type Description
AssertionError

If request doesn't match expected dictionary

Source Code

Show/Hide source
def assert_request_equal(request, dictionary: dict) -> None:
    """Assert metadata request matches expected dictionary.

    Parameters
    ----------
    request : MetadataRequest
        The request object to check
    dictionary : dict
        Expected requests in the form {"method": {"param": value}}

    Raises
    ------
    AssertionError
        If request doesn't match expected dictionary

    """
    for method, requests in dictionary.items():
        mmr = getattr(request, method)
        assert mmr.requests == requests, f"Method {method}: expected {requests}, got {mmr.requests}"

    empty_methods = [
        method
        for method in SIMPLE_METHODS + ["observe", "observe_predict", "observe_transform"]
        if method not in dictionary
    ]
    for method in empty_methods:
        mmr = getattr(request, method, None)
        if mmr is not None:
            assert not len(mmr.requests), f"Method {method} should be empty but has {mmr.requests}"