-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
159 lines (123 loc) · 4.45 KB
/
Copy pathrun_tests.py
File metadata and controls
159 lines (123 loc) · 4.45 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
152
153
154
155
156
157
158
159
"""
Script to run all tests in the chapter16 package.
This script runs the comprehensive test suite to verify the correctness
and performance of the IoT network optimization algorithms.
"""
import sys
import os
import subprocess
import time
def run_tests():
"""Run all tests using pytest."""
print("Chapter 16 IoT Network Optimization - Test Runner")
print("="*60)
print("Running comprehensive test suite...")
print("="*60)
try:
start_time = time.time()
# Run pytest with verbose output
result = subprocess.run([
sys.executable, "-m", "pytest",
"tests/",
"-v",
"--tb=short",
"--durations=10"
], capture_output=True, text=True, cwd=os.getcwd())
end_time = time.time()
print("Test Results:")
print("="*60)
if result.returncode == 0:
print("ALL TESTS PASSED")
else:
print("SOME TESTS FAILED")
print(f"Execution time: {end_time - start_time:.2f} seconds")
if result.stdout:
print("\nTest Output:")
print(result.stdout)
if result.stderr:
print("\nError Output:")
print(result.stderr)
return result.returncode == 0
except Exception as e:
print(f"EXCEPTION: {e}")
return False
def run_individual_tests():
"""Run individual test modules."""
test_modules = [
"tests.test_algorithms"
]
print("\n" + "="*60)
print("INDIVIDUAL TEST MODULES")
print("="*60)
for module in test_modules:
print(f"\nRunning {module}...")
try:
result = subprocess.run([
sys.executable, "-m", "pytest",
module,
"-v"
], capture_output=True, text=True, cwd=os.getcwd())
if result.returncode == 0:
print(f"{module} PASSED")
else:
print(f"{module} FAILED")
if result.stdout:
print(result.stdout)
if result.stderr:
print(result.stderr)
except Exception as e:
print(f"EXCEPTION in {module}: {e}")
def check_dependencies():
"""Check if required dependencies are installed."""
print("Checking dependencies...")
required_packages = [
"numpy", "matplotlib", "networkx", "scipy",
"pandas", "plotly", "pytest"
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
print(f"{package} - OK")
except ImportError:
print(f"{package} - MISSING")
missing_packages.append(package)
if missing_packages:
print(f"\nMissing packages: {', '.join(missing_packages)}")
print("Please install them using: pip install -r requirements.txt")
return False
print("All dependencies available")
return True
def main():
"""Main function to run all tests."""
print("Chapter 16 IoT Network Optimization - Test Suite")
print("="*60)
# Check dependencies
if not check_dependencies():
print("\nCannot run tests due to missing dependencies")
return
# Run main test suite
success = run_tests()
# Run individual test modules
run_individual_tests()
# Summary
print("\n" + "="*60)
print("TEST SUMMARY")
print("="*60)
if success:
print("All tests completed successfully!")
print("\nThe IoT network optimization package is working correctly.")
print("You can now use the algorithms and examples with confidence.")
else:
print("Some tests failed!")
print("\nPlease check the error messages above and fix any issues.")
print("The package may not work correctly until all tests pass.")
print("\nTest coverage includes:")
print(" - MST algorithms (Kruskal's, Prim's, Constrained)")
print(" - Steiner Tree algorithms")
print(" - Graph generation utilities")
print(" - Network visualization")
print(" - Edge cases and error handling")
print(" - Performance validation")
if __name__ == "__main__":
main()