Q:

testing errors: comparing 2 files

I have 5 functions working relatively
1- singleline_diff(line1, line2)
comparing 2 line in one file
Inputs:
      line1 - first single line string
      line2 - second single line string
    Output:
      the index of the first difference between the two lines
      identical if the two lines are the same.
2- singleline_diff_format(line1, line2, idx):
comparing 2 line in one file
Inputs:
      line1 - first single line string
      line2 - second single line string
      idx   - index at which to indicate difference (from 1st function)
    Output:
      abcd (first line)
      ==^  (= indicate identical character, ^ indicate the difference)
      abef (second line)
  If either input line contains a newline or carriage return, 
  then returns an empty string.
  If idx is not a valid index, then returns an empty string.

3- multiline_diff(lines1, lines2):
deal with two lists of lines
Inputs:
      lines1 - list of single line strings
      lines2 - list of single line strings
    Output:
      a tuple containing the line number (starting from 0) and
      the index in that line where the first difference between lines1
      and lines2 occurs.
      Returns (IDENTICAL, IDENTICAL) if the two lists are the same.
4-get_file_lines(filename)
    Inputs:
      filename - name of file to read
    Output:
      a list of lines from the file named filename. 
      If the file does not exist or is not readable, then the
      behavior of this function is undefined.
5- file_diff_format(filename1, filename2) " the function with the problem"
deals with two input files
Inputs:
      filename1 - name of first file
      filename2 - name of second file
    Output:
      four line string showing the location of the first
      difference between the two files named by the inputs.
  If the files are identical, the function instead returns the
  string "No differences\n".

  If either file does not exist or is not readable, then the
  behavior of this function is undefined.

testing the function:
everything goes will until it the test use one empty file 
it gave me "list index out of range"
this is the code I use
def file_diff_format(filename1, filename2):

    file_1 = get_file_lines(filename1)
    file_2 = get_file_lines(filename2)
    mli_dif = multiline_diff(file_1, file_2)
    min_lens = min(len(file_1), len(file_2))

    if mli_dif == (-1,-1) :
        return "No differences" "\n" 

    else:
        diff_line_indx = mli_dif[0]
        diff_str_indx = int (mli_dif[1])
        if len(file_1) >= 0:
            line_file_1 = ""
        else:
            line_file_1 = file_1[diff_line_indx]

        if len(file_2) >= 0:
            line_file_2 = ""
        else:
            line_file_2 = file_2[diff_line_indx]

        line_file_1 = file_1[diff_line_indx]
        line_file_2 = file_2 [diff_line_indx]

        out_print = singleline_diff_format(line_file_1, line_file_2, diff_str_indx)

        return ( "Line {}{}{}".format ((diff_line_indx), (":\n"), (out_print)))

A:

If one of the files is empty, either file1 or file2 should be an empty list, so that trying to access an element of either would cause the error you describe.
Your code checks for these files to be empty when assigning to line_file_`` andline_file_2`, but then goes ahead and tries to access elements of both.

