-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformat_markdown.py
206 lines (154 loc) · 7.67 KB
/
format_markdown.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Authors:
# - Stefan Profanter ([email protected])
#
import logging
import codecs
import os
from result import TestResult
from status import ImplementationStatus
logger = logging.getLogger(__name__)
testResultIconMap = {
TestResult.ERROR: ':x:',
TestResult.WARNING: ':warning:',
TestResult.NOT_IMPLEMENTED: ':heavy_minus_sign:',
TestResult.SKIPPED: ':white_circle:',
TestResult.NOT_SUPPORTED: ':radio_button:',
TestResult.OK: ':heavy_check_mark:',
TestResult.BACK_TRACE: ':collision:',
TestResult.UNKNOWN: ':grey_question:',
}
statusIconMap = {
ImplementationStatus.UNKNOWN: ':grey_question:',
ImplementationStatus.NOT_IMPLEMENTED: ':new_moon:',
ImplementationStatus.BEING_IMPLEMENTED: ':waning_crescent_moon:',
ImplementationStatus.INCUBATING: ':last_quarter_moon:',
ImplementationStatus.STABLE: ':full_moon:',
ImplementationStatus.CERTIFIED: ':heavy_check_mark:',
}
def write_format_markdown(profiles, selection, results, outputFilePath, templateHeaderFile, templateFooterFile):
logger.info("Writing Markdown output to file {}".format(outputFilePath))
outfilemd = codecs.open(outputFilePath, r"w+", encoding='utf-8')
def writemd(line):
print(line, end='\n', file=outfilemd)
headerFile = codecs.open(templateHeaderFile.name, "r", encoding='utf-8')
print(headerFile.read(), file=outfilemd)
headerFile.close()
writemd("## Explanation\n")
writemd("\nThe following tables use these signs to indicate the implementation status:")
writemd(" * Unknown = {}".format(statusIconMap[ImplementationStatus.UNKNOWN]))
writemd(" * Not Implemented = {}".format(statusIconMap[ImplementationStatus.NOT_IMPLEMENTED]))
writemd(" * Being Implemented = {}".format(statusIconMap[ImplementationStatus.BEING_IMPLEMENTED]))
writemd(" * Incubating = {}".format(statusIconMap[ImplementationStatus.INCUBATING]))
writemd(" * Stable = {}".format(statusIconMap[ImplementationStatus.STABLE]))
writemd(" * Certified = {}".format(statusIconMap[ImplementationStatus.CERTIFIED]))
writemd("\nThe following tables use these signs to indicate the test results:")
writemd(" * Error = {}".format(testResultIconMap[TestResult.ERROR]))
writemd(" * Warning = {}".format(testResultIconMap[TestResult.WARNING]))
writemd(" * Not Implemented = {}".format(testResultIconMap[TestResult.NOT_IMPLEMENTED]))
writemd(" * Skipped = {}".format(testResultIconMap[TestResult.SKIPPED]))
writemd(" * Not Supported = {}".format(testResultIconMap[TestResult.NOT_SUPPORTED]))
writemd(" * OK = {}".format(testResultIconMap[TestResult.OK]))
writemd(" * Back Trace = {}".format(testResultIconMap[TestResult.BACK_TRACE]))
writemd(" * No test results = {}".format(testResultIconMap[TestResult.UNKNOWN]))
writemd("")
writemd("Project Info:")
writemd(" * Type = {}".format(profiles.projectInfo.type))
writemd(" * Profile = {}".format(profiles.projectInfo.profile))
writemd(" * Version = {}".format(profiles.projectInfo.version))
#writeSelectedUnits(writemd, selection)
#writemd("\n")
writeAllCategories(writemd, profiles)
writemd("\n")
writeAllProfiles(writemd, profiles)
writemd("\n")
footerFile = codecs.open(templateFooterFile.name, "r", encoding='utf-8')
print(footerFile.read(), file=outfilemd)
footerFile.close()
outfilemd.flush()
os.fsync(outfilemd)
outfilemd.close()
def writeSelectedUnits(writemd, selection):
writemd("\n## Summarized Results for tested Conformance Units\n")
writemd("Tested with version: `{}`\n".format(selection.projectInfo.version))
writemd("| Status | Result | Conformance Group | Conformance Unit |")
writemd("|--------|--------|---------------------|---------------------|")
for selGroup in selection.conformanceGroups:
writemd("| {status} | {result} | {group} | |".format(
group=selGroup.group.name,
result=testResultIconMap[selGroup.result.testresult],
status=statusIconMap[selGroup.group.getImplementationStatus()]
))
for selUnit in selGroup.selectedUnits:
writemd("| | | {status} | {result} {unit} |".format(
unit=selUnit.unit.name,
result=testResultIconMap[selUnit.result.testresult],
status=statusIconMap[selUnit.unit.implementationStatus]
))
def writeAllCategories(writemd, profiles):
writemd("\n## Grouped by Category\n")
writemd("| Status | Result | Category | Conformance Unit |")
writemd("|--------|----------|----------------------|------------------|")
for category in profiles.categories:
writemd("| {status} | {result} | {category} | |".format(
category=category.name,
result=testResultIconMap[category.getResult()],
status=statusIconMap[category.getImplementationStatus()]
))
for group in profiles.conformanceGroups:
for unit in group.conformanceUnits:
if not unit.category == category:
continue
writemd("| | | {status} | {result} {unit} |".format(
unit=unit.name,
result=testResultIconMap[unit.getResult()],
status=statusIconMap[unit.implementationStatus]
))
def writeAllProfiles(writemd, profiles):
writemd("\n## Grouped by Conformance Groups\n")
writemd("| Status | Result | Conformance Group | Conformance Unit |")
writemd("|--------|----------|----------------------|------------------|")
for group in profiles.conformanceGroups:
writemd("| {status} | {result} | {group} | |".format(
group=group.name,
result=testResultIconMap[group.getResult()],
status=statusIconMap[group.getImplementationStatus()]
))
for unit in group.conformanceUnits:
writemd("| | | {status} | {result} {unit} |".format(
unit=unit.name,
result=testResultIconMap[unit.getResult()],
status=statusIconMap[unit.implementationStatus]
))
writemd("\n## Grouped by Profiles and Facets\n")
writemd(" Units writen in *italics* are optional within that profile\n\n")
writemd("| Status | Result | Profile | Type | Name |")
writemd("|--------|----------|------------|------|------|")
for profile in profiles.profiles:
writemd("| {status} | {result} | {profile} | {type} | |".format(
profile=profile.name,
result=testResultIconMap[profile.getResult()],
type="Profile" if not profile.isFacet else "Facet",
status=statusIconMap[profile.getImplementationStatus()]
))
for incUnits in profile.conformanceUnits:
writemd("| | | {status} | Unit | {result} {optional}{unit}{optional} |".format(
unit=incUnits.unit.name,
result=testResultIconMap[incUnits.unit.getResult()],
optional='*' if incUnits.optional else '',
status=statusIconMap[incUnits.unit.implementationStatus]
))
for incProfile in profile.profiles:
writemd("| | | {status} | {type} | {result} {unit} |".format(
unit=incProfile.name,
result=testResultIconMap[incProfile.getResult()],
type="Profile" if not incProfile.isFacet else "Facet",
status=statusIconMap[incProfile.getImplementationStatus()]
))