from unittest.mock import Mock


def _generic_mock(**kwargs):
    """Create a mock object with the provided keyword arguments as attributes."""
    mock = Mock()

    # Treat type_ differently!!
    if "type_" in kwargs:
        # Type is a class variable of road sections,
        # it must be set in a different way
        mock.__class__.TYPE = kwargs["type_"]
        del kwargs["type_"]

    # Obstacles are not polygons but rather classes that have a frame attribute
    if "obstacles" in kwargs and kwargs["obstacles"] is not None:
        for i, obs in enumerate(kwargs["obstacles"]):
            m = Mock()
            m.frame = obs
            m.height = (i % 4 + 5) / 10
            m.id_ = i
            m.desc = "test"
            kwargs["obstacles"][i] = m

    for key, val in kwargs.items():
        setattr(mock, key, val)
    return mock