-
Notifications
You must be signed in to change notification settings - Fork 2
/
selection.py
113 lines (83 loc) · 3.64 KB
/
selection.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
#!/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
import json
logger = logging.getLogger(__name__)
class CttSelection:
"""Class containing all selected conformance groups and units of a CTT run"""
def __init__(self):
self.projectInfo = ProjectInfo()
self.conformanceGroups = []
def parseFile(self, selectionFile, serverProfiles, clientProfiles):
logger.info("Parsing selection: {}".format(selectionFile.name))
self.__init__()
fileContent = selectionFile.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")
uaSelection = dom.parseString(fileContent).getElementsByTagName("UaTestCaseSelection")[0]
self.projectInfo.parseXml(uaSelection.getElementsByTagName("ProjectInfo")[0])
profiles = None
if self.projectInfo.type == "ServerProject":
profiles = serverProfiles
elif self.projectInfo.type == "ClientProject":
profiles = clientProfiles
for groupsXml in uaSelection.getElementsByTagName("ConformanceGroups")[0].childNodes:
if groupsXml.nodeType != groupsXml.ELEMENT_NODE:
continue
group = SelectedConformanceGroup()
group.parseXml(groupsXml, profiles)
self.conformanceGroups.append(group)
logger.debug("Profile file parsed.")
#print(json.dumps(mapping_bugs, indent=4))
return profiles
class ProjectInfo:
"""Class containing the project info of a selection file"""
def __init__(self):
self.type = None
self.version = None
def parseXml(self, xmlelement):
self.type = xmlelement.getAttribute("ProjectType")
self.version = xmlelement.getAttribute("Version")
class SelectedConformanceGroup:
def __init__(self):
self.group = None
self.selectedUnits = []
def parseXml(self, xmlelement, profiles):
self.group = profiles.getConformanceGroup(xmlelement.getAttribute("name"))
for unitXml in xmlelement.getElementsByTagName("ConformanceUnit"):
if unitXml.nodeType != unitXml.ELEMENT_NODE:
continue
unit = SelectedConformanceUnit()
unit.parseXml(unitXml, profiles, self.group)
if unit._correctedGroup:
self.group = unit._correctedGroup
self.selectedUnits.append(unit)
class SelectedConformanceUnit:
def __init__(self):
self.unit = None
self.selectedTests = []
self._correctedGroup = None
def parseXml(self, xmlelement, profiles, group):
self.unit = group.getConformanceUnit(xmlelement.getAttribute("name"), showWarning=False)
if not self.unit:
self._correctedGroup = profiles.getConformanceGroupForUnit(xmlelement.getAttribute("name"))
self.unit = self._correctedGroup.getConformanceUnit(xmlelement.getAttribute("name"))
for testXml in xmlelement.getElementsByTagName("TestCases")[0].childNodes:
if testXml.nodeType != testXml.ELEMENT_NODE:
continue
self.selectedTests.append(self.unit.getTest(testXml.getAttribute("name")))