-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaultRule.py
328 lines (312 loc) · 15.1 KB
/
defaultRule.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import rule
import base
import re
import rucmElement
class DefaultRule17(rule.Rule):
def check(self):
steps = rucmElement.RUCMRoot.getAllSteps()
errors = []
for step in steps:
# �õ�INCLUDE USE CASE��index
for i in range(len(step.sentences)+1):
if i == len(step.sentences):
break
if step.sentences[i].nature == base.NatureType.include_use_case_:
break
if i == len(step.sentences):
continue
# ���뿪ͷ�������ҽ���һ��USE CASE
if i != 0 or len(step.sentences) != 2:
errors.append(rule.ErrorInfo(self.description+'AAA', step.useCaseName, step.val))
continue
if step.sentences[1].val not in rucmElement.RUCMRoot.getUseCase(step.useCaseName).include:
# print(rucmElement.RUCMRoot.getUseCase(step.useCaseName).include)
errors.append(rule.ErrorInfo(self.description+'BBB', step.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule18(rule.Rule):
def check(self):
steps = rucmElement.RUCMRoot.getAllSteps()
errors = []
for step in steps:
# �õ�EXTENDED USE CASE��index
for i in range(len(step.sentences)+1):
if i == len(step.sentences):
break
if step.sentences[i].nature == base.NatureType.extened_by_usecase_:
break
if i == len(step.sentences):
continue
# ���뿪ͷ�������ҽ���һ��USE CASE
if i != 0 or len(step.sentences) != 2:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
if step.sentences[1].val not in rucmElement.RUCMRoot.getUseCase(step.useCaseName).extend:
# print(rucmElement.RUCMRoot.getUseCase(step.useCaseName).extend)
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule19(rule.Rule):
def check(self):
flows = rucmElement.RUCMRoot.getAllFlows()
errors = []
for flow in flows:
if flow.type == 'BasicFlow' or flow.type == 'Global Alternative Flow':
continue
rfs = flow.RfsSentence
res = re.search(r'(RFS )(\D+ )(\d.*)', rfs)
if not res:
errors.append(rule.ErrorInfo(self.description+'aaa', flow.useCaseName, rfs))
continue
flowName = res.group(2).rstrip(' ')
_str = res.group(3).replace(' ', '')
stepNums = _str.split(',')
nums = []
for stepNum in stepNums:
resNum = re.fullmatch(r'(\d+)(-\d+)?( )?', stepNum)
if not resNum:
# �����ʽ����ȷ
errors.append(rule.ErrorInfo(self.description+'bbb', flow.useCaseName, rfs))
continue
startNum = resNum.group(1)
endNum = resNum.group(2)
if endNum:
# ��
endNum = endNum[1:]
startNum = int(startNum)
endNum = int(endNum)
if startNum >= endNum:
errors.append(rule.ErrorInfo(self.description+'ccc', flow.useCaseName, rfs))
continue
nums += range(startNum, endNum+1)
else:
# û���
nums.append(int(resNum.group(1)))
for num in nums:
print(flowName)
if not flow.parent.findRFS(flowName.replace(' ',''), num):
errors.append(rule.ErrorInfo(self.description+'ddd', flow.useCaseName, rfs))
break
rule.Reporter.errors += errors
class DefaultRule20(rule.Rule):
def check(self):
flows = rucmElement.RUCMRoot.getAllFlows()
errors = []
valid_pre = []
valid = []
for flow in flows:
# ��ÿ��flow��Χ�ڽ��й�����
for step in flow.steps:
natureI = {}
natureI['if'] = -1
natureI['else'] = -1
natureI['elseif'] = -1
natureI['then'] = -1
natureI['endif'] = -1
for i in range(len(step.sentences)):
if step.sentences[i].nature == base.NatureType.if_:
# ��״̬ת��ջ���һ��Ԫ��
# ״̬ת�ƣ�����THEN
natureI['if'] = i
#stackIfNum += 1
#stackThenNum += 1
valid_pre.append(['IF'])
valid.append(['THEN'])
elif step.sentences[i].nature == base.NatureType.else_:
# ״̬ת�ƣ�����END IF
# û����״̬
if not valid:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
natureI['else'] = i
if not 'ELSE' in valid[len(valid_pre)-1] :
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
valid_pre.pop()
valid_pre.append(valid.pop())
valid.append(['END IF'])
elif step.sentences[i].nature == base.NatureType.elseif_:
# ״̬ת�ƣ�����THEN
natureI['elseif'] = i
# û����״̬
if not valid:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
if not 'ELSE IF' in valid[len(valid)-1] :
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
valid_pre.pop()
valid_pre.append(valid.pop())
valid.append(['THEN'])
elif step.sentences[i].nature == base.NatureType.then_:
# ״̬ת�ƣ����THEN��ӦIF������ELSE/ELSE IF/END IF
# ���THEN��ӦELSE IF������END IF
# ������֭ת�Ƴ���
natureI['then'] = i
# û����״̬
if not valid:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
if not 'THEN' in valid[len(valid)-1] :
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
v_pre = valid_pre.pop()
if 'IF' in v_pre:
valid_pre.append(valid.pop())
valid.append(['ELSE', 'ELSE IF', 'END IF'])
elif 'ELSE IF' in v_pre:
valid_pre.append(valid.pop())
valid.append(['END IF'])
else:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
elif step.sentences[i].nature == base.NatureType.endif_:
# ��״̬ת�ƣ���״̬ת��ջ�Ƴ�һ��Ԫ��
# û����״̬
if not valid:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
natureI['endif'] = i
if not 'END IF' in valid[len(valid)-1] :
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
valid_pre.pop()
valid.pop()
# IF���뿪ͷ
if natureI['if'] > 0 or natureI['elseif'] > 0 or natureI['else'] > 0:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
# THEN�����β
if natureI['then'] >= 0 and natureI['then'] != len(step.sentences)-1:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
if natureI['endif'] >= 0 and len(step.sentences) != 1:
# ��ռһ��
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
# �����Ļ���validΪ��
if len(valid):
errors.append(rule.ErrorInfo(self.description, flow.useCaseName, flow.title))
rule.Reporter.errors += errors
class DefaultRule21(rule.Rule):
def check(self):
steps = rucmElement.RUCMRoot.getAllSteps()
errors = []
for step in steps:
# �õ�MEANWHILE��index
for i in range(len(step.sentences)+1):
if i == len(step.sentences):
break
if step.sentences[i].nature == base.NatureType.mean_while_:
break
if i == len(step.sentences):
continue
# ǰ������ж���
if i == 0 or i == len(step.sentences)-1:
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule22(rule.Rule):
def check(self):
steps = rucmElement.RUCMRoot.getAllSteps()
errors = []
for step in steps:
# �õ�VALIDATES THAT��index
for i in range(len(step.sentences)+1):
if i == len(step.sentences):
break
if step.sentences[i].nature == base.NatureType.validates_that_:
break
if i == len(step.sentences):
# û��
continue
if i == 0 or i == len(step.sentences)-1:
# ǰ������ж���
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule23(rule.Rule):
def check(self):
flows = rucmElement.RUCMRoot.getAllFlows()
errors = []
for flow in flows:
# doNum:ά����ջ������������do++,����until--
doNum = 0
for stepInd, step in enumerate(flow.steps):
# ��do
doI = -1
untilI = -1
for i in range(len(step.sentences)):
if step.sentences[i].nature == base.NatureType.do_:
doI = i
if step.sentences[i].nature == base.NatureType.until_:
untilI = i
# �ҵ�do
if doI >= 0:
# doռһ��step
doNum+=1
if len(step.sentences) != 1:
errors.append(rule.ErrorInfo(self.description, flow.useCaseName, step.val))
continue
if untilI >= 0:
# until�����ڿ�ͷ��until��������ж���, untilǰ�����Ѵ���do
if untilI != 0 or len(step.sentences) == 1 or doNum == 0:
errors.append(rule.ErrorInfo(self.description, flow.useCaseName, step.val))
continue
doNum -= 1
if doNum != 0:
# do��until��������ƥ��
errors.append(rule.ErrorInfo(self.description, flow.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule24(rule.Rule):
def check(self):
steps = rucmElement.RUCMRoot.getAllSteps()
errors = []
for step in steps:
# �õ�ABORT��index
for i in range(len(step.sentences)+1):
if i == len(step.sentences):
break
if step.sentences[i].nature == base.NatureType.abort_:
break
if i == len(step.sentences):
# û��
continue
if len(step.sentences) != 1:
# ��ռһ��
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule25(rule.Rule):
def check(self):
steps = rucmElement.RUCMRoot.getAllSteps()
errors = []
for step in steps:
# �õ�RESUME��index
for i in range(len(step.sentences)+1):
if i == len(step.sentences):
break
if step.sentences[i].nature == base.NatureType.resume_step_:
break
if i == len(step.sentences):
# û��
continue
if len(step.sentences) != 2 or i != 0:
# �ҵ��ˣ��ж�RESUME�ڲ��ڿ�ͷ�������Dz���ֻ����һ�����
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
try:
# �жϵڶ������Dz������
num = int(step.sentences[1].val)
except Exception as e:
print(e)
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
continue
if not step.parent.type == 'Specific Flow' or \
not rucmElement.RUCMRoot.getUseCase(step.useCaseName).findRFS(rucmElement.RUCMRoot.getUseCase(step.useCaseName).basicFlow.title, num):
# ��Ӧ��flow�Dz���alternative����Ӧ��step�ڲ���basic flow��
errors.append(rule.ErrorInfo(self.description, step.useCaseName, step.val))
rule.Reporter.errors += errors
class DefaultRule26(rule.Rule):
def check(self):
flows = rucmElement.RUCMRoot.getAllFlows()
errors = []
for flow in flows:
if not flow.postCondition:
errors.append(rule.ErrorInfo(self.description, flow.useCaseName, flow.title))
rule.Reporter.errors += errors