-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_conformance_report.py
More file actions
executable file
·288 lines (234 loc) · 10 KB
/
Copy pathgenerate_conformance_report.py
File metadata and controls
executable file
·288 lines (234 loc) · 10 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env python3
"""
Generate CONFORMANCE_REPORT.md from 3MF test suite results.
This script runs the conformance tests and generates a detailed report
with statistics and failure information.
"""
import subprocess
import sys
import json
import re
from datetime import datetime, timezone
from pathlib import Path
from typing import Dict, List, Tuple
def run_conformance_tests() -> str:
"""Run the conformance test summary and return output."""
print("Running conformance tests...")
try:
result = subprocess.run(
["cargo", "test", "--test", "conformance_tests", "summary",
"--", "--ignored", "--nocapture"],
capture_output=True,
text=True,
timeout=600 # 10 minute timeout
)
# Return combined output (stdout + stderr contains test results)
return result.stdout + result.stderr
except subprocess.TimeoutExpired:
print("ERROR: Test execution timed out")
sys.exit(1)
except Exception as e:
print(f"ERROR: Failed to run tests: {e}")
sys.exit(1)
def parse_test_output(output: str) -> Dict:
"""Parse the test output to extract statistics."""
# Initialize results
suites = {}
# Pattern to match suite results
# Example: "suite1_core_slice_prod Positive: 5/ 5 Negative: 3/ 3"
suite_pattern = re.compile(
r'(\S+)\s+Positive:\s+(\d+)/\s*(\d+)\s+Negative:\s+(\d+)/\s*(\d+)'
)
# Pattern to match total line
# Example: "TOTAL Positive: 45/ 50 Negative: 30/ 35"
total_pattern = re.compile(
r'TOTAL\s+Positive:\s+(\d+)/\s*(\d+)\s+Negative:\s+(\d+)/\s*(\d+)'
)
# Pattern to match overall conformance
# Example: "Overall conformance: 92.5% (74/80)"
conformance_pattern = re.compile(
r'Overall conformance:\s+([\d.]+)%\s+\((\d+)/(\d+)\)'
)
total_stats = None
overall_conformance = None
for line in output.split('\n'):
# Check for suite results
suite_match = suite_pattern.search(line)
if suite_match:
suite_name = suite_match.group(1)
pos_passed = int(suite_match.group(2))
pos_total = int(suite_match.group(3))
neg_passed = int(suite_match.group(4))
neg_total = int(suite_match.group(5))
suites[suite_name] = {
'positive': {'passed': pos_passed, 'total': pos_total},
'negative': {'passed': neg_passed, 'total': neg_total}
}
# Check for total
total_match = total_pattern.search(line)
if total_match:
total_stats = {
'positive': {
'passed': int(total_match.group(1)),
'total': int(total_match.group(2))
},
'negative': {
'passed': int(total_match.group(3)),
'total': int(total_match.group(4))
}
}
# Check for overall conformance
conf_match = conformance_pattern.search(line)
if conf_match:
overall_conformance = {
'percentage': float(conf_match.group(1)),
'passed': int(conf_match.group(2)),
'total': int(conf_match.group(3))
}
return {
'suites': suites,
'total': total_stats,
'overall': overall_conformance
}
def get_suite_description(suite_name: str) -> str:
"""Get a human-readable description for each suite."""
descriptions = {
'suite1_core_slice_prod': 'Core + Production + Slice Extensions',
'suite2_core_prod_matl': 'Core + Production + Materials Extensions',
'suite3_core': 'Core Specification (Basic)',
'suite4_core_slice': 'Core + Slice Extension',
'suite5_core_prod': 'Core + Production Extension',
'suite6_core_matl': 'Core + Materials Extension',
'suite7_beam': 'Beam Lattice Extension',
'suite8_secure': 'Secure Content Extension',
'suite9_core_ext': 'Core Extensions',
'suite10_boolean': 'Boolean Operations Extension',
'suite11_Displacement': 'Displacement Extension'
}
return descriptions.get(suite_name, suite_name)
def generate_report(results: Dict) -> str:
"""Generate the markdown report content."""
report = []
# Header
report.append("# 3MF Conformance Test Report")
report.append("")
report.append(f"**Generated:** {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')}")
report.append("")
# Overall Summary
report.append("## Overall Summary")
report.append("")
if results['overall']:
overall = results['overall']
report.append(f"**Overall Conformance:** {overall['percentage']:.1f}% ({overall['passed']}/{overall['total']} tests passed)")
if results['total']:
total = results['total']
pos = total['positive']
neg = total['negative']
report.append(f"- **Positive Tests:** {pos['passed']}/{pos['total']} passed ({pos['passed']/pos['total']*100 if pos['total'] > 0 else 0:.1f}%)")
report.append(f"- **Negative Tests:** {neg['passed']}/{neg['total']} passed ({neg['passed']/neg['total']*100 if neg['total'] > 0 else 0:.1f}%)")
report.append("")
# Results by Suite
report.append("## Results by Test Suite")
report.append("")
report.append("| Suite | Description | Positive Tests | Negative Tests | Total |")
report.append("|-------|-------------|----------------|----------------|-------|")
for suite_name, stats in sorted(results['suites'].items()):
description = get_suite_description(suite_name)
pos = stats['positive']
neg = stats['negative']
pos_status = f"{pos['passed']}/{pos['total']}"
neg_status = f"{neg['passed']}/{neg['total']}"
total_passed = pos['passed'] + neg['passed']
total_tests = pos['total'] + neg['total']
total_status = f"{total_passed}/{total_tests}"
# Add emoji indicators
pos_emoji = "✅" if pos['passed'] == pos['total'] else "⚠️" if pos['passed'] > 0 else "❌"
neg_emoji = "✅" if neg['passed'] == neg['total'] else "⚠️" if neg['passed'] > 0 else "❌"
total_emoji = "✅" if total_passed == total_tests else "⚠️" if total_passed > 0 else "❌"
report.append(
f"| {suite_name} | {description} | "
f"{pos_emoji} {pos_status} | {neg_emoji} {neg_status} | "
f"{total_emoji} {total_status} |"
)
report.append("")
# Detailed Suite Breakdown
report.append("## Detailed Suite Breakdown")
report.append("")
for suite_name, stats in sorted(results['suites'].items()):
description = get_suite_description(suite_name)
report.append(f"### {suite_name}")
report.append(f"*{description}*")
report.append("")
pos = stats['positive']
neg = stats['negative']
# Positive tests
if pos['total'] > 0:
pos_rate = (pos['passed'] / pos['total']) * 100
status = "✅ All passed" if pos['passed'] == pos['total'] else f"⚠️ {pos['total'] - pos['passed']} failed"
report.append(f"**Positive Tests:** {pos['passed']}/{pos['total']} ({pos_rate:.1f}%) - {status}")
else:
report.append("**Positive Tests:** No tests found")
# Negative tests
if neg['total'] > 0:
neg_rate = (neg['passed'] / neg['total']) * 100
status = "✅ All passed" if neg['passed'] == neg['total'] else f"⚠️ {neg['total'] - neg['passed']} failed"
report.append(f"**Negative Tests:** {neg['passed']}/{neg['total']} ({neg_rate:.1f}%) - {status}")
else:
report.append("**Negative Tests:** No tests found")
report.append("")
# Footer
report.append("---")
report.append("")
report.append("## About This Report")
report.append("")
report.append("This report is automatically generated by running the conformance test suite against the official 3MF Consortium test cases from [3MFConsortium/test_suites](https://github.com/3MFConsortium/test_suites).")
report.append("")
report.append("**Test Methodology:**")
report.append("- **Positive tests** validate that valid 3MF files parse successfully")
report.append("- **Negative tests** validate that invalid 3MF files are properly rejected")
report.append("")
report.append("**How to Regenerate:**")
report.append("```bash")
report.append("python3 generate_conformance_report.py")
report.append("```")
report.append("")
return '\n'.join(report)
def main():
"""Main entry point."""
print("=" * 60)
print("3MF Conformance Report Generator")
print("=" * 60)
print()
# Check if test_suites directory exists
if not Path("test_suites").exists():
print("ERROR: test_suites directory not found.")
print("Please run './run_conformance_tests.sh' first to clone the test suites.")
sys.exit(1)
# Run tests
output = run_conformance_tests()
print()
# Parse results
print("Parsing test results...")
results = parse_test_output(output)
if not results['suites']:
print("ERROR: Failed to parse test results. Output:")
print(output)
sys.exit(1)
print(f"Found results for {len(results['suites'])} test suites")
print()
# Generate report
print("Generating report...")
report_content = generate_report(results)
# Write to file
output_file = Path("CONFORMANCE_REPORT.md")
output_file.write_text(report_content)
print(f"✅ Report generated: {output_file}")
print()
# Print summary
if results['overall']:
overall = results['overall']
print("=" * 60)
print(f"Overall Conformance: {overall['percentage']:.1f}% ({overall['passed']}/{overall['total']})")
print("=" * 60)
if __name__ == "__main__":
main()