def enforce_file_extension(file, extension):
    """
    Returns the given string (file name or full path) with the given extension.
    string had no file extension .extension will be appended. If it had another
    extension it is changed to the given extension. If it had the given
    extension already the unchanged string is returned.

    Parameters
    ----------
    file: File name or full path. Can include a file extension .*
    extension: File extension the given file name will be returned with.

    Returns
    -------
    The given file with the given extension.
    """
    if not extension.startswith('.'):
        extension = '.' + extension
    split_str = file.split('.', 1)
    if (len(split_str) != 2) or (split_str[-1] != extension[1:]):
        file = split_str[0] + extension
    return file