import pathlib
import stat


def check_file(file_name):
    """
    test if file: exists and is writable or can be created
        Args:
            file_name (str): the file name
        Returns:
            (pathlib.Path): the path or None if problems
    """
    if not file_name:
        return None

    path = pathlib.Path(file_name)

    # if file exists test if writable
    if path.exists() and path.is_file():
        handle = None
        try:
            handle = open(path, 'w')
        except PermissionError:
            return None
        finally:
            if handle:
                handle.close()

    # crate file with write permissions
    try:
        path.touch(stat.S_IWUSR)
    except PermissionError:
        return None

    return path