def run(source, source_extension, compile_commands, run_commands, test_cases=default_testcase_array): result = [] current_directory = os.getcwd() temp_dir = uuid.uuid4().hex os.makedirs(temp_dir) os.chdir(temp_dir) try: source_file_name = create_source_file(source, source_extension) out_compile = compile_source(compile_commands, source_file_name, result) execute_tests(run_commands, test_cases, out_compile, result) except Exception as e: out_exception = Output() result.append(out_exception) out_exception.status = Status.ENV_CRASH out_exception.stderr = str(e) print(os.sys.exc_info()) os.chdir(current_directory) shutil.rmtree(temp_dir, True) return result
def execute_tests(run_command, test_cases, out_compile, result): if out_compile.status == Status.COMPILE_ERROR: return ("Compilation Error") else: #run each test case and add the output to the list for test_case in test_cases: out_test = Output() out_test.test_case_id = test_case.id if run_command: start_time = time.time() completed = subprocess.run(run_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, input=test_case.input.encode('utf-8'), timeout=test_case.timeout, check = True) out_test.stderr = completed.stderr.decode('utf-8').rstrip() out_test.stdout = completed.stdout.decode('utf-8').rstrip() out_test.time = time.time() - start_time if completed.returncode: out_test.status = Status.RUNTIME_ERROR else: out_test.status = Status.OK result.append(out_test) else: raise ValueError("Test cases must have a run command")
def generate_routes(job, clustering_parameters, objective_coefficients): output_routes = [] un_routed_orders = job.orders[0:] while True: clustered_orders = SectorClustering.get_next_cluster(un_routed_orders, clustering_parameters) if len(clustered_orders) == 0: continue route = initiate_new_route(clustered_orders, job.depot, job.vehicles[0], job.locationMatrix, job.configuration) if route is None: break if len(clustered_orders) > 0: apply_best_feasible_insertion(route, clustered_orders, job.depot, job.vehicles[0], job.locationMatrix, job.configuration, objective_coefficients) if len(route.orders) > 0: output_routes.append(route) un_routed_orders = [order for order in un_routed_orders if order not in route.orders] else: break if len(un_routed_orders) <= 0: break return Output(output_routes, un_routed_orders)
def main(inputParams: Input = None) -> None: getcontext().traps[FloatOperation] = True if inputParams is None: inputParams = GetInput() columnNames = PeptideColumns() rawPeptideTables = RawPeptideTables(columnNames, inputDir=inputParams.inputPath) # TODO: FDR filter FDRFilter(rawPeptideTables=rawPeptideTables).ApplyDefaultFilter() if inputParams.blackList is not None: ApplyBlackList(rawPeptideTables, inputParams.blackList[1]) TestFastaAccessions(inputParams.seqDB, rawPeptideTables) peptideTables = PeptideTables(rawPeptideTables, seqDB=inputParams.seqDB) if inputParams.isProteinConfidence is True: ApplyProteinConfidenceFilter(inputParams.proteinConfidence, peptideTables) ApplyPeptideConfidenceFilter(inputParams.confPeptide, peptideTables) accessionTables = AccessionTables(inputParams.seqDB, peptideTables) accessionTables.sortedTableNums = peptideTables.GetSortedTableNums() filesSumms = GetScPsigAndNormFilesSumm(accessionTables) CalculateAccessionsNormRatios(accessionTables, filesSumms) ApplyGroupFilter( accessionTables, inputParams.maxGroupAbsence, inputParams.minGroupsWithAccession, ) Output( inputParams, seqDB=inputParams.seqDB, accessionTables=accessionTables, proteinGroupsDB=None, )
def compile_source(compile_commands, source_file_name, result): out_compile = Output() if compile_commands: compile_commands.append(source_file_name) completed = subprocess.run(compile_commands, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if completed.returncode: result.append(out_compile) out_compile.status = Status.COMPILE_ERROR out_compile.stdout = completed.stdout.decode('utf-8').rstrip() out_compile.stderr = completed.stderr.decode('utf-8').rstrip() else: out_compile.status = Status.OK return out_compile
def execute_tests(run_command, test_cases, out_compile, result): if out_compile.status != Status.COMPILE_ERROR: for test_case in test_cases: out_test = Output() out_test.test_case_id = test_case.id if run_command: completed = subprocess.run( run_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, input=test_case.input.encode('utf-8'), timeout=test_case.timeout) out_test.stdout = completed.stdout.decode('utf-8').rstrip() out_test.stderr = completed.stderr.decode('utf-8').rstrip() if completed.returncode: out_test.status = Status.RUNTIME_ERROR else: out_test.status = Status.OK result.append(out_test)