예제 #1
0
def __get_sources_and_goals(task: TASK, test_type: TEST_TYPE = TEST_TYPE.DIFF) -> Tuple[List[str], List[str]]:
    root = os.path.join(BASE_DATA_PATH, test_type.value, task.value)
    sources_paths = get_all_file_system_items(root, match_condition(r'source_\d+.py'))
    sources_paths.sort()
    goals_paths = get_all_file_system_items(root, match_condition(r'goal_\d+.py'))
    goals_paths.sort()

    sources = [get_content_from_file(f) for f in sources_paths]
    goals = [get_content_from_file(f) for f in goals_paths]
    return sources, goals
예제 #2
0
def __get_chains(task: TASK) -> List[Tuple[List[str], str]]:
    root = os.path.join(BASE_DATA_PATH, task.value)
    chains = get_all_file_system_items(root, match_condition(r'chain_\d+'), item_type=FILE_SYSTEM_ITEM.SUBDIR)
    # We have to know ids for vertexes
    chains.sort()
    res_chains = []
    for chain in chains:
        sources_paths = get_all_file_system_items(chain, match_condition(r'source_\d+.py'))
        goals = get_all_file_system_items(chain, match_condition(r'goal.py'))
        if len(goals) != 1:
            log_and_raise_error(f'The chain {chain} contains more than 1 goal', log)
        sources_paths.sort()
        res_chains.append(([get_content_from_file(f) for f in sources_paths], get_content_from_file(goals[0])))
    return res_chains
def create_in_and_out_dict(tasks: List[TASK]) -> FilesDict:
    in_and_out_files_dict = {}
    for task in tasks:
        root = os.path.join(TASKS_TESTS_PATH, task.value)
        in_files = get_all_file_system_items(root,
                                             match_condition(r'in_\d+.txt'))
        out_files = get_all_file_system_items(root,
                                              match_condition(r'out_\d+.txt'))
        if len(out_files) != len(in_files):
            log_and_raise_error(
                'Length of out files list does not equal in files list', log)
        in_and_out_files_dict[task] = pair_in_and_out_files(
            in_files, out_files)
    return in_and_out_files_dict
def get_src_and_dst_files(test_type: DIFF_HANDLER_TEST_TYPES,
                          task: TASK) -> List[Tuple[str, str]]:
    root = os.path.join(CANONICALIZATION_TESTS.DATA_PATH.value,
                        ADDITIONAL_FOLDER, test_type.value, task.value)
    files = get_all_file_system_items(root, match_condition(r'\d+.py'))
    if len(files) == 0:
        log_and_raise_error(
            f'Number of test files is zero! Root for files is {root}', log)
    return list(itertools.product(files, repeat=2))
예제 #5
0
def get_test_in_and_out_files(
        test_type: Union[CANONICALIZATION_TESTS_TYPES,
                         DIFF_HANDLER_TEST_TYPES],
        task: TASK = None,
        additional_folder_name: str = '') -> List[Tuple[str, str]]:
    root = os.path.join(CANONICALIZATION_TESTS.DATA_PATH.value,
                        additional_folder_name, test_type.value)
    if task is not None:
        root = os.path.join(root, task.value)
    in_files = get_all_file_system_items(root, match_condition(r'in_\d+.py'))
    out_files = get_all_file_system_items(root, match_condition(r'out_\d+.py'))
    if len(out_files) != len(in_files):
        log_and_raise_error(
            'Length of out files list does not equal in files list', log)
    if len(in_files) == 0:
        log_and_raise_error(
            f'Number of test files is zero! Root for files is {root}', log)
    return pair_in_and_out_files(in_files, out_files)
예제 #6
0
def get_user_solutions(task: TASK) -> List[str]:
    root = os.path.join(BASE_DATA_PATH, task.value, 'user_solutions')
    solutions = get_all_file_system_items(root, match_condition(r'source_\d+.py'))
    # We have to know the order
    solutions.sort()
    return [get_content_from_file(f) for f in solutions]
예제 #7
0
 def __get_test_in_and_out_files(root: str) -> List[Tuple[str, str]]:
     in_files = get_all_file_system_items(root, match_condition(r'in_\d+.py'))
     out_files = get_all_file_system_items(root, match_condition(r'out_\d+.py'))
     assert len(in_files) != 0, f'Number of test files is zero! Root for files is {root}'
     return pair_in_and_out_files(in_files, out_files)