Spaces:
Sleeping
Sleeping
Delete tests
Browse files
tests/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
# Tests package for SQL Quality Environment
|
|
|
|
|
|
tests/__pycache__/__init__.cpython-313.pyc
DELETED
|
Binary file (206 Bytes)
|
|
|
tests/__pycache__/test_environment.cpython-313-pytest-8.3.5.pyc
DELETED
|
Binary file (25.7 kB)
|
|
|
tests/test_environment.py
DELETED
|
@@ -1,255 +0,0 @@
|
|
| 1 |
-
"""Tests for SQL Quality Environment."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
import requests
|
| 5 |
-
import time
|
| 6 |
-
from typing import Any, Dict
|
| 7 |
-
|
| 8 |
-
# Base URL for testing
|
| 9 |
-
BASE_URL = "http://localhost:7860"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
class TestHealthEndpoint:
|
| 13 |
-
"""Test the health check endpoint."""
|
| 14 |
-
|
| 15 |
-
def test_health_returns_ok(self):
|
| 16 |
-
"""Health endpoint should return status ok."""
|
| 17 |
-
try:
|
| 18 |
-
r = requests.get(f"{BASE_URL}/health", timeout=5)
|
| 19 |
-
assert r.status_code == 200
|
| 20 |
-
data = r.json()
|
| 21 |
-
assert data.get("status") == "ok"
|
| 22 |
-
except requests.ConnectionError:
|
| 23 |
-
pytest.skip("Server not running")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class TestNullAuditTask:
|
| 27 |
-
"""Test null_audit task functionality."""
|
| 28 |
-
|
| 29 |
-
def setup_method(self):
|
| 30 |
-
"""Reset episode before each test."""
|
| 31 |
-
self.base_url = BASE_URL
|
| 32 |
-
|
| 33 |
-
def test_null_audit_reset(self):
|
| 34 |
-
"""Should initialize null_audit task successfully."""
|
| 35 |
-
try:
|
| 36 |
-
r = requests.post(
|
| 37 |
-
f"{self.base_url}/reset",
|
| 38 |
-
json={"task_id": "null_audit"},
|
| 39 |
-
timeout=30
|
| 40 |
-
)
|
| 41 |
-
assert r.status_code == 200
|
| 42 |
-
data = r.json()
|
| 43 |
-
assert "episode_id" in data
|
| 44 |
-
assert data.get("task_id") == "null_audit"
|
| 45 |
-
except requests.ConnectionError:
|
| 46 |
-
pytest.skip("Server not running")
|
| 47 |
-
|
| 48 |
-
def test_null_audit_query_users(self):
|
| 49 |
-
"""Should be able to query users table."""
|
| 50 |
-
try:
|
| 51 |
-
# Reset first
|
| 52 |
-
requests.post(
|
| 53 |
-
f"{self.base_url}/reset",
|
| 54 |
-
json={"task_id": "null_audit"},
|
| 55 |
-
timeout=30
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
# Query users
|
| 59 |
-
r = requests.post(
|
| 60 |
-
f"{self.base_url}/step",
|
| 61 |
-
json={
|
| 62 |
-
"task_id": "null_audit",
|
| 63 |
-
"action_type": "query",
|
| 64 |
-
"sql": "SELECT * FROM users LIMIT 5"
|
| 65 |
-
},
|
| 66 |
-
timeout=30
|
| 67 |
-
)
|
| 68 |
-
assert r.status_code == 200
|
| 69 |
-
except requests.ConnectionError:
|
| 70 |
-
pytest.skip("Server not running")
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
class TestTypeRepairTask:
|
| 74 |
-
"""Test type_repair task functionality."""
|
| 75 |
-
|
| 76 |
-
def test_type_repair_schema(self):
|
| 77 |
-
"""Should have transactions table with amount column."""
|
| 78 |
-
try:
|
| 79 |
-
r = requests.post(
|
| 80 |
-
f"{BASE_URL}/reset",
|
| 81 |
-
json={"task_id": "type_repair"},
|
| 82 |
-
timeout=30
|
| 83 |
-
)
|
| 84 |
-
assert r.status_code == 200
|
| 85 |
-
data = r.json()
|
| 86 |
-
schema = data.get("schema_info", [])
|
| 87 |
-
|
| 88 |
-
# Find transactions table
|
| 89 |
-
tables = [s.get("table_name", s.get("name", "")) for s in schema]
|
| 90 |
-
assert "transactions" in tables
|
| 91 |
-
except requests.ConnectionError:
|
| 92 |
-
pytest.skip("Server not running")
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
class TestDedupBugTask:
|
| 96 |
-
"""Test dedup_bug task functionality."""
|
| 97 |
-
|
| 98 |
-
def test_dedup_has_duplicates(self):
|
| 99 |
-
"""Should have duplicate order_ids initially."""
|
| 100 |
-
try:
|
| 101 |
-
r = requests.post(
|
| 102 |
-
f"{BASE_URL}/reset",
|
| 103 |
-
json={"task_id": "dedup_bug"},
|
| 104 |
-
timeout=30
|
| 105 |
-
)
|
| 106 |
-
assert r.status_code == 200
|
| 107 |
-
data = r.json()
|
| 108 |
-
sample_rows = data.get("sample_rows", {})
|
| 109 |
-
|
| 110 |
-
# Get order_items samples
|
| 111 |
-
sample = sample_rows.get("order_items", [])
|
| 112 |
-
|
| 113 |
-
# Check sample for duplicates
|
| 114 |
-
if sample:
|
| 115 |
-
order_ids = [row.get("order_id") for row in sample]
|
| 116 |
-
# Sample should show duplicates
|
| 117 |
-
assert len(order_ids) > len(set(order_ids)) or True # May or may not have dups in sample
|
| 118 |
-
except requests.ConnectionError:
|
| 119 |
-
pytest.skip("Server not running")
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
class TestFKIntegrityTask:
|
| 123 |
-
"""Test fk_integrity task functionality."""
|
| 124 |
-
|
| 125 |
-
def test_fk_tables_exist(self):
|
| 126 |
-
"""Should have invoices and invoice_items tables."""
|
| 127 |
-
try:
|
| 128 |
-
r = requests.post(
|
| 129 |
-
f"{BASE_URL}/reset",
|
| 130 |
-
json={"task_id": "fk_integrity"},
|
| 131 |
-
timeout=30
|
| 132 |
-
)
|
| 133 |
-
assert r.status_code == 200
|
| 134 |
-
data = r.json()
|
| 135 |
-
schema = data.get("schema_info", [])
|
| 136 |
-
|
| 137 |
-
tables = [s.get("table_name", s.get("name", "")) for s in schema]
|
| 138 |
-
assert "invoices" in tables
|
| 139 |
-
assert "customers" in tables
|
| 140 |
-
except requests.ConnectionError:
|
| 141 |
-
pytest.skip("Server not running")
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
class TestSchemaDriftTask:
|
| 145 |
-
"""Test schema_drift task functionality."""
|
| 146 |
-
|
| 147 |
-
def test_raw_events_table_exists(self):
|
| 148 |
-
"""Should have events_v1 and events_v2 tables."""
|
| 149 |
-
try:
|
| 150 |
-
r = requests.post(
|
| 151 |
-
f"{BASE_URL}/reset",
|
| 152 |
-
json={"task_id": "schema_drift"},
|
| 153 |
-
timeout=30
|
| 154 |
-
)
|
| 155 |
-
assert r.status_code == 200
|
| 156 |
-
data = r.json()
|
| 157 |
-
schema = data.get("schema_info", [])
|
| 158 |
-
|
| 159 |
-
tables = [s.get("table_name", s.get("name", "")) for s in schema]
|
| 160 |
-
assert "events_v1" in tables
|
| 161 |
-
assert "events_v2" in tables
|
| 162 |
-
except requests.ConnectionError:
|
| 163 |
-
pytest.skip("Server not running")
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
class TestQueryAction:
|
| 167 |
-
"""Test QUERY action validation."""
|
| 168 |
-
|
| 169 |
-
def test_query_rejects_update(self):
|
| 170 |
-
"""QUERY action should reject UPDATE statements."""
|
| 171 |
-
try:
|
| 172 |
-
# Reset any task
|
| 173 |
-
requests.post(
|
| 174 |
-
f"{BASE_URL}/reset",
|
| 175 |
-
json={"task_id": "null_audit"},
|
| 176 |
-
timeout=30
|
| 177 |
-
)
|
| 178 |
-
|
| 179 |
-
# Try UPDATE via query
|
| 180 |
-
r = requests.post(
|
| 181 |
-
f"{BASE_URL}/step",
|
| 182 |
-
json={
|
| 183 |
-
"task_id": "null_audit",
|
| 184 |
-
"action_type": "query",
|
| 185 |
-
"sql": "UPDATE users SET email = 'test' WHERE 1=1"
|
| 186 |
-
},
|
| 187 |
-
timeout=30
|
| 188 |
-
)
|
| 189 |
-
|
| 190 |
-
# Should get feedback about read-only
|
| 191 |
-
data = r.json()
|
| 192 |
-
feedback = data.get("reward", {}).get("feedback", "")
|
| 193 |
-
assert "read-only" in feedback.lower() or "fix" in feedback.lower()
|
| 194 |
-
except requests.ConnectionError:
|
| 195 |
-
pytest.skip("Server not running")
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
class TestFixAction:
|
| 199 |
-
"""Test FIX action functionality."""
|
| 200 |
-
|
| 201 |
-
def test_fix_allows_update(self):
|
| 202 |
-
"""FIX action should allow UPDATE statements."""
|
| 203 |
-
try:
|
| 204 |
-
# Reset type_repair task
|
| 205 |
-
requests.post(
|
| 206 |
-
f"{BASE_URL}/reset",
|
| 207 |
-
json={"task_id": "type_repair"},
|
| 208 |
-
timeout=30
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
# Apply fix
|
| 212 |
-
r = requests.post(
|
| 213 |
-
f"{BASE_URL}/step",
|
| 214 |
-
json={
|
| 215 |
-
"task_id": "type_repair",
|
| 216 |
-
"action_type": "fix",
|
| 217 |
-
"fix_query": "UPDATE transactions SET amount = '100' WHERE rowid = 1"
|
| 218 |
-
},
|
| 219 |
-
timeout=30
|
| 220 |
-
)
|
| 221 |
-
|
| 222 |
-
assert r.status_code == 200
|
| 223 |
-
except requests.ConnectionError:
|
| 224 |
-
pytest.skip("Server not running")
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
class TestGrading:
|
| 228 |
-
"""Test grading functionality."""
|
| 229 |
-
|
| 230 |
-
def test_submit_returns_score(self):
|
| 231 |
-
"""Submit should return a score between 0 and 1."""
|
| 232 |
-
try:
|
| 233 |
-
# Reset and immediately submit
|
| 234 |
-
requests.post(
|
| 235 |
-
f"{BASE_URL}/reset",
|
| 236 |
-
json={"task_id": "null_audit"},
|
| 237 |
-
timeout=30
|
| 238 |
-
)
|
| 239 |
-
|
| 240 |
-
r = requests.post(
|
| 241 |
-
f"{BASE_URL}/step",
|
| 242 |
-
json={
|
| 243 |
-
"task_id": "null_audit",
|
| 244 |
-
"action_type": "submit",
|
| 245 |
-
"answer": "city"
|
| 246 |
-
},
|
| 247 |
-
timeout=30
|
| 248 |
-
)
|
| 249 |
-
|
| 250 |
-
data = r.json()
|
| 251 |
-
score = data.get("reward", {}).get("score")
|
| 252 |
-
assert score is not None
|
| 253 |
-
assert 0.0 <= score <= 1.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