-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
94 lines (74 loc) · 3.2 KB
/
run_tests.py
File metadata and controls
94 lines (74 loc) · 3.2 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
#!/usr/bin/env python
"""
Test runner script for Pokemon middleware.
Provides convenient ways to run different test suites.
"""
import os
import sys
import subprocess
import argparse
def run_command(command, description):
"""Run a command and handle errors."""
print(f"\n{'='*60}")
print(f"Running: {description}")
print(f"Command: {command}")
print(f"{'='*60}")
result = subprocess.run(command, shell=True)
if result.returncode != 0:
print(f"❌ {description} failed with exit code {result.returncode}")
return False
else:
print(f"✅ {description} completed successfully")
return True
def main():
"""Main test runner function."""
parser = argparse.ArgumentParser(description='Run Pokemon middleware tests')
parser.add_argument('--all', action='store_true', help='Run all tests')
parser.add_argument('--services', action='store_true', help='Run service tests')
parser.add_argument('--factories', action='store_true', help='Run factory tests')
parser.add_argument('--entities', action='store_true', help='Run entity tests')
parser.add_argument('--repositories', action='store_true', help='Run repository tests')
parser.add_argument('--coverage', action='store_true', help='Run with coverage report')
parser.add_argument('--verbose', '-v', action='store_true', help='Verbose output')
args = parser.parse_args()
# Set Django settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.local')
# Base command
base_cmd = "python manage.py test"
if args.verbose:
base_cmd += " --verbosity=2"
success = True
if args.coverage:
# Install coverage if not available
print("Installing coverage...")
subprocess.run("pip install coverage", shell=True)
base_cmd = f"coverage run --source='middleware' manage.py test"
if args.all or (not any([args.services, args.factories, args.entities, args.repositories])):
# Run all tests
success &= run_command(f"{base_cmd} middleware.tests", "All tests")
else:
# Run specific test suites
if args.services:
success &= run_command(f"{base_cmd} middleware.tests.test_services", "Service tests")
if args.factories:
success &= run_command(f"{base_cmd} middleware.tests.test_factories", "Factory tests")
if args.entities:
success &= run_command(f"{base_cmd} middleware.tests.test_entities", "Entity tests")
if args.repositories:
success &= run_command(f"{base_cmd} middleware.tests.test_repositories", "Repository tests")
if args.coverage:
print("\n" + "="*60)
print("Generating coverage report...")
print("="*60)
# Generate coverage report
run_command("coverage report", "Coverage report")
run_command("coverage html", "HTML coverage report")
print("\n📊 Coverage report generated in htmlcov/index.html")
if success:
print("\n🎉 All tests completed successfully!")
sys.exit(0)
else:
print("\n❌ Some tests failed!")
sys.exit(1)
if __name__ == '__main__':
main()