emergency-resource-env / validate.py
Sudeeksha-07's picture
Deploy Emergency Resource Environment
7266370
Raw
History Blame Contribute Delete
3.01 kB
import requests
import sys
BASE_URL = "http://127.0.0.1:7860"
def validate():
print("=" * 50)
print("VALIDATING EMERGENCY RESOURCE ENVIRONMENT")
print("=" * 50)
print()
tests = 0
passed = 0
# Test 1: Server health
tests += 1
try:
r = requests.get(f"{BASE_URL}/", timeout=5)
if r.status_code == 200:
print("βœ… Server is running")
passed += 1
else:
print("❌ Server returned error")
except Exception as e:
print(f"❌ Cannot connect to server: {e}")
return False
# Test 2: Reset endpoint
tests += 1
r = requests.post(f"{BASE_URL}/reset", params={"task": "easy"})
if r.status_code == 200 and "agent_position" in r.json():
print("βœ… Reset endpoint works")
passed += 1
else:
print("❌ Reset endpoint failed")
# Test 3: All three tasks
tests += 1
all_tasks_work = True
for task in ["easy", "medium", "hard"]:
r = requests.post(f"{BASE_URL}/reset", params={"task": task})
if r.status_code != 200:
all_tasks_work = False
print(f"❌ Task '{task}' failed")
break
if all_tasks_work:
print("βœ… All 3 tasks (easy, medium, hard) work")
passed += 1
# Test 4: Step endpoint
tests += 1
action = {"action_type": "move", "direction": "up"}
r = requests.post(f"{BASE_URL}/step", json=action)
if r.status_code == 200 and "reward" in r.json():
print("βœ… Step endpoint works")
passed += 1
else:
print("❌ Step endpoint failed")
# Test 5: State endpoint
tests += 1
r = requests.get(f"{BASE_URL}/state")
if r.status_code == 200 and "agent_position" in r.json():
print("βœ… State endpoint works")
passed += 1
else:
print("❌ State endpoint failed")
# Test 6: Grade endpoint
tests += 1
r = requests.get(f"{BASE_URL}/grade")
if r.status_code == 200 and "score" in r.json():
score = r.json()['score']
if 0 <= score <= 1:
print(f"βœ… Grade endpoint returns valid score: {score:.3f}")
passed += 1
else:
print(f"❌ Score {score} is not between 0 and 1")
else:
print("❌ Grade endpoint failed")
# Test 7: Reward values
tests += 1
rewards = []
for _ in range(5):
action = {"action_type": "move", "direction": "right"}
r = requests.post(f"{BASE_URL}/step", json=action)
rewards.append(r.json()['reward']['score'])
if all(0 <= r <= 1 for r in rewards):
print("βœ… All rewards are between 0 and 1")
passed += 1
else:
print("❌ Some rewards outside 0-1 range")
print()
print("=" * 50)
print(f"RESULTS: {passed}/{tests} tests passed")
print("=" * 50)
return passed == tests
if __name__ == "__main__":
success = validate()
sys.exit(0 if success else 1)