Esempio n. 1
0
def create_result_transform_file(function_test,
                                 new_extension_for_result,
                                 filename_ext=".md",
                                 folder_search=get_test_folder(),
                                 force_creation=False):
    logging.info('Create result for %s', new_extension_for_result)
    folder_search = common.check_folder(folder_search)
    len_end_of_filename = len(new_extension_for_result)

    def __create_result__(filename):
        filename = common.check_is_file_and_correct_path(filename)
        result_filename = common.set_correct_path(os.path.splitext(filename)[
            0] + new_extension_for_result)

        if (len(filename) > len_end_of_filename) and \
                (filename[-len_end_of_filename:] == new_extension_for_result):
            return
        if (os.path.isfile(result_filename)) and (not force_creation):
            return

        logging.info('Create result for the file %s', filename)
        function_test(filename)
        common.check_is_file_and_correct_path(result_filename)

    common.apply_function_in_folder(
        folder_search, __create_result__, filename_ext=filename_ext)
Esempio n. 2
0
def create_result_trans_file_inside(function_test,
                                    new_extension_for_result,
                                    filename_ext=".md",
                                    folder_search=get_test_folder(),
                                    force_creation=False):
    logging.info('Create result for %s', new_extension_for_result)
    folder_search = common.check_folder(folder_search)
    len_end_of_filename = len(new_extension_for_result)

    def __create_result__(filename):
        filename = common.check_is_file_and_correct_path(filename)
        result_filename = common.set_correct_path(os.path.splitext(filename)[
            0] + new_extension_for_result)

        if (len(filename) > len_end_of_filename) and \
                (filename[-len_end_of_filename:] == new_extension_for_result):
            return
        if (os.path.isfile(result_filename)) and (not force_creation):
            return

        logging.info('Create result for the file %s', filename)
        shutil.copyfile(filename, result_filename)
        function_test(result_filename)
        new_result_filename = "%s.%s-" % (result_filename,
                                          common.get_today())
        if os.path.isfile(new_result_filename + "000.bak"):
            os.remove(new_result_filename + "000.bak")
        if os.path.isfile(new_result_filename + "001.bak"):
            os.remove(new_result_filename + "001.bak")

    common.apply_function_in_folder(
        folder_search, __create_result__, filename_ext=filename_ext)
Esempio n. 3
0
def find_test_file_couple(new_extension_for_result, filename_ext=".md",
                          folder_search=get_test_folder()):
    logging.info('Search test files for %s', new_extension_for_result)
    folder_search = common.check_folder(folder_search)
    len_end_of_filename = len(new_extension_for_result)

    result = []

    def __search_test_file__(filename):
        filename = common.check_is_file_and_correct_path(filename)
        result_filename = common.set_correct_path(os.path.splitext(filename)[
            0] + new_extension_for_result)

        # case when the filename is a result filename
        if (len(filename) > len_end_of_filename) \
                and (filename[-len_end_of_filename:] ==
                     new_extension_for_result):
            return

        if os.path.isfile(result_filename):
            result.append((filename, result_filename))

    common.apply_function_in_folder(
        folder_search, __search_test_file__, filename_ext=filename_ext)

    return result
Esempio n. 4
0
def rename_file_result(test_folder, extension, new_extension):
    logging.info('rename_file_result in %s from %s to %s',
                 test_folder, extension, new_extension)
    folder_search = common.check_folder(os.path.join(get_test_folder(),
                                                     test_folder))
    len_end_of_filename = len(extension)

    def __rename_test_file__(filename):
        filename = common.check_is_file_and_correct_path(filename)

        if (len(filename) > len_end_of_filename) \
                and (filename[-len_end_of_filename:] == extension):
            shutil.move(filename,
                        filename[:-len_end_of_filename] + new_extension)
            print(filename)
            return

    common.apply_function_in_folder(
        folder_search, __rename_test_file__, filename_ext=".md")

    return