-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_tests.py
More file actions
108 lines (89 loc) · 2.92 KB
/
run_tests.py
File metadata and controls
108 lines (89 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
Test runner for the RAG Chatbot system.
Runs all available tests in the correct order.
"""
import sys
import subprocess
import os
from pathlib import Path
def run_command(command, description):
"""Run a command and return success status."""
print(f"\n🧪 {description}")
print("=" * 50)
try:
result = subprocess.run(
command,
shell=True,
capture_output=True,
text=True,
cwd=Path(__file__).parent
)
if result.returncode == 0:
print("✅ PASSED")
if result.stdout:
print(result.stdout)
return True
else:
print("❌ FAILED")
if result.stderr:
print("Error output:")
print(result.stderr)
if result.stdout:
print("Standard output:")
print(result.stdout)
return False
except Exception as e:
print(f"❌ ERROR: {e}")
return False
def check_api_running():
"""Check if the API is running."""
try:
import requests
response = requests.get("http://localhost:8000/api/v1/health", timeout=2)
return response.status_code == 200
except:
return False
def main():
"""Run all tests."""
print("🚀 RAG Chatbot Test Suite")
print("=" * 60)
# Ensure we're in the right directory
os.chdir(Path(__file__).parent)
# Basic tests that don't require external services
basic_tests = [
("python -m pytest tests/test_basic.py -v", "Unit Tests"),
("python tests/test_real_system.py", "System Component Tests")
]
# Tests that require API to be running
api_tests = [
("python tests/test_end_to_end.py", "End-to-End API Tests")
]
passed = 0
total = len(basic_tests) + len(api_tests)
# Run basic tests
for command, description in basic_tests:
if run_command(command, description):
passed += 1
# Check if API is running for end-to-end tests
if check_api_running():
print("\n✅ API is running, executing end-to-end tests...")
for command, description in api_tests:
if run_command(command, description):
passed += 1
else:
print("\n⚠️ API not running, skipping end-to-end tests")
print("💡 To run end-to-end tests, start the API with: python start_api.py")
# Don't count API tests as failed if API is not running
total = len(basic_tests)
print("\n" + "=" * 60)
print(f"🎯 Test Results: {passed}/{total} test suites passed")
if passed == total:
print("🎉 All available tests passed!")
return True
else:
print("⚠️ Some tests failed. Check the output above for details.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)