-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
151 lines (119 loc) · 4.55 KB
/
run_tests.py
File metadata and controls
151 lines (119 loc) · 4.55 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
#!/usr/bin/env python3
"""
starward Test Runner
A clean test runner with multiple output modes for the starward test suite.
Usage:
python run_tests.py # Quick run (default)
python run_tests.py -v # Verbose output
python run_tests.py --full # Full output with coverage
python run_tests.py --module time # Run specific module tests
python run_tests.py --failed # Re-run failed tests only
"""
import subprocess
import sys
import argparse
from pathlib import Path
def main():
parser = argparse.ArgumentParser(
description="starward Test Runner",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python run_tests.py Quick test run
python run_tests.py -v Verbose output
python run_tests.py --full Full coverage report
python run_tests.py --module sun Test sun module only
python run_tests.py --module precision Test precision module
python run_tests.py -k "parse" Run tests matching 'parse'
python run_tests.py --failed Re-run failed tests
python run_tests.py --fast Skip slow tests
"""
)
parser.add_argument('-v', '--verbose', action='store_true',
help='Show verbose test output')
parser.add_argument('--full', action='store_true',
help='Full run with coverage report')
parser.add_argument('--module', '-m', type=str,
help='Run tests for specific module (e.g., time, sun, angles)')
parser.add_argument('--failed', action='store_true',
help='Re-run only failed tests from last run')
parser.add_argument('--fast', action='store_true',
help='Skip slow tests')
parser.add_argument('-k', type=str,
help='Run tests matching expression')
parser.add_argument('--watch', action='store_true',
help='Watch mode - re-run on file changes')
parser.add_argument('extra', nargs='*',
help='Additional pytest arguments')
args = parser.parse_args()
# Build pytest command
cmd = ['python', '-m', 'pytest']
# Output mode
if args.full:
cmd.extend(['-v', '--cov=starward', '--cov-report=term-missing', '--cov-report=html'])
print_header("Full Test Run with Coverage")
elif args.verbose:
cmd.append('-v')
print_header("Verbose Test Run")
else:
cmd.append('-q')
print_header("Quick Test Run")
# Test selection
if args.module:
module_path = find_module_tests(args.module)
if module_path:
cmd.append(str(module_path))
else:
print(f"Error: No tests found for module '{args.module}'")
print(f"Available modules: {', '.join(list_modules())}")
sys.exit(1)
if args.failed:
cmd.append('--lf')
if args.fast:
cmd.extend(['-m', 'not slow'])
if args.k:
cmd.extend(['-k', args.k])
# Add extra arguments
cmd.extend(args.extra)
# Run tests
print(f" Command: {' '.join(cmd)}\n")
print("─" * 60)
result = subprocess.run(cmd)
return result.returncode
def print_header(title: str):
"""Print a nice header."""
print()
print("╭" + "─" * 58 + "╮")
print(f"│ ✦ {title:<53} │")
print("╰" + "─" * 58 + "╯")
print()
def find_module_tests(module: str) -> Path | None:
"""Find test file for a given module."""
tests_dir = Path(__file__).parent / 'tests'
# Check core modules
core_test = tests_dir / 'core' / f'test_{module}.py'
if core_test.exists():
return core_test
# Check CLI tests
cli_test = tests_dir / 'cli' / f'test_{module}.py'
if cli_test.exists():
return cli_test
# Check output tests
output_test = tests_dir / 'output' / f'test_{module}.py'
if output_test.exists():
return output_test
# Check for partial match
for test_file in tests_dir.rglob('test_*.py'):
if module.lower() in test_file.stem.lower():
return test_file
return None
def list_modules() -> list[str]:
"""List available test modules."""
tests_dir = Path(__file__).parent / 'tests'
modules = []
for test_file in tests_dir.rglob('test_*.py'):
name = test_file.stem.replace('test_', '')
modules.append(name)
return sorted(set(modules))
if __name__ == '__main__':
sys.exit(main())