def is_valid_variable_name(varname):
    """
    Tests if a variable name is valid.

    Variable names must:
        - begin with an alphabetic character
    Variable names can:
        - contain arbitrarily many single quotes as their final characters
            x or x' or x''' but not x''yz
        - contain any sequence of alphanumeric characters and underscores between
            their first character and ending single quotes

    Usage:
    >>> is_valid_variable_name('x')
    True
    >>> is_valid_variable_name('x_')
    True
    >>> is_valid_variable_name('_x')
    False
    >>> is_valid_variable_name('df_1')
    True
    >>> is_valid_variable_name("cat''")
    True
    >>> is_valid_variable_name("cat''dog")
    False
    """
    varname_pieces = varname.split("'")
    if len(varname_pieces) > 1:
        if not all(piece == "" for piece in varname_pieces[1:]):
            return False
    front = varname_pieces[0]
    return front[0].isalpha() and front.replace("_", "").isalnum()