-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·128 lines (106 loc) · 4.01 KB
/
run_tests.py
File metadata and controls
executable file
·128 lines (106 loc) · 4.01 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
#!/usr/bin/env python3
"""
Test runner for Stack-Wise test suite.
Usage:
python tests/run_tests.py # Run all tests
python tests/run_tests.py --unit # Run unit tests only
python tests/run_tests.py --integration # Run integration tests only
python tests/run_tests.py --examples # Run example tests only
python tests/run_tests.py --verbose # Verbose output
"""
import sys
import os
import subprocess
import argparse
from pathlib import Path
# Add src directory to Python path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
def run_tests(test_type=None, verbose=False):
"""Run tests based on type."""
test_dir = Path(__file__).parent
if test_type == "unit":
test_path = test_dir / "unit"
elif test_type == "integration":
test_path = test_dir / "integration"
elif test_type == "examples":
test_path = test_dir / "examples"
else:
test_path = test_dir
# Find all test files
test_files = []
for pattern in ["test_*.py", "*_test.py"]:
test_files.extend(test_path.glob(pattern))
if test_type is None: # If running all tests, also check subdirectories
for subdir in ["unit", "integration", "examples"]:
subdir_path = test_path / subdir
if subdir_path.exists():
test_files.extend(subdir_path.glob(pattern))
if not test_files:
print(f"No test files found in {test_path}")
return True # Empty test directories are OK
# Run tests
success = True
for test_file in test_files:
print(f"\n{'='*60}")
print(f"Running {test_file.name}")
print(f"{'='*60}")
try:
# Run the test file with proper Python path
env = os.environ.copy()
src_path = str(Path(__file__).parent.parent / "src")
if 'PYTHONPATH' in env:
env['PYTHONPATH'] = src_path + os.pathsep + env['PYTHONPATH']
else:
env['PYTHONPATH'] = src_path
result = subprocess.run([
sys.executable, str(test_file)
], capture_output=True, text=True, env=env)
if result.returncode == 0:
print(f"✅ {test_file.name} passed")
if verbose and result.stdout:
print("STDOUT:")
print(result.stdout)
else:
print(f"❌ {test_file.name} failed")
print("STDERR:")
print(result.stderr)
if result.stdout:
print("STDOUT:")
print(result.stdout)
success = False
except Exception as e:
print(f"❌ {test_file.name} failed with exception: {e}")
success = False
return success
def main():
"""Main test runner."""
parser = argparse.ArgumentParser(description="Run Stack-Wise tests")
parser.add_argument("--unit", action="store_true", help="Run unit tests only")
parser.add_argument("--integration", action="store_true", help="Run integration tests only")
parser.add_argument("--examples", action="store_true", help="Run example tests only")
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
args = parser.parse_args()
# Determine test type
test_type = None
if args.unit:
test_type = "unit"
elif args.integration:
test_type = "integration"
elif args.examples:
test_type = "examples"
print("🧪 Stack-Wise Test Suite")
print("=" * 60)
if test_type:
print(f"Running {test_type} tests...")
else:
print("Running all tests...")
success = run_tests(test_type, args.verbose)
print("\n" + "=" * 60)
if success:
print("🎉 All tests passed!")
sys.exit(0)
else:
print("❌ Some tests failed!")
sys.exit(1)
if __name__ == "__main__":
main()