1+ from pathlib import Path
2+ from unidiff import PatchSet
3+ from elleelleaime .core .benchmarks .benchmark import Benchmark
4+ from elleelleaime .core .benchmarks .runbugrun .runbugrunbug import RunBugRunBug
5+
6+ import subprocess
7+ import logging
8+
9+ import pandas as pd
10+
11+ class RunBugRun (Benchmark ):
12+ """
13+ The class for representing the RunBugRun benchmark.
14+ """
15+
16+ def __init__ (
17+ self , path : Path = Path ("benchmarks/run_bug_run" ).absolute ()
18+ ) -> None :
19+ super ().__init__ ("runbugrun" , path )
20+
21+ def initialize (self ) -> None :
22+ """
23+ Initializes the RunBugRun benchmark object by collecting all the bugs.
24+ """
25+ logging .info ("Initializing RunBugRun benchmark..." )
26+
27+ python_path = Path (self .get_path (), 'python_valid0.jsonl' )
28+ # test_path = Path(self.get_path(), 'tests_all.jsonl')
29+
30+ python_df = pd .read_json (python_path , lines = True ).set_index ('problem_id' )
31+
32+ for prob_id , (buggy_submission_id , buggy_code , fixed_submission_id , fixed_code ) \
33+ in python_df .drop_duplicates (subset = ['buggy_submission_id' ])[
34+ ['buggy_submission_id' ,'buggy_code' , 'fixed_submission_id' , 'fixed_code' ]
35+ ].iterrows ():
36+
37+ buggy_file = Path (self .path , f'{ prob_id } _{ buggy_submission_id } .py' )
38+ fixed_file = Path (self .path , f'{ prob_id } _{ fixed_submission_id } .py' )
39+
40+ run = subprocess .run (
41+ f"""cd { self .get_path ()} &&
42+ echo '''{ buggy_code } ''' > { buggy_file } &&
43+ echo '''{ fixed_code } ''' > { fixed_file } &&
44+ diff --unified { fixed_file .relative_to (self .path )} { buggy_file .relative_to (self .path )} """ ,
45+ shell = True ,
46+ capture_output = True
47+ )
48+ if run .returncode :
49+ print (run )
50+
51+ diff = PatchSet (run .stdout .decode ("utf-8" ))
52+ # Change the source file path to point to the buggy version
53+ diff [0 ].source_file = f"{ buggy_file .relative_to (self .path )} "
54+
55+ self .add_bug (RunBugRunBug (self , f"{ prob_id } _{ buggy_submission_id } " , str (diff )))
56+
0 commit comments