<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def check_valid(var, key, expected):
 r"""Check that a variable's attribute has the expected value. Warn user otherwise."""


    att = getattr(var, key, None)
    if att is None:
        e = 'Variable does not have a `{}` attribute.'.format(key)
        warn(e)
    elif att != expected:
        e = 'Variable has a non-conforming {}. Got `{}`, expected `{}`'.format(key, att, expected)
        warn(e)