def check_enum(val, candidates, name):
    """
    Checks the specified val is in the specified candidates.
    """
    if val not in candidates:
        message = \
            "{0} can not be used for {1}. " \
            "Available values are {2}." \
            .format(val, name, candidates)
        raise ValueError(message)
    return val