示例#1
0
    def test_check_sfdb_comparison_sfdb_new_longer(self):
        entries1 = [['1', '2'], ['1', '2'], ['1', '3']]
        entries2 = [['1', '2'], ['1', '2']]
        sfdb1 = create_test_sfdbcontainer(entries=entries1)
        sfdb2 = create_test_sfdbcontainer(entries=entries2)

        with self.assertRaises(sc.ComparisonError):
            sc.check_sfdb_comparison(sfdb1, sfdb2)
示例#2
0
    def test_check_sfdb_comparison_sfdb_old_longer_insufficient_excluded_lines(
            self):
        entries1 = [['1', '2'], ['1', '2']]
        entries2 = [['1', '2'], ['1', '2'], ['1', '3'], ['1', '4']]
        sfdb1 = create_test_sfdbcontainer(entries=entries1)
        sfdb2 = create_test_sfdbcontainer(entries=entries2)
        excluded_lines2 = [2 + sc.INDEX_SHIFT]

        with self.assertRaises(sc.ComparisonError):
            sc.check_sfdb_comparison(sfdb1,
                                     sfdb2,
                                     excluded_lines_old=excluded_lines2)
示例#3
0
    def test_check_sfdb_comparison_identical_sfdb(self):
        sfdb1 = create_test_sfdbcontainer()
        sfdb2 = create_test_sfdbcontainer()

        diverging_lines = sc.check_sfdb_comparison(sfdb1, sfdb2)

        expected_output = []
        self.assertEqual(expected_output, diverging_lines)
示例#4
0
    def test_check_sfdb_comparison_multiple_column_difference_excluded(self):
        columns = ['COLUMN1', 'COLUMN2', 'COLUMN3']
        entries1 = [['1', '2'], ['1', '2'], ['1', '2']]
        entries2 = [['1', '2'], ['1', '3'], ['1', '4']]
        sfdb1 = create_test_sfdbcontainer(entries=entries1, columns=columns)
        sfdb2 = create_test_sfdbcontainer(entries=entries2, columns=columns)
        excluded_columns = ['COLUMN2', 'COLUMN3']

        diverging_lines = sc.check_sfdb_comparison(
            sfdb1, sfdb2, excluded_columns=excluded_columns)

        expected_output = []
        self.assertEqual(expected_output, diverging_lines)
示例#5
0
    def test_check_sfdb_comparison_sfdb_new_longer_sufficient_excluded_lines(
            self):
        entries1 = [['1', '2'], ['1', '2'], ['1', '3'], ['1', '4']]
        entries2 = [['1', '2'], ['1', '2']]
        sfdb1 = create_test_sfdbcontainer(entries=entries1)
        sfdb2 = create_test_sfdbcontainer(entries=entries2)
        excluded_lines1 = [2 + sc.INDEX_SHIFT, 3 + sc.INDEX_SHIFT]

        diverging_lines = sc.check_sfdb_comparison(
            sfdb1, sfdb2, excluded_lines_new=excluded_lines1)

        expected_output = []
        self.assertEqual(expected_output, diverging_lines)
示例#6
0
    def test_check_sfdb_comparison_identical_sfdb_1_line_difference(self):
        entries1 = [['1', '2'], ['1', '2']]
        entries2 = [['1', '2'], ['1', '3']]
        sfdb1 = create_test_sfdbcontainer(entries=entries1)
        sfdb2 = create_test_sfdbcontainer(entries=entries2)

        diverging_entries = sc.check_sfdb_comparison(sfdb1, sfdb2)

        expected_output = [(1, np.array(['1', '2']), 1, np.array(['1', '3']))]
        self.assertEqual(expected_output[0][0], diverging_entries[0][0])
        np.testing.assert_array_equal(expected_output[0][1],
                                      diverging_entries[0][1])
        self.assertEqual(expected_output[0][2], diverging_entries[0][2])
        np.testing.assert_array_equal(expected_output[0][3],
                                      diverging_entries[0][3])
示例#7
0
    def test_check_sfdb_comparison_identical_sfdb_1_line_difference_excluded(
            self):
        entries1 = [['1', '2'], ['1', '2']]
        entries2 = [['1', '2'], ['1', '3']]
        sfdb1 = create_test_sfdbcontainer(entries=entries1)
        sfdb2 = create_test_sfdbcontainer(entries=entries2)
        excluded_lines1 = [1 + sc.INDEX_SHIFT]
        excluded_lines2 = [1 + sc.INDEX_SHIFT]

        diverging_lines = sc.check_sfdb_comparison(
            sfdb1,
            sfdb2,
            excluded_lines_new=excluded_lines1,
            excluded_lines_old=excluded_lines2)

        expected_output = []
        self.assertEqual(expected_output, diverging_lines)
示例#8
0
def run():
    if len(sys.argv) == 1:
        ap._build_parser().print_help()
        sys.exit(1)

    # Initialize logging
    sfdb_path = os.path.abspath(sys.argv[1])
    log_filepath = create_log_filepath(sfdb_path)
    configurate_logger(log_filepath)

    logging.log(LOGFILE_LEVEL, f'LOG FILE FOR SFDB FILE : {sfdb_path}')
    logging.log(LOGFILE_LEVEL, 'Indices in this log start from 1\n')

    warning_counter = 0

    # Receive Arguments
    args = ap.parse_args(sys.argv[1:])
    if args.request:
        args = ap.request_missing_args(args)

    # Perform Tests on SFDB file
    logging.log(LOGFILE_LEVEL, 'STARTING CONTENT FORMAT TEST')
    wrong_format_entries = sc.check_content_format(args.sfdb_new)
    sc.log_sfdb_content_format_check(len(args.sfdb_new.columns),
                                     wrong_format_entries)
    logging.log(LOGFILE_LEVEL, 'FINISHED CONTENT FORMAT TEST\n')

    # Run tests that crash if SFDB file has format issues
    if not wrong_format_entries:
        logging.log(LOGFILE_LEVEL, 'STARTING EXCEL AUTOFORMATTING TEST')
        formatted_cells_list = sc.check_excel_autoformatting(args.sfdb_new)
        sc.log_excel_autoformatting_check(formatted_cells_list)
        warning_counter += len(formatted_cells_list)
        logging.log(LOGFILE_LEVEL, 'FINISHED EXCEL AUTOFORMATTING TEST\n')

        logging.log(LOGFILE_LEVEL, 'STARTING DUPLICATE TEST')
        duplicates = args.sfdb_new.get_duplicates()
        sc.log_duplicates_check(duplicates)
        warning_counter += len(args.sfdb_new._get_duplicate_index_list())
        logging.log(LOGFILE_LEVEL, 'FINISHED DUPLICATE TEST\n')

        logging.log(LOGFILE_LEVEL, 'STARTING DATATYPE TEST')
        non_conform_entries = sc.check_datatype_conformity(args.sfdb_new)
        sc.log_datatype_check(non_conform_entries)
        warning_counter += 0 if non_conform_entries is None else len(
            non_conform_entries)
        logging.log(LOGFILE_LEVEL, 'FINISHED  DATATYPE TEST\n')

        if args.column_patterns:
            logging.log(LOGFILE_LEVEL, 'STARTING REGEX TEST')
            non_compliant_entries = sc.check_content_against_regex(
                args.sfdb_new, args.column_patterns)
            sc.log_regex_check(non_compliant_entries)
            warning_counter += len(non_compliant_entries)
            logging.log(LOGFILE_LEVEL, 'FINISHED REGEX TEST\n')

        if args.sfdb_old:
            logging.log(LOGFILE_LEVEL, 'STARTING COMPARISON TEST')
            diverging_entries = sc.check_sfdb_comparison(
                args.sfdb_new, args.sfdb_old, args.excluded_lines1,
                args.excluded_lines2, args.excluded_columns)
            sc.log_sfdb_comparison(diverging_entries)
            warning_counter += len(diverging_entries)
            logging.log(LOGFILE_LEVEL, 'FINISHED COMPARISON TEST\n')

        if args.write:
            no_dupl_sfdb_file = args.SFDBFile[:-5] + '_no_duplicates.sfdb'
            logging.log(
                LOGFILE_LEVEL,
                'Writing SFDB file without duplicates to {no_dupl_sfdb_file}')
            args.sfdb_new.write(no_dupl_sfdb_file,
                                sort=args.sorted,
                                remove_duplicates=True)

    else:
        logging.info(
            'Only format tests were carried out due to the format issues.\n'
            'Please run this software again after fixing them.')

    # Finish logging
    logging.log(LOGFILE_LEVEL, 'Done')
    logging.info(f'The file caused {warning_counter} warning-messages.')
    logging.info(f'Logfile written to {log_filepath}.\nDone')