from pathlib import Path


def check_file_ext(filename, extension):
    """Checks whether filename ends with extension and adds it if not."""
    is_path = False
    
    if isinstance(filename, Path):
        is_path = True
        filename = str(filename)    
    elif isinstance(filename, str):
        pass
    else:
        raise RuntimeError("Wrong input type for file extension check.")
    
    if filename[-len(extension):] != extension:
        filename += extension
    
    if is_path:
        filename = Path(filename)

    return filename