Spaces:
Running
Running
Commit ·
36ce0f6
1
Parent(s): 74d99be
added test_env file
Browse files- test_env.py +41 -0
test_env.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
# Add the current directory to sys.path so we can import 'server'
|
| 4 |
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 5 |
+
|
| 6 |
+
from server.environment import CodeReviewEnvironment
|
| 7 |
+
from server.models import CodeReviewAction
|
| 8 |
+
|
| 9 |
+
def run_test():
|
| 10 |
+
print("Initializing CodeReviewEnvironment...")
|
| 11 |
+
env = CodeReviewEnvironment()
|
| 12 |
+
|
| 13 |
+
print("\n--- 1. Testing 'easy' task (reset) ---")
|
| 14 |
+
obs = env.reset(difficulty="easy")
|
| 15 |
+
print(f"Task ID: {obs.task_id}")
|
| 16 |
+
print(f"Difficulty: {obs.difficulty}")
|
| 17 |
+
print(f"Task Description: {obs.task_description}")
|
| 18 |
+
print(f"Code Snippet:\n{obs.code_snippet}")
|
| 19 |
+
print("-" * 40)
|
| 20 |
+
|
| 21 |
+
print("\n--- 2. Submitting an accurate CodeReviewAction ---")
|
| 22 |
+
action = CodeReviewAction(
|
| 23 |
+
bug_identified=True,
|
| 24 |
+
bug_type="off-by-one error",
|
| 25 |
+
bug_location="range(1, len(arr) + 1)",
|
| 26 |
+
bug_description="The loop contains an off-by-one IndexError because it tries to access arr[i] which goes out of bounds.",
|
| 27 |
+
suggested_fix="Change to range(len(arr))",
|
| 28 |
+
severity="high"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
obs, reward, done, info = env.step(action)
|
| 32 |
+
print(f"Step Reward: {reward}")
|
| 33 |
+
print(f"Is Done: {done}")
|
| 34 |
+
print(f"Info Breakdown:")
|
| 35 |
+
for k, v in info['breakdown'].items():
|
| 36 |
+
print(f" {k}: {v}")
|
| 37 |
+
print(f"Total Score: {info['total_score']}")
|
| 38 |
+
print(f"Feedback: {info['feedback']}")
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
run_test()
|