forked from zhajio1988/YASA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupCfg.py
156 lines (141 loc) · 5.52 KB
/
groupCfg.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
#******************************************************************************
# * Copyright (c) 2019, XtremeDV. All rights reserved.
# *
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *
# * Author: Jude Zhang, Email: [email protected]
# *******************************************************************************
from baseCfg import *
from copy import *
from exceptions import groupUnknown
class groupCfg(includableTopCfg):
def __init__(self, name, section, parent=None):
super(groupCfg, self).__init__(name, section, parent)
self._subSectionType = groupSubCfg
def getGroup(self, group=''):
if group:
if not group in self.subSection:
raise groupUnknown(group)
groupSection = self.subSection[group]
return groupSection
class groupSubCfg(includableCfg):
def __init__(self, name, section, parent=None):
super(groupSubCfg, self).__init__(name, section, parent)
self._addOption('build')
self._addOption('args')
self._addOption('tests')
self._tests = []
@property
def incGroups(self):
for inc in self._include:
for incGroup in inc.incGroups:
yield incGroup
yield deepcopy(self)
def _readBuildInOption(self):
super(groupSubCfg, self)._readBuildInOption()
self._parseBuild()
self._parseArgs()
self._parseTests()
def _parseBuild(self):
return self._buildInOpts['build']
def _parseArgs(self):
return self._buildInOpts['args']
def _parseTests(self):
"""
Parse each testcase in group. If group have args field,
append args with testcase name. if tests field itself has
args field. Duplicate fields in group args field will be overwritten
Such as sanity2 will use its seed 56789 and repeat num 2.
seed 56789 overwrite seed 12345 in args field.
sanity3 will use its seed 12345 and repeat num 3
```
[[top_smoke]]
build = candy_lover
args = -vh -seed 12345 -r 2
tests = sanity2 -seed 56789
tests = sanity3 -r 3
```
"""
testsOpts = []
# when only one case in group, _buildInOpts['tests'] is string,
#should change to list for post processing
if isinstance(self._buildInOpts['tests'], str):
testsOpts.append(self._buildInOpts['tests'])
self._buildInOpts['tests'] = testsOpts
for test in self._buildInOpts['tests']:
appendArgs = []
testList = test.split("-")
testArgs = test.split(" ")[1:]
if testList[1:] and self.argsOption:
self._getTestArgs(testList[1:], appendArgs)
testArgs.append(" ".join(['-'+ x for x in appendArgs]))
index = self._buildInOpts['tests'].index(test)
self._buildInOpts['tests'].pop(index)
self._buildInOpts['tests'].insert(index, testList[0] + " ".join(testArgs))
elif self.argsOption:
testList.append(self.argsOption)
index = self._buildInOpts['tests'].index(test)
self._buildInOpts['tests'].pop(index)
self._buildInOpts['tests'].insert(index, " ".join(testList))
def _getTestArgs(self, testArgs, appendArgs):
"""
Get testcase args. Judge if Duplicate fields exist or not.
then deal with these situation.
"""
append = True
argsList = [i.strip() for i in self.argsOptionList if i != '']
for j in argsList:
j = j.strip().split(" ")
for i in testArgs:
i = i.strip().split(" ")
if len(i) > 1:
if len(j) >1:
if j[0] == i[0]:
append = False
break
elif len(j) == 1:
append = True
elif len(i) == 1:
if len(i) == 1:
if j == i:
append = False
break
elif len(j) > 1:
append = True
if append:
appendArgs.append(" ".join(j))
@property
def buildOption(self):
return self._buildInOpts['build']
@property
def argsOption(self):
return self._buildInOpts['args']
@property
def argsOptionList(self):
if self.argsOption:
return self.argsOption.strip().split("-")
@property
def testsOption(self):
return self._buildInOpts['tests']
#if __name__ == '__main__':
# config = ConfigObj(infile=defaultGroupFile(), stringify=True)
# group = groupCfg('test', config['testgroup'])
# group.parse()
# for v in group.subSection.values():
# print(v.name)
# print(v.buildOption)
# print(v.argsOption)
# print(v.testsOption)
# print('haha', v.include)
# for include in v.include:
# print(group.getGroup(include).testsOption)