-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·110 lines (89 loc) · 2.93 KB
/
run_tests.py
File metadata and controls
executable file
·110 lines (89 loc) · 2.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
#!/usr/bin/env python3
"""
Test Runner for Binary Math Education System
Quick test runner with options for different test modes.
"""
import sys
import unittest
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / 'src'))
def run_all_tests(verbose=True):
"""Run all tests"""
loader = unittest.TestLoader()
suite = loader.discover('tests', pattern='test_*.py')
runner = unittest.TextTestRunner(verbosity=2 if verbose else 1)
result = runner.run(suite)
return result.wasSuccessful()
def run_module_tests(module_name, verbose=True):
"""Run tests for a specific module"""
loader = unittest.TestLoader()
module_map = {
'binary': 'tests.test_binary_basics',
'gates': 'tests.test_logic_gates',
'truth': 'tests.test_truth_tables',
'practice': 'tests.test_practice_generator',
'tutor': 'tests.test_interactive_tutor'
}
test_module = module_map.get(module_name)
if not test_module:
print(f"Unknown module: {module_name}")
print(f"Available modules: {', '.join(module_map.keys())}")
return False
try:
suite = loader.loadTestsFromName(test_module)
runner = unittest.TextTestRunner(verbosity=2 if verbose else 1)
result = runner.run(suite)
return result.wasSuccessful()
except Exception as e:
print(f"Error running tests: {e}")
return False
def show_help():
"""Display help information"""
help_text = """
Binary Math Education System - Test Runner
Usage:
python3 run_tests.py [option]
Options:
(none) Run all tests (verbose)
all Run all tests
binary Run binary basics tests only
gates Run logic gates tests only
truth Run truth tables tests only
practice Run practice generator tests only
tutor Run interactive tutor tests only
quick Run all tests (non-verbose)
help Show this help message
Examples:
python3 run_tests.py
python3 run_tests.py binary
python3 run_tests.py quick
"""
print(help_text)
def main():
"""Main entry point"""
args = sys.argv[1:]
if not args or args[0] == 'all':
print("Running all tests...\n")
success = run_all_tests(verbose=True)
elif args[0] == 'quick':
print("Running all tests (quick mode)...\n")
success = run_all_tests(verbose=False)
elif args[0] == 'help':
show_help()
return
elif args[0] in ['binary', 'gates', 'truth', 'practice', 'tutor']:
print(f"Running {args[0]} tests...\n")
success = run_module_tests(args[0], verbose=True)
else:
print(f"Unknown option: {args[0]}")
show_help()
sys.exit(1)
if success:
print("\n✅ All tests passed!")
sys.exit(0)
else:
print("\n❌ Some tests failed!")
sys.exit(1)
if __name__ == '__main__':
main()