import filecmp
import io
import difflib


def _perform_diff(result, original):
    """  Compares the files `result` and `original`

    Returns a tuple:
      The first value is True if the files are the same
      The second arg is the text representation of the diff
    """

    are_same = filecmp.cmp(result, original)
    if not are_same:
        with open(result) as f:
            result_txt = f.readlines()
        with open(original) as f:
            original_txt = f.readlines()

        with io.StringIO() as output_stream:
            for line in  difflib.unified_diff(result_txt, original_txt):
                output_stream.write(line)
            return (False, output_stream.getvalue())
    else:
        return (True, "")