-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsimple_test_runner.py
More file actions
201 lines (165 loc) Β· 6.07 KB
/
simple_test_runner.py
File metadata and controls
201 lines (165 loc) Β· 6.07 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python3
"""
Simple test runner for PraisonAI Agents
Works without pytest dependency at import time
"""
import sys
import subprocess
from pathlib import Path
def run_tests_with_subprocess():
"""Run tests using subprocess to avoid import issues."""
project_root = Path(__file__).parent.parent
print("π§ͺ PraisonAI Agents - Simple Test Runner")
print("=" * 50)
# Test commands to run
test_commands = [
{
"name": "Unit Tests",
"cmd": [sys.executable, "-m", "pytest", "tests/unit/", "-v", "--tb=short"],
"description": "Core functionality tests"
},
{
"name": "Integration Tests",
"cmd": [sys.executable, "-m", "pytest", "tests/integration/", "-v", "--tb=short"],
"description": "Complex feature integration tests"
},
{
"name": "Legacy Tests",
"cmd": [sys.executable, "-m", "pytest", "tests/test.py", "-v", "--tb=short"],
"description": "Original example tests"
}
]
all_passed = True
results = []
for test_config in test_commands:
print(f"\nπ Running: {test_config['name']}")
print(f"π {test_config['description']}")
print("-" * 40)
try:
result = subprocess.run(
test_config['cmd'],
cwd=project_root,
capture_output=True,
text=True,
timeout=300 # 5 minute timeout
)
if result.returncode == 0:
print(f"β
{test_config['name']}: PASSED")
results.append((test_config['name'], "PASSED"))
# Show some successful output
if result.stdout:
lines = result.stdout.strip().split('\n')
if len(lines) > 0:
print(f"π {lines[-1]}") # Show last line
else:
print(f"β {test_config['name']}: FAILED")
results.append((test_config['name'], "FAILED"))
all_passed = False
# Show error details
if result.stderr:
print("Error output:")
print(result.stderr[-500:]) # Last 500 chars
if result.stdout:
print("Standard output:")
print(result.stdout[-500:]) # Last 500 chars
except subprocess.TimeoutExpired:
print(f"β±οΈ {test_config['name']}: TIMEOUT")
results.append((test_config['name'], "TIMEOUT"))
all_passed = False
except Exception as e:
print(f"π₯ {test_config['name']}: ERROR - {e}")
results.append((test_config['name'], "ERROR"))
all_passed = False
# Summary
print("\n" + "=" * 50)
print("π TEST SUMMARY")
print("=" * 50)
for name, status in results:
if status == "PASSED":
print(f"β
{name}: {status}")
else:
print(f"β {name}: {status}")
if all_passed:
print("\nπ All tests passed!")
return 0
else:
print("\nπ₯ Some tests failed!")
return 1
def run_fast_tests():
"""Run only the fastest tests."""
project_root = Path(__file__).parent.parent
print("π Running Fast Tests Only")
print("=" * 30)
# Try to run a simple Python import test first
try:
result = subprocess.run([
sys.executable, "-c",
"import sys; sys.path.insert(0, 'src'); import praisonaiagents; print('β
Import successful')"
], cwd=project_root, capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print("β
Basic import test: PASSED")
print(result.stdout.strip())
else:
print("β Basic import test: FAILED")
if result.stderr:
print(result.stderr)
return 1
except Exception as e:
print(f"β Basic import test: ERROR - {e}")
return 1
# Run a subset of legacy tests
try:
result = subprocess.run([
sys.executable, "-c",
"""
import sys
sys.path.insert(0, 'src')
sys.path.insert(0, 'tests')
# Try to run basic_example
try:
from basic_example import basic_agent_example
result = basic_agent_example()
print(f'β
basic_example: {result}')
except Exception as e:
print(f'β basic_example failed: {e}')
# Try to run advanced_example
try:
from advanced_example import advanced_agent_example
result = advanced_agent_example()
print(f'β
advanced_example: {result}')
except Exception as e:
print(f'β advanced_example failed: {e}')
"""
], cwd=project_root, capture_output=True, text=True, timeout=60)
print("π Fast Example Tests:")
if result.stdout:
print(result.stdout)
if result.stderr:
print("Errors:", result.stderr)
return 0 if result.returncode == 0 else 1
except Exception as e:
print(f"β Fast tests failed: {e}")
return 1
def main():
"""Main entry point."""
import argparse
parser = argparse.ArgumentParser(description="Simple PraisonAI Test Runner")
parser.add_argument("--fast", action="store_true", help="Run only fast tests")
parser.add_argument("--unit", action="store_true", help="Run unit tests via subprocess")
args = parser.parse_args()
if args.fast:
return run_fast_tests()
elif args.unit:
# Run only unit tests
try:
result = subprocess.run([
sys.executable, "-m", "pytest", "tests/unit/", "-v", "--tb=short"
], cwd=Path(__file__).parent.parent)
return result.returncode
except Exception as e:
print(f"Failed to run unit tests: {e}")
return 1
else:
return run_tests_with_subprocess()
if __name__ == "__main__":
sys.exit(main())