CodeReviewEnv-Elite / setup_datasets.py
Krsnapriya's picture
Upload folder using huggingface_hub
2692c5d verified
Raw History Blame Contribute Delete
3.68 kB
import os
import json
def write_file(path, content):
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
f.write(content.strip() + "\n")
# EASY
write_file("datasets/easy_01/repo/main.py", '''
from utils import calculate_discount
def checkout(price):
return calculate_discount(price)
if __name__ == "__main__":
print(checkout(100))
''')
write_file("datasets/easy_01/repo/utils.py", '''
def calculate_discount(price):
discount = 0.1
return price - (price * discount * 10) # BUG: extra *10
''')
write_file("datasets/easy_01/logs.txt", '''
Running checkout...
Expected output: 90
Actual output: 0
AssertionError: Discount calculation incorrect
''')
write_file("datasets/easy_01/tests.txt", '''
test_checkout:
input: 100
expected: 90
''')
write_file("datasets/easy_01/metadata.json", json.dumps({
"bug_location": ["utils.py"],
"bug_type": "logic_error",
"difficulty": "easy"
}, indent=2))
# MEDIUM
write_file("datasets/medium_01/repo/app.py", '''
from parser import parse_input
from validator import validate
def process(data):
parsed = parse_input(data)
if validate(parsed):
return parsed["value"]
return None
''')
write_file("datasets/medium_01/repo/parser.py", '''
def parse_input(data):
return {
"value": int(data),
"status": "ok"
}
''')
write_file("datasets/medium_01/repo/validator.py", '''
def validate(data):
return data["status"] == "valid"
''')
write_file("datasets/medium_01/logs.txt", '''
Validation failed: status not valid
Check validator logic
''')
write_file("datasets/medium_01/tests.txt", '''
input: "10"
expected output: 10
''')
write_file("datasets/medium_01/metadata.json", json.dumps({
"bug_location": ["parser.py"],
"bug_type": "semantic_error",
"difficulty": "medium",
"misleading_logs": True
}, indent=2))
# HARD
write_file("datasets/hard_01/repo/main.py", '''
from service import get_user_score
print(get_user_score("alice"))
''')
write_file("datasets/hard_01/repo/db.py", '''
DATABASE = {
"alice": {"score": 50}
}
def fetch_user(name):
return DATABASE.get(name)
''')
write_file("datasets/hard_01/repo/service.py", '''
from db import fetch_user
def get_user_score(name):
user = fetch_user(name)
return user["points"] * 2 # BUG: wrong key ("points")
''')
write_file("datasets/hard_01/logs.txt", '''
KeyError: 'points'
Occurred in service layer
''')
write_file("datasets/hard_01/tests.txt", '''
input: "alice"
expected: 100
''')
write_file("datasets/hard_01/metadata.json", json.dumps({
"bug_location": ["service.py"],
"bug_type": "key_error",
"difficulty": "hard"
}, indent=2))
# EXTREME
write_file("datasets/extreme_01/repo/engine.py", '''
from cache import get_cache
def compute(x):
cache = get_cache()
if x in cache:
return cache[x]
return x * 2
''')
write_file("datasets/extreme_01/repo/cache.py", '''
_cache = {}
def get_cache():
return _cache
def update_cache(key, value):
_cache[key] = value
''')
write_file("datasets/extreme_01/repo/api.py", '''
from engine import compute
from cache import update_cache
def handler(x):
result = compute(x)
update_cache(x, result + 1) # BUG: corrupt cache
return result
''')
write_file("datasets/extreme_01/logs.txt", '''
Inconsistent outputs detected
Same input produces different results
''')
write_file("datasets/extreme_01/tests.txt", '''
input: 5
run1: 10
run2: 11 <-- ERROR
''')
write_file("datasets/extreme_01/metadata.json", json.dumps({
"bug_location": ["api.py"],
"bug_type": "state_corruption",
"difficulty": "extreme",
"non_deterministic": True
}, indent=2))
print("Datasets generated successfully.")