MCPcopy Index your code
hub / github.com/evalplus/evalplus / prepare_mutants

Function prepare_mutants

tools/tsr/mutation_init.py:20–61  ·  view source on GitHub ↗
(mutation_dir: str, dataset: str)

Source from the content-addressed store, hash-verified

18
19
20def prepare_mutants(mutation_dir: str, dataset: str):
21 pwd = os.getcwd()
22 task_ids = get_task_ids(dataset)
23 problems = get_problems(dataset)
24 os.makedirs(mutation_dir, exist_ok=True)
25 for task_id in track(task_ids, "Generating mutants"):
26 task_dir = os.path.join(mutation_dir, to_path(task_id))
27 os.makedirs(task_dir, exist_ok=True)
28 if any(map(lambda filename: filename.startswith("m"), os.listdir(task_dir))):
29 # already have mutants
30 continue
31 # Make groundtruth
32 groundtruth_code = (
33 problems[task_id]["prompt"] + problems[task_id]["canonical_solution"]
34 )
35 with open(os.path.join(task_dir, "gt.py"), "w") as f:
36 f.write(groundtruth_code)
37 # Make dummy pytest
38 with open(os.path.join(task_dir, "test_dummy.py"), "w") as f:
39 f.write("def test_dummy():\n pass")
40 # Use mutmut to generate mutants
41 os.chdir(task_dir)
42 clean(".mutmut-cache")
43 execute_cmd(["mutmut run", "--paths-to-mutate=gt.py", "1>/dev/null"])
44 try:
45 # Collect metainfo
46 total_mutants = int(
47 get_cmd_output(["mutmut", "results"]).split("\n")[-2].split("-")[-1]
48 )
49 except:
50 total_mutants = 0
51 # Dump mutants
52 for i in range(1, total_mutants + 1):
53 execute_cmd(["cp", "gt.py", "gt_copy.py"])
54 execute_cmd(["mutmut", "apply", str(i)])
55 execute_cmd(["mv", "gt.py", f"m{i}.py"])
56 execute_cmd(["mv", "gt_copy.py", "gt.py"])
57 # Remove gt and dummy pytest
58 execute_cmd(["rm", "gt.py"])
59 execute_cmd(["rm", "test_dummy.py"])
60 clean(".mutmut-cache")
61 os.chdir(pwd)
62
63
64def mutants_eval(mutation_dir: str, dataset: str):

Callers 1

mutation_init.pyFile · 0.85

Calls 6

get_task_idsFunction · 0.90
get_problemsFunction · 0.90
to_pathFunction · 0.90
cleanFunction · 0.90
execute_cmdFunction · 0.90
get_cmd_outputFunction · 0.90

Tested by

no test coverage detected