forked from galbot-ioai/physics_sim_edu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·85 lines (70 loc) · 2.34 KB
/
run_tests.py
File metadata and controls
executable file
·85 lines (70 loc) · 2.34 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
#!/usr/bin/env python3
"""
Test runner script for physics_simulator.
Provides convenient commands for running different types of tests.
"""
import sys
import subprocess
import argparse
from pathlib import Path
def run_command(cmd, description):
"""Run a command and handle errors."""
print(f"\n{'='*60}")
print(f"Running: {description}")
print(f"Command: {' '.join(cmd)}")
print(f"{'='*60}")
try:
result = subprocess.run(cmd, check=True, capture_output=False)
print(f"✅ {description} completed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed with exit code {e.returncode}")
return False
except FileNotFoundError:
print(f"❌ Command not found. Make sure pytest is installed: pip install pytest")
return False
def main():
parser = argparse.ArgumentParser(description="Run physics_simulator tests")
parser.add_argument(
"--type",
choices=["unit", "integration", "all", "coverage"],
default="all",
help="Type of tests to run"
)
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()
# Base pytest command
base_cmd = ["python", "-m", "pytest"]
if args.verbose:
base_cmd.append("-v")
# Test type specific commands
if args.type == "unit":
cmd = base_cmd + ["-m", "unit", "tests/"]
description = "Unit Tests"
elif args.type == "integration":
cmd = base_cmd + ["-m", "integration", "tests/"]
description = "Integration Tests"
elif args.type == "coverage":
cmd = base_cmd + ["--cov=src/physics_simulator", "--cov-report=html", "tests/"]
description = "Coverage Tests"
else: # all
cmd = base_cmd + ["tests/"]
description = "All Tests"
if args.fast:
cmd.extend(["-m", "not slow"])
# Run the tests
success = run_command(cmd, description)
if args.type == "coverage" and success:
print(f"\n📊 Coverage report generated in: htmlcov/index.html")
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())