-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
140 lines (108 loc) · 3.93 KB
/
Copy pathrun_tests.py
File metadata and controls
140 lines (108 loc) · 3.93 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
#!/usr/bin/env python3
"""
Test runner script for AINative Python SDK
Runs the complete test suite with coverage reporting and provides
detailed output about test results and coverage.
"""
import os
import sys
import subprocess
import argparse
from pathlib import Path
def run_command(command, description=""):
"""Run a command and return the result."""
print(f"\n{'='*60}")
if description:
print(f"Running: {description}")
print(f"Command: {command}")
print('='*60)
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.stdout:
print("STDOUT:")
print(result.stdout)
if result.stderr:
print("STDERR:")
print(result.stderr)
print(f"Exit code: {result.returncode}")
return result
def main():
parser = argparse.ArgumentParser(description="Run AINative SDK tests")
parser.add_argument("--unit-only", action="store_true", help="Run only unit tests")
parser.add_argument("--integration-only", action="store_true", help="Run only integration tests")
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("--fast", action="store_true", help="Skip slow tests")
args = parser.parse_args()
# Change to project directory
project_dir = Path(__file__).parent
os.chdir(project_dir)
print(f"Running tests from: {project_dir}")
print(f"Python version: {sys.version}")
# Install dependencies if needed
print("\nInstalling dependencies...")
install_result = run_command(
"pip install -e .[dev]",
"Installing package in development mode"
)
if install_result.returncode != 0:
print("Failed to install dependencies")
return 1
# Build pytest command
pytest_cmd_parts = ["python", "-m", "pytest"]
# Add verbosity
if args.verbose:
pytest_cmd_parts.append("-v")
else:
pytest_cmd_parts.append("-q")
# Add coverage options (unless disabled)
if not args.no_coverage:
pytest_cmd_parts.extend([
"--cov=ainative",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=90"
])
# Add test markers
marker_conditions = []
if args.fast:
marker_conditions.append("not slow")
if args.unit_only:
pytest_cmd_parts.append("tests/unit/")
elif args.integration_only:
pytest_cmd_parts.append("tests/integration/")
marker_conditions.append("integration")
else:
pytest_cmd_parts.append("tests/")
# Add marker conditions
if marker_conditions:
pytest_cmd_parts.extend(["-m", " and ".join(marker_conditions)])
# Additional pytest options
pytest_cmd_parts.extend([
"--tb=short",
"--strict-markers",
"--durations=10" # Show 10 slowest tests
])
pytest_cmd = " ".join(pytest_cmd_parts)
# Run tests
test_result = run_command(pytest_cmd, "Running test suite")
# Generate test summary
print(f"\n{'='*60}")
print("TEST SUMMARY")
print('='*60)
if test_result.returncode == 0:
print("✅ All tests passed!")
else:
print("❌ Some tests failed!")
# Coverage summary
if not args.no_coverage and test_result.returncode == 0:
print("\nCoverage report generated:")
print(f" - Terminal: (shown above)")
print(f" - HTML: {project_dir}/htmlcov/index.html")
print(f" - XML: {project_dir}/coverage.xml")
# Additional information
print(f"\nTest files location: {project_dir}/tests/")
print(f"Configuration: {project_dir}/pytest.ini")
return test_result.returncode
if __name__ == "__main__":
sys.exit(main())