-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
120 lines (99 loc) · 4.39 KB
/
run_tests.py
File metadata and controls
120 lines (99 loc) · 4.39 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
"""
COM Framework Test Runner
This script runs the test suite for the COM Framework and generates a test report.
"""
import unittest
import sys
import os
import time
from datetime import datetime
# Add the current directory to the path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import the test module
from com_tests import (
TestLZModule,
TestOctaveModule,
TestVisualizationModule,
TestMathematicalAnalysisModule,
TestPatternRecognitionModule,
TestStatisticalAnalysisModule
)
def run_tests_with_report():
"""Run all tests and generate a detailed report."""
# Create output directory for test results
os.makedirs('test_results', exist_ok=True)
# Open report file
report_path = os.path.join('test_results', f'test_report_{datetime.now().strftime("%Y%m%d_%H%M%S")}.txt')
with open(report_path, 'w') as report_file:
# Write report header
report_file.write("COM Framework Test Report\n")
report_file.write("=======================\n\n")
report_file.write(f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n")
# Create test suite
test_suite = unittest.TestSuite()
# Add test cases
test_classes = [
TestLZModule,
TestOctaveModule,
TestVisualizationModule,
TestMathematicalAnalysisModule,
TestPatternRecognitionModule,
TestStatisticalAnalysisModule
]
# Track overall statistics
total_tests = 0
total_passed = 0
total_failed = 0
total_errors = 0
# Run tests for each module
for test_class in test_classes:
report_file.write(f"\nTesting {test_class.__name__}\n")
report_file.write("-" * (len(f"Testing {test_class.__name__}") + 1) + "\n")
# Create test suite for this class
class_suite = unittest.TestLoader().loadTestsFromTestCase(test_class)
total_tests += class_suite.countTestCases()
# Create a result collector
result = unittest.TestResult()
# Run tests and time execution
start_time = time.time()
class_suite.run(result)
end_time = time.time()
# Update statistics
passed = result.testsRun - len(result.failures) - len(result.errors)
total_passed += passed
total_failed += len(result.failures)
total_errors += len(result.errors)
# Write results to report
report_file.write(f"Tests run: {result.testsRun}\n")
report_file.write(f"Passed: {passed}\n")
report_file.write(f"Failed: {len(result.failures)}\n")
report_file.write(f"Errors: {len(result.errors)}\n")
report_file.write(f"Time: {end_time - start_time:.2f} seconds\n\n")
# Write details of failures
if result.failures:
report_file.write("Failures:\n")
for i, (test, traceback) in enumerate(result.failures):
report_file.write(f" {i+1}. {test}\n")
report_file.write(f" {traceback.split('Traceback')[0].strip()}\n\n")
# Write details of errors
if result.errors:
report_file.write("Errors:\n")
for i, (test, traceback) in enumerate(result.errors):
report_file.write(f" {i+1}. {test}\n")
report_file.write(f" {traceback.split('Traceback')[0].strip()}\n\n")
# Write summary
report_file.write("\nSummary\n")
report_file.write("=======\n")
report_file.write(f"Total tests: {total_tests}\n")
report_file.write(f"Passed: {total_passed} ({total_passed/total_tests*100:.1f}%)\n")
report_file.write(f"Failed: {total_failed} ({total_failed/total_tests*100:.1f}%)\n")
report_file.write(f"Errors: {total_errors} ({total_errors/total_tests*100:.1f}%)\n")
# Overall result
if total_failed == 0 and total_errors == 0:
report_file.write("\nOVERALL RESULT: PASS\n")
else:
report_file.write("\nOVERALL RESULT: FAIL\n")
return report_path
if __name__ == "__main__":
report_path = run_tests_with_report()
print(f"Test report generated: {report_path}")