def collapse_codepoints(codepoints):
    """
    Convert a list of code points in a list of ranges.

    Given a list of code points, extract the ranges with the maximal length from
    consecutive code points.

    :param: codepoints: List of code points.
    :returns: List of ranges (first_cp, last_cp)

    >>> ranges = collapse_codepoints([1,2,3,4,7,10,11,12,15])
    >>> ranges == [(1,4), (7, 7), (10, 12), (15,15)]
    True
    """
    result = []
    # Sort list
    codepoints = sorted(codepoints)
    first_cp = codepoints[0]
    last_cp = codepoints[0]
    for cp in codepoints[1:]:
        if cp == last_cp + 1:
            # Code point is continuous of last one, extend range
            last_cp = cp
        else:
            # Code point is not successor of last one, create new range
            result.append((first_cp, last_cp))
            first_cp = cp
            last_cp = cp

    result.append((first_cp, last_cp))

    return result