forked from daily-co/pipecat-cloud-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
185 lines (150 loc) · 5.62 KB
/
run_tests.py
File metadata and controls
185 lines (150 loc) · 5.62 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
#!/usr/bin/env python3
"""Test runner script for ToolProcessor behavior-driven specifications.
This script provides convenient ways to run the comprehensive test suite
with different configurations and reporting options.
"""
import sys
import subprocess
import argparse
from pathlib import Path
def run_command(cmd, description):
"""Run a command and handle errors."""
print(f"\n{'='*50}")
print(f"🧪 {description}")
print(f"{'='*50}")
print(f"Running: {' '.join(cmd)}")
print()
result = subprocess.run(cmd, capture_output=False)
if result.returncode != 0:
print(f"\n❌ {description} failed with exit code {result.returncode}")
return False
else:
print(f"\n✅ {description} completed successfully")
return True
def install_dependencies():
"""Install test dependencies."""
cmd = [sys.executable, "-m", "pip", "install", "-r", "tests/requirements.txt"]
return run_command(cmd, "Installing test dependencies")
def run_tests(
coverage=True, verbose=False, parallel=False, html_report=False, filter_expr=None
):
"""Run the test suite with specified options."""
cmd = [sys.executable, "-m", "pytest"]
if verbose:
cmd.append("-v")
if coverage:
cmd.extend(["--cov=tool_processor", "--cov-report=term-missing"])
if html_report:
cmd.append("--cov-report=html")
if parallel:
cmd.extend(["-n", "auto"])
if filter_expr:
cmd.extend(["-k", filter_expr])
cmd.append("tests/")
description = "Running ToolProcessor behavior-driven specifications"
if filter_expr:
description += f" (filtered: {filter_expr})"
return run_command(cmd, description)
def run_linting():
"""Run code quality checks."""
print("\n🔍 Running code quality checks...")
# Check if flake8 is available
try:
subprocess.run(
[sys.executable, "-m", "flake8", "--version"],
capture_output=True,
check=True,
)
cmd = [sys.executable, "-m", "flake8", "tool_processor.py", "tests/"]
if not run_command(cmd, "Code style check (flake8)"):
return False
except (subprocess.CalledProcessError, FileNotFoundError):
print("⚠️ flake8 not installed, skipping style check")
# Check if mypy is available
try:
subprocess.run(
[sys.executable, "-m", "mypy", "--version"], capture_output=True, check=True
)
cmd = [sys.executable, "-m", "mypy", "tool_processor.py"]
if not run_command(cmd, "Type check (mypy)"):
return False
except (subprocess.CalledProcessError, FileNotFoundError):
print("⚠️ mypy not installed, skipping type check")
return True
def main():
"""Main test runner function."""
parser = argparse.ArgumentParser(
description="Run ToolProcessor behavior-driven specifications",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python run_tests.py # Run all tests with coverage
python run_tests.py --no-coverage # Run tests without coverage
python run_tests.py --verbose # Run with verbose output
python run_tests.py --parallel # Run tests in parallel
python run_tests.py --html # Generate HTML coverage report
python run_tests.py --filter "session" # Run only session-related tests
python run_tests.py --install-deps # Install test dependencies
python run_tests.py --lint # Run code quality checks
python run_tests.py --all # Run everything (deps, lint, tests)
""",
)
parser.add_argument(
"--install-deps", action="store_true", help="Install test dependencies"
)
parser.add_argument(
"--no-coverage", action="store_true", help="Skip coverage reporting"
)
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
parser.add_argument(
"--parallel", "-n", action="store_true", help="Run tests in parallel"
)
parser.add_argument(
"--html", action="store_true", help="Generate HTML coverage report"
)
parser.add_argument("--filter", "-k", help="Filter tests by expression")
parser.add_argument("--lint", action="store_true", help="Run code quality checks")
parser.add_argument(
"--all",
action="store_true",
help="Run everything: install deps, lint, and tests",
)
args = parser.parse_args()
success = True
# Handle --all flag
if args.all:
args.install_deps = True
args.lint = True
args.html = True
# Install dependencies if requested
if args.install_deps:
if not install_dependencies():
success = False
# Run linting if requested
if args.lint and success:
if not run_linting():
success = False
# Run tests if no specific action requested or if --all
if success and (not any([args.install_deps, args.lint]) or args.all):
coverage = not args.no_coverage
if not run_tests(
coverage=coverage,
verbose=args.verbose,
parallel=args.parallel,
html_report=args.html,
filter_expr=args.filter,
):
success = False
# Final summary
print(f"\n{'='*50}")
if success:
print("🎉 All operations completed successfully!")
if args.html:
print("📊 HTML coverage report: htmlcov/index.html")
else:
print("💥 Some operations failed!")
return 1
print(f"{'='*50}\n")
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())