-
Notifications
You must be signed in to change notification settings - Fork 2
/
result.py
151 lines (119 loc) · 4.61 KB
/
result.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
#!/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 sys
import xml.dom.minidom as dom
logger = logging.getLogger(__name__)
from enum import IntEnum
from dateutil.parser import parse
class CttResults:
"""Class grouping all the CTT results"""
def __init__(self):
self.runs = []
def parseFileResultsIntoSelection(self, profilesFile, cttSelection):
logger.info("Parsing results: {}".format(profilesFile.name))
self.__init__()
fileContent = profilesFile.read()
# Remove BOM since the dom parser cannot handle it on python 3 windows
if fileContent.startswith( codecs.BOM_UTF8 ):
fileContent = fileContent.lstrip( codecs.BOM_UTF8 )
if (sys.version_info >= (3, 0)):
fileContent = fileContent.decode("utf-8")
cttResults = dom.parseString(fileContent).getElementsByTagName("UaCttResults")[0]
for xmlElement in cttResults.childNodes:
if xmlElement.nodeType != xmlElement.ELEMENT_NODE:
continue
result = Result()
result.parseXml(xmlElement)
self.runs.append(result)
if len(self.runs) < 1:
logger.error("Results file does not contain any run.")
return
elif len(self.runs) > 1:
logger.error("Results file contains more than one run. Only considering the first one.")
run = self.runs[0]
self.setResultsForSelectedConformanceGroups(run, cttSelection)
def setResultsForSelectedConformanceGroups(self, runResults, cttSelection):
for selGroup in cttSelection.conformanceGroups:
groupResults = None
for res in runResults.results:
if res.name == selGroup.group.name:
groupResults = res
break
if not groupResults:
logger.error("Did not find result nodes for group {}".format(selGroup.name))
break
selGroup.result = groupResults
self.setResultsForSelectedUnits(selGroup)
def setResultsForSelectedUnits(self, group):
for selUnit in group.selectedUnits:
unitResults = None
for res in group.result.results:
if res.name == selUnit.unit.name:
unitResults = res
break
if not unitResults:
logger.error("Did not find result nodes for unit {}".format(selUnit.name))
break
selUnit.result = unitResults
self.setResultsForSelectedTests(selUnit)
def setResultsForSelectedTests(self, unit):
for selTest in unit.selectedTests:
testResults = None
for res in unit.result.results:
if res.name == selTest.name:
testResults = res
break
if not testResults:
logger.error("Did not find result nodes for test {}".format(selTest.name))
break
selTest.result = testResults
class TestResult(IntEnum):
ERROR = 0
WARNING = 1
NOT_IMPLEMENTED = 2
SKIPPED = 3
NOT_SUPPORTED = 4
OK = 5
BACK_TRACE = 6
UNKNOWN = 99
class Result:
"""Class describing the result of a CTT test and grouping sub-results"""
def __init__(self):
self.status = None
self.description = None
self.testresult = None
self.timestamp = None
self.name = None
self.results = []
def parseXml(self, xmlelement):
testresult_map = {
"0": TestResult.ERROR,
"1": TestResult.WARNING,
"2": TestResult.NOT_IMPLEMENTED,
"3": TestResult.SKIPPED,
"4": TestResult.NOT_SUPPORTED,
"5": TestResult.OK,
"6": TestResult.BACK_TRACE
}
self.status = xmlelement.getAttribute("status")
self.description = xmlelement.getAttribute("description")
self.testresult = testresult_map[xmlelement.getAttribute("testresult")]
self.timestamp = parse(xmlelement.getAttribute("timestamp"))
self.name = xmlelement.getAttribute("name")
for subElement in xmlelement.childNodes:
if subElement.nodeType != subElement.ELEMENT_NODE:
continue
result = Result()
result.parseXml(subElement)
self.results.append(result)