def rewrite_title(lines, expected_title, rewritten_title):
    """Rewrite the title of a .rst file.

    Args:
        lines (List[str]): lines of the file.
        expected_title (str): title expected to be generated by apidoc
        rewritten_title (str): title to replace

    Returns
        List[str]: rewritten title lines.

    Raises
        ValueError: If the title '==...==' isn't on line 1.
        ValueError: If the title isn't the expected value.
    """
    rewritten_content = []

    # Find the title header **and** assert there is only one '==...==' line.
    title_index, = [i for i, line in enumerate(lines) if set(line) == set('=')]
    if title_index != 1:
        raise ValueError('Unexpected title line', title_index)
    if lines[0] != expected_title:
        raise ValueError('Unexpected title content', lines[0])

    rewritten_content.append(rewritten_title)
    rewritten_content.append('=' * len(rewritten_title))

    return rewritten_content