|
1 #!/usr/bin/python |
|
2 import string |
|
3 import sys |
|
4 import os |
|
5 import re |
|
6 import time |
|
7 import sys |
|
8 import csv |
|
9 |
|
10 class TestcaseConfig: |
|
11 def __init__(self): |
|
12 self.desc ='' |
|
13 self.option ='' |
|
14 self.expect ='' |
|
15 self.warnItems =[] |
|
16 self.author = '' |
|
17 self.type = '' |
|
18 self.date ='' |
|
19 def printSelf(self): |
|
20 print 'desc:'+self.desc |
|
21 print 'option:'+self.option |
|
22 print 'author:'+self.author |
|
23 print 'type:'+self.type |
|
24 print 'date:'+self.date |
|
25 print 'expect:'+self.expect |
|
26 print 'check:' |
|
27 for warnItem in self.warnItems: |
|
28 print ' line:'+str(warnItem.line) |
|
29 printType = 0; |
|
30 if len(warnItem.checkExist)>0: |
|
31 print ' checkExist' |
|
32 printType +=1; |
|
33 for checkWord in warnItem.checkExist: |
|
34 print ' '+checkWord |
|
35 if len(warnItem.checkNoExist)>0: |
|
36 print ' checkNoExist' |
|
37 printType +=1; |
|
38 for checkWord in warnItem.checkNoExist: |
|
39 print ' '+checkWord |
|
40 if printType == 0: |
|
41 |
|
42 print ' nothing to check' |
|
43 |
|
44 class CheckPoint: |
|
45 def __init__(self): |
|
46 self.line = -1 |
|
47 self.checkExist=[] |
|
48 self.checkNoExist=[] |
|
49 def setCheckPoint(self,warnString): |
|
50 warnString=warnString.strip() |
|
51 if len(warnString)<=0: |
|
52 return |
|
53 keywordList = warnString.split(',') |
|
54 for keyword in keywordList: |
|
55 keyword = keyword.strip() |
|
56 if keyword[0]=='+': |
|
57 self.checkExist.append(keyword[1:]) |
|
58 elif keyword[0]=='-': |
|
59 self.checkNoExist.append(keyword[1:]) |
|
60 else: |
|
61 self.checkExist.append(keyword) |
|
62 |
|
63 def toString(self): |
|
64 printType = 0; |
|
65 res='' |
|
66 res = res+'line:'+ str(self.line)+'\n' |
|
67 if len(self.checkExist)>0: |
|
68 res =res + ' checkExist\n' |
|
69 printType +=1; |
|
70 for checkWord in self.checkExist: |
|
71 res =res+ ' '+checkWord+'\n' |
|
72 if len(self.checkNoExist)>0: |
|
73 res =res+ ' checkNoExist\n' |
|
74 printType +=1; |
|
75 for checkWord in self.checkNoExist: |
|
76 res=res+ ' '+checkWord+'\n' |
|
77 if printType == 0: |
|
78 res=res+ ' nothing to check\n' |
|
79 return res |
|
80 |
|
81 def get_case_name(value): |
|
82 while value.find('\\\\') != -1: |
|
83 value = value.replace('\\\\', '\\') |
|
84 continue |
|
85 while value.find('//') != -1: |
|
86 value = value.replace('//', '\\') |
|
87 continue |
|
88 while value.find('/') != -1: |
|
89 value = value.replace('/', '\\') |
|
90 continue |
|
91 pos = value.rfind('\\') |
|
92 value = value[pos+1:] |
|
93 pos = value.find('.') |
|
94 return value[:pos] |
|
95 |
|
96 def get_testcase_config(fileName): |
|
97 file = open(fileName,"r") |
|
98 fileLine = 0 |
|
99 testcaseConfig = TestcaseConfig() |
|
100 for line in file.readlines(): |
|
101 if not line.endswith('\\'): |
|
102 fileLine += 1 |
|
103 line = line.strip() |
|
104 scommnet = line.find('//') |
|
105 if scommnet == 0: |
|
106 if (line.find('desc:'))>0: |
|
107 desc = line[line.find('desc:')+5:].strip() |
|
108 testcaseConfig.desc=desc |
|
109 elif line.find('option:')>0: |
|
110 option = line[line.find('option:')+7:].strip() |
|
111 testcaseConfig.option=option |
|
112 elif line.find('expect file:')>0: |
|
113 expect = line[line.find('expect file:')+12:].strip() |
|
114 #get the content of the file |
|
115 data = open(expect,"r") |
|
116 for dataline in data.readlines(): |
|
117 testcaseConfig.expect += dataline |
|
118 elif line.find('expect:')>0: |
|
119 expect = line[line.find('expect:')+7:].strip() |
|
120 testcaseConfig.expect=expect |
|
121 elif line.find('author:')>0: |
|
122 expect = line[line.find('author:')+7:].strip() |
|
123 testcaseConfig.author=expect |
|
124 elif line.find('type:')>0: |
|
125 expect = line[line.find('type:')+5:].strip() |
|
126 testcaseConfig.type=expect |
|
127 elif line.find('date:')>0: |
|
128 expect = line[line.find('date:')+5:].strip() |
|
129 testcaseConfig.date=expect |
|
130 |
|
131 if scommnet >=0: |
|
132 line =line[scommnet+2:] |
|
133 if line.find('check:')>=0: |
|
134 line = line[line.find('check:')+6:].strip() |
|
135 warnItem = CheckPoint() |
|
136 warnItem.setCheckPoint(line) |
|
137 warnItem.line = fileLine |
|
138 testcaseConfig.warnItems.append(warnItem) |
|
139 return testcaseConfig |
|
140 |
|
141 |
|
142 def comment_string(value): |
|
143 lines = value.splitlines() |
|
144 result = '' |
|
145 for line in lines: |
|
146 if line.find('@SYM')==0: |
|
147 result += '//! ' + line+'\n' |
|
148 else: |
|
149 result += '//! ' + line+'\n' |
|
150 return result |
|
151 |
|
152 if __name__ == '__main__': |
|
153 argv = sys.argv[1:] |
|
154 if len(argv) >=1: |
|
155 input_file_name = argv[0] |
|
156 else: |
|
157 print 'case2tef file_list_file' |
|
158 if input_file_name == '-': |
|
159 input_file = sys.stdin |
|
160 elif os.path.exists(input_file_name) and os.path.isfile(input_file_name): |
|
161 input_file = open(input_file_name) |
|
162 else: |
|
163 input_file = None |
|
164 if not input_file == None: |
|
165 lines = input_file.readlines() |
|
166 for line in lines: |
|
167 while line.find('\n') != -1: |
|
168 line = line.replace('\n', '') |
|
169 continue |
|
170 |
|
171 testcase_config =get_testcase_config(line) |
|
172 case_name = get_case_name(line) |
|
173 res = 'START_TESTCASE '+case_name+'\n' |
|
174 body = '@SYMTestCaseID ' +case_name+'\n' |
|
175 body+= '@SYMTestCaseDesc ' +testcase_config.desc+'\n' |
|
176 body+= '@SYMTestPriority ' +'HIGH'+'\n' |
|
177 body+= '@SYMTestActions ' +'run LeaveScan command line' |
|
178 if not testcase_config.option=='': |
|
179 body+=' with option:'+testcase_config.option |
|
180 body+='\n' |
|
181 body+= '@SYMTestExpectedResults ' +'Check the follwing:'+'\n' |
|
182 if not testcase_config.expect=='': |
|
183 body+='Output is:\n' |
|
184 body+=testcase_config.expect+'\n' |
|
185 if len(testcase_config.warnItems)>0: |
|
186 body+='check the keyword of output\n' |
|
187 for warnItem in testcase_config.warnItems: |
|
188 body+= warnItem.toString() |
|
189 body+= '' |
|
190 body+= '@SYMTestType ' +testcase_config.type+'\n' |
|
191 body+= '@SYMCreationDate ' +testcase_config.date+'\n' |
|
192 body+= '@SYMAuthor ' +testcase_config.author+'\n' |
|
193 res += comment_string(body) |
|
194 res += 'END_TESTCASE '+case_name+'\n' |
|
195 res += '\n' |
|
196 print res |
|
197 |
|
198 |
|
199 |
|
200 |