-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·150 lines (119 loc) · 4.41 KB
/
Copy pathrun_tests.py
File metadata and controls
executable file
·150 lines (119 loc) · 4.41 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
#!/usr/bin/env python3
"""
Test runner script for deploy.py
This script provides different test execution modes:
- Unit tests only
- Integration tests only
- All tests
- Coverage report
- Linting and code quality checks
"""
import sys
import subprocess
import argparse
import os
def run_command(cmd, description=""):
"""Run a command and handle errors"""
if description:
print(f"\n{'='*60}")
print(f"Running: {description}")
print(f"{'='*60}")
print(f"Executing: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=False)
if result.returncode != 0:
print(f"❌ {description} failed with exit code {result.returncode}")
return False
else:
print(f"✅ {description} completed successfully")
return True
def run_unit_tests():
"""Run only unit tests"""
cmd = ["python", "-m", "pytest",
"test_deploy.py::TestArgumentParsing",
"test_deploy.py::TestCommandExecution",
"test_deploy.py::TestDeploymentFunctions",
"test_deploy.py::TestMainFunction",
"test_deploy.py::TestErrorHandling",
"test_deploy.py::TestUtilities",
"-v"]
return run_command(cmd, "Unit Tests")
def run_integration_tests():
"""Run only integration tests"""
cmd = ["python", "-m", "pytest", "test_deploy.py::TestIntegration", "-v"]
return run_command(cmd, "Integration Tests")
def run_all_tests():
"""Run all tests"""
cmd = ["python", "-m", "pytest", "test_deploy.py", "-v"]
return run_command(cmd, "All Tests")
def run_coverage():
"""Run tests with coverage report"""
cmd = ["python", "-m", "pytest",
"test_deploy.py",
"--cov=deploy",
"--cov-report=html",
"--cov-report=term-missing",
"-v"]
return run_command(cmd, "Coverage Report")
def run_linting():
"""Run code quality checks"""
success = True
# Check if tools are available
tools = ["black", "flake8", "mypy"]
available_tools = []
for tool in tools:
try:
subprocess.run([tool, "--version"], capture_output=True, check=True)
available_tools.append(tool)
except (subprocess.CalledProcessError, FileNotFoundError):
print(f"⚠️ {tool} not available, skipping...")
if "black" in available_tools:
if not run_command(["black", "--check", "deploy.py", "test_deploy.py"],
"Code formatting check (black)"):
success = False
if "flake8" in available_tools:
if not run_command(["flake8", "deploy.py", "test_deploy.py"],
"Code style check (flake8)"):
success = False
if "mypy" in available_tools:
if not run_command(["mypy", "deploy.py"], "Type checking (mypy)"):
success = False
return success
def main():
parser = argparse.ArgumentParser(description="Test runner for deploy.py")
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("--coverage", action="store_true", help="Run tests with coverage")
parser.add_argument("--lint", action="store_true", help="Run linting and code quality checks")
parser.add_argument("--all", action="store_true", help="Run all tests and checks")
args = parser.parse_args()
# Check if pytest is available
try:
subprocess.run(["python", "-m", "pytest", "--version"],
capture_output=True, check=True)
except (subprocess.CalledProcessError, FileNotFoundError):
print("❌ pytest is not available. Please install it with:")
print(" pip install -r requirements-test.txt")
sys.exit(1)
success = True
if args.unit:
success &= run_unit_tests()
elif args.integration:
success &= run_integration_tests()
elif args.coverage:
success &= run_coverage()
elif args.lint:
success &= run_linting()
elif args.all:
success &= run_all_tests()
success &= run_linting()
else:
# Default: run all tests
success &= run_all_tests()
if success:
print("\n🎉 All tests passed!")
sys.exit(0)
else:
print("\n❌ Some tests failed!")
sys.exit(1)
if __name__ == "__main__":
main()