예제 #1
0
    def compareCsvOutputs(self, ref_path, test_path, failures):
        # print( "Comparing CSV files: ref = " + ref_path + ", test = " + test_path )
        # Do Md5 comp first.
        ref_md5 = ru.md5_hash_of_file(ref_path)
        test_md5 = ru.md5_hash_of_file(test_path)
        if ref_md5 == test_md5:
            # print( "CSV files passed MD5 comparison test." )
            return False, ""

        fail_validation = False
        err_msg = ""

        # print( "CSV files failed MD5 comparison test." )
        # First (md5) test failed. Do line length, then line-by-line
        ref_length = ru.file_len(ref_path)
        test_length = ru.file_len(test_path)
        if ref_length != test_length:
            fail_validation = True
            err_msg = "Reference output {0} has {1} lines but test output {2} has {3} lines".format(
                ref_path, ref_length, test_path, test_length)

        else:
            with open(ref_path, "r") as ref_file, open(test_path,
                                                       "r") as test_file:
                line_num = 0
                for ref_line in ref_file:
                    line_num = line_num + 1
                    test_line = test_file.readline()
                    if ref_line != test_line:
                        ref_line_tokens = ref_line.split(',')
                        test_line_tokens = test_line.split(',')
                        for col_idx in range(len(ref_line_tokens)):
                            if ref_line_tokens[col_idx] != test_line_tokens[
                                    col_idx]:
                                break
                        err_msg = "First mismatch at line {0} of {1} column {2}: reference line...\n{3}vs test line...\n{4}{5} vs {6}".format(
                            line_num, ref_path, col_idx, ref_line, test_line,
                            ref_line_tokens[col_idx],
                            test_line_tokens[col_idx])
                        fail_validation = True
                        break

        print(err_msg)
        failure_txt = err_msg
        #self.report.addFailingTest( self.scenario_path, failure_txt, test_path, self.scenario_type )
        return fail_validation, failure_txt
예제 #2
0
    def compareCsvOutputs( self, ref_path, test_path, failures ):
        # print( "Comparing CSV files: ref = " + ref_path + ", test = " + test_path )
        # Do Md5 comp first.
        ref_md5 = ru.md5_hash_of_file( ref_path )
        test_md5 = ru.md5_hash_of_file( test_path )
        if ref_md5 == test_md5:
            # print( "CSV files passed MD5 comparison test." )
            return False, ""

        fail_validation = False
        err_msg = ""

        # print( "CSV files failed MD5 comparison test." )
        # First (md5) test failed. Do line length, then line-by-line
        ref_length = ru.file_len( ref_path )
        test_length = ru.file_len( test_path )
        if ref_length != test_length:
            fail_validation = True
            err_msg = "Reference output {0} has {1} lines but test output {2} has {3} lines".format( ref_path, ref_length, test_path, test_length )

        else:
            ref_file = open( ref_path )
            test_file = open( test_path )
            line_num = 0
            for ref_line in ref_file:
                line_num = line_num + 1
                test_line = test_file.readline()
                if ref_line != test_line:
                    ref_line_tokens = ref_line.split(',')
                    test_line_tokens = test_line.split(',')
                    for col_idx in range( len( ref_line_tokens) ):
                        if ref_line_tokens[col_idx] != test_line_tokens[col_idx]:
                            break
                    err_msg = "First mismatch at line {0} of {1} column {2}: reference line...\n{3}vs test line...\n{4}{5} vs {6}".format( line_num, ref_path, col_idx, ref_line, test_line, ref_line_tokens[col_idx], test_line_tokens[col_idx] ) 
                    fail_validation = True
                    ref_file.close()
                    test_file.close()
                    break

        print( err_msg )
        failure_txt = err_msg
        #self.report.addFailingTest( self.scenario_path, failure_txt, test_path, self.scenario_type )
        return fail_validation, failure_txt