blob: b98c68bae589db4dd3c1d8dad386d30cdc4a220a [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#/usr/bin/env python
2'''
3Created on 20-Dec-2012
Jeremy Songsterae01bba2016-07-11 15:39:17 -07004Modified 2015 by ON.Lab
Jon Hall4ba53f02015-07-29 13:07:41 -07005
Jeremy Songsterae01bba2016-07-11 15:39:17 -07006Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
adminbae64d82013-08-01 10:50:15 -07009
10 TestON is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
14
15 TestON is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
Jon Hall4ba53f02015-07-29 13:07:41 -070021 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070022
23
24'''
25import re
26import inspect
27
28
29class OpenSpeak:
30
31 def __init__(self):
32 self.default = ''
Jon Hall4ba53f02015-07-29 13:07:41 -070033 self.flag = 0
adminbae64d82013-08-01 10:50:15 -070034 self.CurrentStep = 0
35 self.grtrOrLssr = 0
36
37 def compiler(self,**compileParameters):
38 '''
Jon Hall4ba53f02015-07-29 13:07:41 -070039 This method will parse the openspeak file and will write to a python module with the equivalent translations.
40 It can accept OpenSpeak syntax in string or an OpenSpeak file as an input parameter.
adminbae64d82013-08-01 10:50:15 -070041 Translated form can be written into python module if attribute "WRITETOFILE" is set to 1.
42 '''
Jon Hall4ba53f02015-07-29 13:07:41 -070043
adminbae64d82013-08-01 10:50:15 -070044 args = self.parse_args(["OPENSPEAKFILE","TEXT","WRITETOFILE","FILEHANDLE"],**compileParameters)
45 resultString = ''
46 Test = "Mininet"
47 args["WRITETOFILE"] = args["WRITETOFILE"] if args["WRITETOFILE"] != None else 1
48 self.CurrentStep = 0
49 self.CurrentCase = ''
Jon Hall4ba53f02015-07-29 13:07:41 -070050
adminbae64d82013-08-01 10:50:15 -070051 ## here Open Speak file will be parsed by each line and translated.
52 if args["OPENSPEAKFILE"] !=None and args["TEXT"] ==None and args["FILEHANDLE"] == None:
53 self.openspeakfile = args["OPENSPEAKFILE"]
54 openSpeakFile = open(args["OPENSPEAKFILE"],"r").readlines()
Jon Hall4ba53f02015-07-29 13:07:41 -070055
56 elif args["OPENSPEAKFILE"] ==None and args["TEXT"] and args["FILEHANDLE"] == None:
57 openSpeakFile = args["TEXT"].split("\n")
adminbae64d82013-08-01 10:50:15 -070058 elif args["FILEHANDLE"] and args["OPENSPEAKFILE"] ==None and args["TEXT"] ==None:
59 openSpeakFile = args["FILEHANDLE"].readlines()
Jon Hall4ba53f02015-07-29 13:07:41 -070060
adminbae64d82013-08-01 10:50:15 -070061 index = 0
62 outputFile = []
63 testName = re.search("\/(.*)\.ospk$",self.openspeakfile,0)
64 testName = testName.group(1)
65 testName = testName.split("/")
66 testName = testName[len(testName)-1]
67 outputFile.append("\nclass " + testName + " :" + "\n")
68 outputFile.append("\n" + " " * 4 + "def __init__(self) :")
Jon Hall4ba53f02015-07-29 13:07:41 -070069 outputFile.append("\n" + " " * 8 + "self.default = \'\'" + "\n")
70
adminbae64d82013-08-01 10:50:15 -070071 while index < len(openSpeakFile):
72 ifelseMatch = re.match("\s+IF|\s+ELSE|\s+ELIF",openSpeakFile[index],flags=0)
73 line = openSpeakFile[index]
74 repeatMatch = re.match("\s*REPEAT", openSpeakFile[index], flags=0)
75 if ifelseMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -070076 result = self.verify_and_translate(line)
adminbae64d82013-08-01 10:50:15 -070077 initialSpaces = len(line) -len(line.lstrip())
Jon Hall4ba53f02015-07-29 13:07:41 -070078 self.outLoopSpace = initialSpaces
adminbae64d82013-08-01 10:50:15 -070079 nextLine = openSpeakFile[index+1]
80 nextinitialSpaces = len(nextLine) -len(nextLine.lstrip())
Jon Hall4ba53f02015-07-29 13:07:41 -070081
82
adminbae64d82013-08-01 10:50:15 -070083 while nextinitialSpaces > initialSpaces :
84 try :
85 elseMatch = re.match("\s*ELSE|\s*ELIF",nextLine,flags=0)
86 if elseMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -070087 self.flag = self.flag -1
88 result = result + self.verify_and_translate(nextLine)
adminbae64d82013-08-01 10:50:15 -070089 nextLine = openSpeakFile[index + 1]
90 nextinitialSpaces = len(nextLine) -len(nextLine.lstrip())
91 except IndexError:
Jon Hall4ba53f02015-07-29 13:07:41 -070092 pass
adminbae64d82013-08-01 10:50:15 -070093 index = index + 1
Jon Hall4ba53f02015-07-29 13:07:41 -070094 self.flag = 0
adminbae64d82013-08-01 10:50:15 -070095 elif repeatMatch:
96 self.flag = 0
97 result = self.verify_and_translate(line)
98 index = index + 1
99 endMatch = re.match("\s*END",openSpeakFile[index],flags=0)
100 while not endMatch :
101 try :
Jon Hall4ba53f02015-07-29 13:07:41 -0700102
adminbae64d82013-08-01 10:50:15 -0700103 self.flag = self.flag + 1
104 result = result + self.verify_and_translate(openSpeakFile[index])
105 index = index + 1
Jon Hall4ba53f02015-07-29 13:07:41 -0700106
adminbae64d82013-08-01 10:50:15 -0700107 except IndexError :
108 pass
Jon Hall4ba53f02015-07-29 13:07:41 -0700109
110
adminbae64d82013-08-01 10:50:15 -0700111 else :
112 self.flag = 0
113 result = self.verify_and_translate(line)
114 index = index + 1
115 outputFile.append(result)
116
117 if args["WRITETOFILE"] == 1 :
118 testscript = re.sub("ospk","py",self.openspeakfile,0)
119 testScript = open(testscript,"w")
120 for lines in outputFile :
121 testScript.write(lines)
122 testScript.close()
123 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700124
adminbae64d82013-08-01 10:50:15 -0700125 def verify_and_translate(self,line):
126 '''
127 It will accept the each line and calls the suitable API to conver into pyton equivalent syntax .
Jon Hall4ba53f02015-07-29 13:07:41 -0700128 It will return the translated python syntax .
129 '''
adminbae64d82013-08-01 10:50:15 -0700130 lineSpace = re.match("^\s+",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700131 initialSpaces = len(line) -len(line.lstrip())
132 line = re.sub("^\s+","",line) if lineSpace else line
133
134
adminbae64d82013-08-01 10:50:15 -0700135 resultString = None
136 resultString = "\n" + " " * 4 if str(inspect.stack()[1][3]) == "compiler" else "\n"
Jon Hall4ba53f02015-07-29 13:07:41 -0700137 indent = " " *(4 + 4 * self.flag) if self.flag > 0 else " " * 4
adminbae64d82013-08-01 10:50:15 -0700138 caseMatch = re.search("^CASE\s+(\d+)",line,flags=0)
139 nameMatch = re.match("^NAME\s+\"(.*)\"",line,flags=0)
140 commentMatch = re.match("^COMMENT\s+\"(.*)\"",line,flags=0)
141 stepMatch = re.match("^STEP\s+\"(.*)\"",line,flags=0)
142 connectMatch = re.match("^CONNECT\s+(\w+)\s+USING\s+(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700143 disconnectMatch = re.match("^DISCONNECT\s+(.*)",line,flags=0)
adminbae64d82013-08-01 10:50:15 -0700144 ondoMatch = re.match("^ON\s+(.*)\s+DO\s+(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700145
adminbae64d82013-08-01 10:50:15 -0700146 storeMatch = re.match("^STORE\s+(.*)\s+IN\s+(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700147 variableMatch = re.match("^(.*)\s+=\s+(.*)",line,flags=0)
adminbae64d82013-08-01 10:50:15 -0700148 assertMatch = re.match("^ASSERT\s+(\w+)\s+(.*)\s+(.*)\s+ONPASS\s+(.*)\s+ONFAIL\s+(.*)",line,flags=0)
149 logMatch = re.match("^(ERROR|INFO|DEBUG|CRITICAL|REPORT|EXACT|WARN)\s+(.*)",line,flags=0)
150 ifloop = re.match("IF\s+(\w+)\s*(..|\w+)\s*(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700151 elseloopMatch = re.match("ELSE\s*$",line,flags=0)
adminbae64d82013-08-01 10:50:15 -0700152 elifloop = re.match("ELSE\sIF\s+(\w+)\s*(..|\w+)\s*(.*)",line,flags=0)
153 forloopMatch = re.match("\s*REPEAT\s+(/d+)\s+TIMES",line,flags=0)
154 experimentalMatch = re.match("EXPERIMENTAL\s+MODE\s+(\w+)",line,flags=0)
155 repeatMatch = re.match("\s*REPEAT\s+(\d+)\s+TIMES", line, flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700156
adminbae64d82013-08-01 10:50:15 -0700157 response_pasrse = re.match("\s*PARSE\s+(\w+)\s+AS\s+(\w+)\s+INTO\s+(\w+)", line, flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700158
adminbae64d82013-08-01 10:50:15 -0700159 if caseMatch :
160 self.CurrentStep = 0
161 self.CurrentCase = "CASE" + caseMatch.group(1)
162 resultString = resultString + self.translate_case_block(casenumber=caseMatch.group(1))
163 elif repeatMatch:
164 resultString = resultString + indent + self.translate_repeat(repeat=repeatMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700165 elif nameMatch :
adminbae64d82013-08-01 10:50:15 -0700166 resultString = resultString + indent + self.translate_testcase_name(testname=nameMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700167 elif commentMatch :
adminbae64d82013-08-01 10:50:15 -0700168 resultString = resultString + indent + self.translate_comment(comment=commentMatch.group(1))
169 elif stepMatch :
170 self.CurrentStep = self.CurrentStep + 1
171 resultString = resultString + indent + self.translate_step(step=stepMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700172 elif connectMatch :
adminbae64d82013-08-01 10:50:15 -0700173 resultString = resultString + indent + self.translate_connect(component=connectMatch.group(1),
174 arguments=connectMatch.group(2) )
175 elif disconnectMatch :
176 resultString = resultString + indent + self.translate_disconnect(component=disconnectMatch.group(1))
177 elif ondoMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700178 resultString = resultString + indent + self.translate_onDOAs(component=ondoMatch.group(1),action=ondoMatch.group(2))
adminbae64d82013-08-01 10:50:15 -0700179 elif storeMatch :
180 resultString = resultString + indent + self.translate_store(variable=storeMatch.group(2),
Jon Hall4ba53f02015-07-29 13:07:41 -0700181 value=storeMatch.group(1))
adminbae64d82013-08-01 10:50:15 -0700182 elif variableMatch :
183 resultString = resultString + indent + self.translate_store(variable=variableMatch.group(1),
184 value=variableMatch.group(2))
185 elif assertMatch :
186 resultString = resultString + indent + self.translate_assertion(leftvalue=assertMatch.group(1),
187 operator=assertMatch.group(2),
188 rightvalue=assertMatch.group(3),
189 onpass=assertMatch.group(4),
Jon Hall4ba53f02015-07-29 13:07:41 -0700190 onfail=assertMatch.group(5))
adminbae64d82013-08-01 10:50:15 -0700191 elif logMatch :
192 resultString = resultString + indent + self.translate_logs(loglevel=logMatch.group(1),
193 message=logMatch.group(2))
194 elif ifloop :
Jon Hall4ba53f02015-07-29 13:07:41 -0700195
196 self.initSpace = initialSpaces
adminbae64d82013-08-01 10:50:15 -0700197 operand = ifloop.group(1)
198 operator = ifloop.group(2)
Jon Hall4ba53f02015-07-29 13:07:41 -0700199 value = ifloop.group(3)
200 resultString = resultString + indent + "if " + operand + self.translate_if_else_operator(conditionoperator=operator) + value + ":"
201 self.flag = self.flag + 1
adminbae64d82013-08-01 10:50:15 -0700202 elif experimentalMatch :
203 resultString = resultString + indent + self.translate_experimental_mode(mode=experimentalMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700204
adminbae64d82013-08-01 10:50:15 -0700205 elif elseloopMatch :
206 if initialSpaces == self.initSpace or initialSpaces == self.outLoopSpace:
207 resultString = resultString + indent + "else :"
208 self.flag = self.flag + 1
209 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700210 indent = " " *(4 + 4 * (self.flag-1))
adminbae64d82013-08-01 10:50:15 -0700211 resultString = resultString + indent + "else :"
212 self.flag = self.flag + 1
Jon Hall4ba53f02015-07-29 13:07:41 -0700213
adminbae64d82013-08-01 10:50:15 -0700214 elif elifloop :
Jon Hall4ba53f02015-07-29 13:07:41 -0700215
adminbae64d82013-08-01 10:50:15 -0700216 operand = elifloop.group(1)
217 operator = elifloop.group(2)
Jon Hall4ba53f02015-07-29 13:07:41 -0700218 value = elifloop.group(3)
adminbae64d82013-08-01 10:50:15 -0700219 if initialSpaces == self.initSpace or initialSpaces == self.outLoopSpace:
Jon Hall4ba53f02015-07-29 13:07:41 -0700220 resultString = resultString + indent + "elif " + operand + self.translate_if_else_operator(conditionoperator=operator) + value + ":"
221 self.flag = self.flag + 1
adminbae64d82013-08-01 10:50:15 -0700222 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700223 indent = " " *(4 + 4 * (self.flag-1))
224 resultString = resultString + indent + "elif " + operand + self.translate_if_else_operator(conditionoperator=operator) + value + ":"
adminbae64d82013-08-01 10:50:15 -0700225 self.flag = self.flag + 1
226 elif response_pasrse :
227 output_string = response_pasrse.group(1)
228 req_format = response_pasrse.group(2)
229 store_in = response_pasrse.group(3)
Jon Hall4ba53f02015-07-29 13:07:41 -0700230 resultString = resultString + indent + store_in +'= main.response_parser('+output_string+",\""+req_format+"\")"
231 self.flag = self.flag + 1
adminbae64d82013-08-01 10:50:15 -0700232
233 return resultString
234
235 def translate_repeat(self,**repeatStatement):
236 '''
237 this will transalte the repeat statement into a python equivalen while loop
238 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700239
adminbae64d82013-08-01 10:50:15 -0700240 args = self.parse_args(["REPEAT"],**repeatStatement)
241 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700242
adminbae64d82013-08-01 10:50:15 -0700243 resultString = "i = 0"
244 resultString = resultString + "\n" + " " * 8 +"while i<" + args["REPEAT"] + " :"
245 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700246
adminbae64d82013-08-01 10:50:15 -0700247 def translate_if_else_operator(self,**loopBlock):
248 '''
249 This method will translate if-else loop block into its equivalent python code.
Jon Hall4ba53f02015-07-29 13:07:41 -0700250 Whole loop block will be passed into loopBlock List.
adminbae64d82013-08-01 10:50:15 -0700251 It returns the transalted reuslt as a string.
252 '''
253 args = self.parse_args(["CONDITIONOPERATOR"],**loopBlock)
254 resultString = ''
255 # process the loopBlock List translate all statements underlying the given loop block
256 equalsMatch = re.match("EQUALS$|==\s*$",args["CONDITIONOPERATOR"],flags=0)
257 greaterMatch = re.match("GREATER\s+THAN$|>\s*$",args["CONDITIONOPERATOR"],flags=0)
258 lesserMatch = re.match("LESSER\s+THAN$|<\s*$",args["CONDITIONOPERATOR"],flags=0)
259 greaterEqualMatch = re.match("GREATER\s+THAN\s+OR\s+EQUALS$|>=\s*$",args["CONDITIONOPERATOR"],flags=0)
260 lesserEqualMatch = re.match("LESSER\s+THAN\s+OR\s+EQUALS$|<=\s*$",args["CONDITIONOPERATOR"],flags=0)
261 if equalsMatch :
262 resultString = resultString + " == "
Jon Hall4ba53f02015-07-29 13:07:41 -0700263 elif greaterMatch :
adminbae64d82013-08-01 10:50:15 -0700264 resultString = resultString + " > "
Jon Hall4ba53f02015-07-29 13:07:41 -0700265 elif lesserMatch :
266 resultString = resultString + " < "
adminbae64d82013-08-01 10:50:15 -0700267 elif greaterEqualMatch:
268 resultString = resultString + " >= "
269 elif lesserEqualMatch :
270 resultString = resultString + " <= "
271 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700272 print "\n Error: Given Operator is not listed "
273
274 return resultString
275
adminbae64d82013-08-01 10:50:15 -0700276 def translate_experimental_mode(self,**modeType):
277 '''
278 This API will translate statment EXPERIMENTAL MODE ON/OFF into python equivalent.
279 It will return the transalted value.
280 '''
281 args = self.parse_args(["MODE"],**modeType)
282 resultString = ''
283 ONmatch = re.match("\s*ON",args["MODE"],flags=0)
284 OFFmatch = re.match("\sOFF",args["MODE"],flags=0)
285
286 if ONmatch :
287 resultString = "main.EXPERIMENTAL_MODE = main.TRUE"
288 elif OFFmatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700289 resultString = "main.EXPERIMENTAL_MODE = main.FALSE"
adminbae64d82013-08-01 10:50:15 -0700290
291 return resultString
292
293 def interpret(self,**interpetParameters):
294 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700295 This method will accept the OpenSpeak syntax into a string and will return
adminbae64d82013-08-01 10:50:15 -0700296 a python equivalent translations statement
297 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700298
adminbae64d82013-08-01 10:50:15 -0700299 args = self.parse_args(["TEXT","WRITETOFILE"],**interpetParameters)
300 resultString = ''
301 ## here Open Speak syntax will be translated into python equivalent.
302 resultString = self.verify_and_translate(args["TEXT"])
303 lineSpace = re.match("^\s+",resultString,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700304
305 resultString = re.sub("^\s+","",resultString) if lineSpace else resultString
adminbae64d82013-08-01 10:50:15 -0700306 return resultString
307
308 def translate_logs(self,**logStatement):
309 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700310 This will translate the OpenSpeak log message statements into python equivalent
adminbae64d82013-08-01 10:50:15 -0700311 to resultString and returns resultString
312 '''
313 args = self.parse_args(["LOGLEVEL","MESSAGE"],**logStatement)
314 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700315 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700316 message = self.translate_log_message(message=args["MESSAGE"])
317 if args["LOGLEVEL"] == "INFO" :
318 resultString = resultString + "main.log.info(" + message + ")"
319 elif args["LOGLEVEL"] == "ERROR" :
320 resultString = resultString + "main.log.error(" + message + ")"
321 elif args["LOGLEVEL"] == "DEBUG" :
322 resultString = resultString + "main.log.debug(" + message + ")"
323 elif args["LOGLEVEL"] == "REPORT" :
Jon Hall4ba53f02015-07-29 13:07:41 -0700324 resultString = resultString + "main.log.report(" + message + ")"
adminbae64d82013-08-01 10:50:15 -0700325 elif args["LOGLEVEL"] == "CRITICAL" :
326 resultString = resultString + "main.log.critical(" + message + ")"
327 elif args["LOGLEVEL"] == "WARN" :
328 resultString = resultString + "main.log.warn(" + args["MESSAGE"] + ")"
329 elif args["LOGLEVEL"] == "EXACT" :
Jon Hall4ba53f02015-07-29 13:07:41 -0700330 resultString = resultString + "main.log.exact(" + args["MESSAGE"] + ")"
adminbae64d82013-08-01 10:50:15 -0700331
Jon Hall4ba53f02015-07-29 13:07:41 -0700332
adminbae64d82013-08-01 10:50:15 -0700333 return resultString
334
335 def translate_log_message(self,**messageStatement) :
336 '''
337 This API will translate log messages if it is a string or Variable or combination
Jon Hall4ba53f02015-07-29 13:07:41 -0700338 of string and variable.
adminbae64d82013-08-01 10:50:15 -0700339 It will return the analysed and translate message.
340 '''
341 args = self.parse_args(["MESSAGE"],**messageStatement)
342 resultString = ''
343
344 paramsMatch = re.match("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESULT|LAST_RESPONSE",args["MESSAGE"],flags=0)
345 stringMatch = re.match("\s*\"(.*)\"\s*$",args["MESSAGE"],flags=0)
346 stringWidVariableMatch = re.match("\"(.*)\"\s+\+\s+(.*)",args["MESSAGE"],flags=0)
347 varRefMatch = re.search("\<(\w+)\>",args["MESSAGE"],flags=0)
348 if paramsMatch :
349 resultString = resultString + self.translate_parameters(parameters=args["MESSAGE"])
350 elif stringMatch :
351 resultString = resultString + args["MESSAGE"]
352 elif stringWidVariableMatch:
353 quoteWord = stringWidVariableMatch.group(1)
354 variableRef = stringWidVariableMatch.group(2)
355 varMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]",variableRef,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700356 varRefMatch = re.search("\<(\w+)\>",variableRef,flags=0)
adminbae64d82013-08-01 10:50:15 -0700357 if varMatch :
358 resultString = resultString + "\"" + quoteWord + "\"" + " + " + self.translate_parameters(parameters=variableRef)
359 elif varRefMatch :
360 resultString = resultString + "\"" + quoteWord + "\"" + " + " + varRefMatch.group(1)
361 elif varRefMatch:
362 resultString = resultString + varRefMatch.group(1)
Jon Hall4ba53f02015-07-29 13:07:41 -0700363 else :
364 print "\nError : Syntax error , Not defined way to give log message" + args["MESSAGE"]
adminbae64d82013-08-01 10:50:15 -0700365
Jon Hall4ba53f02015-07-29 13:07:41 -0700366 return resultString
367
adminbae64d82013-08-01 10:50:15 -0700368 def translate_assertion(self,**assertStatement):
369 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700370 This will translate the ASSERT <value1> <COMPARISON OPERATOR> <value2> into python
adminbae64d82013-08-01 10:50:15 -0700371 equivalent to resultString and returns resultString
372 '''
373 args = self.parse_args(["LEFTVALUE","OPERATOR","RIGHTVALUE","ONPASS","ONFAIL"],**assertStatement)
374 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700375 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700376 notOperatorMatch = re.search("NOT\s+(.*)",args["OPERATOR"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700377 notOperatorSymbMatch = re.search("\!(.*)",args["OPERATOR"],flags=0)
adminbae64d82013-08-01 10:50:15 -0700378 operator = ''
379 lastresultMatch = re.match("LAST_RESULT",args["RIGHTVALUE"],flags=0)
380 lastresponseMatch = re.match("LAST_RESPONSE",args["RIGHTVALUE"],flags=0)
381 if lastresultMatch :
382 operator = "main.last_result"
383 elif lastresponseMatch :
384 operator = "main.last_response"
385 else :
386 operator = args["RIGHTVALUE"]
Jon Hall4ba53f02015-07-29 13:07:41 -0700387
adminbae64d82013-08-01 10:50:15 -0700388 if args["OPERATOR"] == None or args["OPERATOR"] == "" :
389 print "\n Error : Operator has not been specified !!!"
390 elif notOperatorMatch or notOperatorSymbMatch:
Jon Hall4ba53f02015-07-29 13:07:41 -0700391
adminbae64d82013-08-01 10:50:15 -0700392 operators = notOperatorMatch.group(1) if notOperatorMatch else notOperatorSymbMatch.group(1)
393 operators = self.translate_operator(operator=operators)
394 if self.grtrOrLssr == 0 :
395 resultString = resultString + "utilities.assert_not_" + operators + "(expect=" +\
396 self.translate_response_result(operator=args["RIGHTVALUE"]) + ",actual=" + self.translate_response_result(operator=args["LEFTVALUE"]) +\
397 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
398 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
399 else :
400 resultString = resultString + "utilities.assert_not_" + operators + "(expect=" +\
401 self.translate_response_result(operator=args["LEFTVALUE"]) + ",actual=" + self.translate_response_result(operator=args["RIGHTVALUE"]) +\
402 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
403 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
404
Jon Hall4ba53f02015-07-29 13:07:41 -0700405 else :
adminbae64d82013-08-01 10:50:15 -0700406 operators = self.translate_operator(operator=args["OPERATOR"])
407 if self.grtrOrLssr == 0 :
408 resultString = resultString + "utilities.assert_" + operators + "(expect=" +\
409 self.translate_response_result(operator=args["RIGHTVALUE"]) +\
410 ",actual=" + self.translate_response_result(operator=args["LEFTVALUE"]) +\
411 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
412 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
413 else :
414 resultString = resultString + "utilities.assert_" + operators + "(expect=" +\
415 self.translate_response_result(operator=args["LEFTVALUE"]) +\
416 ",actual=" + self.translate_response_result(operator=args["RIGHTVALUE"]) +\
417 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
418 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
Jon Hall4ba53f02015-07-29 13:07:41 -0700419
420
adminbae64d82013-08-01 10:50:15 -0700421 return resultString
422
423 def translate_response_result(self,**operatorStatement):
424 '''
425 It will translate the LAST_RESPONSE or LAST_RESULT statement into its equivalent.
426 It returns the translate form in resulString.
427 '''
428 args = self.parse_args(["OPERATOR"],**operatorStatement)
429 resultString = ''
430 lastResultMatch = re.match("LAST_RESULT",args["OPERATOR"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700431 lastResponseMatch = re.match("LAST_RESPONSE",args["OPERATOR"],flags=0)
adminbae64d82013-08-01 10:50:15 -0700432 if lastResultMatch :
433 resultString = resultString + "main.last_result"
434 elif lastResponseMatch:
435 resultString = resultString + "main.last_response"
436 else :
437 resultString = resultString + args["OPERATOR"]
438 return resultString
439
Jon Hall4ba53f02015-07-29 13:07:41 -0700440
adminbae64d82013-08-01 10:50:15 -0700441 def translate_assertMessage(self,**messageStatement) :
442 '''
443 This API will facilitate the translation of assert ONPASS or ONFAIL messages . The message can be
444 a string or calling another API in OpenSpeak syntax.
445 It will return the translated message
446 '''
447 args = self.parse_args(["MESSAGE"],**messageStatement)
Jon Hall4ba53f02015-07-29 13:07:41 -0700448
adminbae64d82013-08-01 10:50:15 -0700449 connectMatch = re.search("CONNECT\s+(\w+)\s+USING\s+(.*)",args["MESSAGE"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700450 disconnectMatch = re.search("DISCONNECT\s+(.*)",args["MESSAGE"],flags=0)
adminbae64d82013-08-01 10:50:15 -0700451 ondoMatch = re.search("ON\s+(.*)\s+DO\s+(.*)",args["MESSAGE"],flags=0)
452 paramsMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]",args["MESSAGE"],flags=0)
453 stringMatch = re.search("\"(.*)\"|\'(.*)\'",args["MESSAGE"],flags=0)
454 variableMatch = re.search("\<(.*)\>",args["MESSAGE"],flags=0)
455
456 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700457 if connectMatch :
adminbae64d82013-08-01 10:50:15 -0700458 resultString = resultString + self.translate_connect(component=connectMatch.group(1),
459 arguments=connectMatch.group(2) )
460 elif disconnectMatch :
461 resultString = resultString + self.translate_disconnect(component=disconnectMatch.group(1))
462 elif ondoMatch :
463 resultString = resultString + self.translate_onDOAs(component=ondoMatch.group(1),
464 action=ondoMatch.group(2))
465 elif paramsMatch :
466 resultString = resultString + self.translate_parameters(parameters=args["MESSAGE"])
Jon Hall4ba53f02015-07-29 13:07:41 -0700467 elif stringMatch :
adminbae64d82013-08-01 10:50:15 -0700468 resultString = resultString + "\"" + stringMatch.group(1) + "\""
469 elif variableMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700470 resultString = resultString + variableMatch.group(1)
adminbae64d82013-08-01 10:50:15 -0700471 elif args["MESSAGE"] == None :
Jon Hall4ba53f02015-07-29 13:07:41 -0700472 print "\n Error : Please pass a message or action for assertion "
473
474 return resultString
475
adminbae64d82013-08-01 10:50:15 -0700476 def translate_operator(self,**operatorStatement) :
477 '''
478 It will translate the operator for assertion , by ensuring against given arguments.
479 It will return the translated assertion operator.
480 '''
481 args = self.parse_args(["OPERATOR"],**operatorStatement)
Jon Hall4ba53f02015-07-29 13:07:41 -0700482
adminbae64d82013-08-01 10:50:15 -0700483 resultString = ''
484 equalsMatch = re.match("EQUALS$|==$",args["OPERATOR"],flags=0)
485 greaterMatch = re.match("GREATER\s+THAN$|>$",args["OPERATOR"],flags=0)
486 lesserMatch = re.match("LESSER\s+THAN$|<$",args["OPERATOR"],flags=0)
487 stringMatch = re.match("MATCHES|~$",args["OPERATOR"],flags=0)
488 greaterEqualMatch = re.match("GREATER\s+THAN\s+OR\s+EQUALS$|>=$",args["OPERATOR"],flags=0)
489 lesserEqualMatch = re.match("LESSER\s+THAN\s+OR\s+EQUALS$|<=$",args["OPERATOR"],flags=0)
490 if equalsMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700491
adminbae64d82013-08-01 10:50:15 -0700492 resultString = resultString + "equals"
Jon Hall4ba53f02015-07-29 13:07:41 -0700493 elif greaterMatch :
adminbae64d82013-08-01 10:50:15 -0700494 self.grtrOrLssr = self.grtrOrLssr + 1
495 resultString = resultString + "greater"
Jon Hall4ba53f02015-07-29 13:07:41 -0700496 elif lesserMatch :
adminbae64d82013-08-01 10:50:15 -0700497 self.grtrOrLssr = self.grtrOrLssr + 1
498 resultString = resultString + "lesser"
499 elif stringMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700500
adminbae64d82013-08-01 10:50:15 -0700501 resultString = resultString + "matches"
502 elif greaterEqualMatch:
Jon Hall4ba53f02015-07-29 13:07:41 -0700503
adminbae64d82013-08-01 10:50:15 -0700504 resultString = resultString + "greater_equals"
505 elif lesserEqualMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700506
adminbae64d82013-08-01 10:50:15 -0700507 resultString = resultString + "lesser_equals"
508 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700509 print "\n Error: Given Operator is not listed for assertion"
510 return resultString
adminbae64d82013-08-01 10:50:15 -0700511
512 def translate_store(self,**storeStatement):
513 '''
514 This will translate the STORE <variable> IN <value> or <variable> = <value>
515 into python equivalent to resultString and returns resultString
516 '''
517 args = self.parse_args(["VARIABLE","VALUE"],**storeStatement)
518 resultString = ''
519 # convert the statement here
520 ondoMatch = re.match("^\s*ON\s+(.*)\s+DO\s+(.*)",args["VALUE"],flags=0)
521 paramsMatch = re.match("^\s*PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESULT|LAST_RESPONSE",args["VALUE"],flags=0)
522 if paramsMatch :
523 argString = self.translate_parameters(parameters=args["VALUE"])
524 resultString = args["VARIABLE"] + " = " + argString
525 elif ondoMatch :
526 resultString = args["VARIABLE"] + " = " + self.translate_onDOAs(component=ondoMatch.group(1),action=ondoMatch.group(2))
527 else :
528 resultString = args["VARIABLE"] + " = " + args["VALUE"]
529
530
531 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700532
adminbae64d82013-08-01 10:50:15 -0700533 def translate_disconnect(self,**disconnectStatement):
534 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700535 This will translate the DISCONNECT <component_name> into python
adminbae64d82013-08-01 10:50:15 -0700536 equivalent to resultString and returns resultString
537 '''
538 args = self.parse_args(["COMPONENT"],**disconnectStatement)
539 resultString = ''
540 # convert the statement here
Jon Hall4ba53f02015-07-29 13:07:41 -0700541 resultString = "main." + args["COMPONENT"] + ".disconnect()"
adminbae64d82013-08-01 10:50:15 -0700542 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700543
adminbae64d82013-08-01 10:50:15 -0700544 def translate_onDOAs(self,**onDoStatement):
545 '''
546 This will translate the ON <component> DO <action> USING <arg1> AS <value1>,<arg2> AS <value2>
547 into python equivalent to resultString and returns resultString
548 '''
549 args = self.parse_args(["COMPONENT","ACTION","ARGUMENTS"],**onDoStatement)
550 subString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700551
adminbae64d82013-08-01 10:50:15 -0700552 usingMatch = re.match("\s*(.*)\s+USING\s+(.*)",args["ACTION"],flags=0)
553 action = ''
554 if usingMatch :
555 action = usingMatch.group(1)
556 arguments = usingMatch.group(2)
557 subString = self.translate_usingas(arguments=arguments)
Jon Hall4ba53f02015-07-29 13:07:41 -0700558
adminbae64d82013-08-01 10:50:15 -0700559 else :
560 andCheck = re.search ("(.*)\s+AND\s+(.*)",args["ACTION"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700561
adminbae64d82013-08-01 10:50:15 -0700562 action = action + "()"
563 if andCheck:
564 action = andCheck.group(1) + "()"
565 subString = subString + self.handle_conjuction(statement=andCheck.group(2))
566 else :
567 action = args["ACTION"]
568 action = action + "()"
Jon Hall4ba53f02015-07-29 13:07:41 -0700569 # convert the statement here
570 resultString = "main." + args["COMPONENT"] + "." + action + subString
adminbae64d82013-08-01 10:50:15 -0700571 return resultString
572
Jon Hall4ba53f02015-07-29 13:07:41 -0700573
adminbae64d82013-08-01 10:50:15 -0700574 def handle_conjuction(self,**conjuctStatement):
575 '''
576 This will handle the conjuctions
577 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700578
adminbae64d82013-08-01 10:50:15 -0700579 args = self.parse_args(["STATEMENT"],**conjuctStatement)
580 subSentence = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700581
adminbae64d82013-08-01 10:50:15 -0700582 storeMatch = re.match("\s*STORE\s+(.*)\s+IN\s+(.*)",args["STATEMENT"],flags=0)
583 assertMatch = re.match("\s*ASSERT\s+(\w+)\s+(.*)\s+(.*)\s+ONPASS\s+(.*)\s+ONFAIL\s+(.*)",args["STATEMENT"],flags=0)
584 if storeMatch :
585 subSentence = "\n" + " " * 8 + self.translate_store(variable=storeMatch.group(2),
586 value=storeMatch.group(1))
587 elif assertMatch :
588 subSentence = "\n" + " " * 8 + self.translate_assertion(leftvalue=assertMatch.group(1),
589 operator=assertMatch.group(2),
590 rightvalue=assertMatch.group(3),
591 onpass=assertMatch.group(4),
592 onfail=assertMatch.group(5))
593 return subSentence
594
595 def translate_usingas(self,**argumentAS) :
596 '''
597 This will tranlate USING argument AS value Statement into equivalent argument passing.
598 It will return translated form into resultString
599 '''
600 args = self.parse_args(["ARGUMENTS"],**argumentAS)
601 resultString = ''
602 argsList = []
603 subString = ''
604 subSentence = ''
605 line = ''
606 andCheck = re.search ("(.*)\s+AND\s+(.*)",args["ARGUMENTS"],flags=0)
607 if andCheck:
608 line = andCheck.group(1)
609 subSentence = self.handle_conjuction(statement=andCheck.group(2))
610 else :
611 line = args["ARGUMENTS"]
Jon Hall4ba53f02015-07-29 13:07:41 -0700612
613
614
adminbae64d82013-08-01 10:50:15 -0700615 argsMatch = re.search("(.*),(.*)",line,flags=0)
616
617
618 if args["ARGUMENTS"] == None or args["ARGUMENTS"] == '' :
619 subString = ''
620 elif argsMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700621
adminbae64d82013-08-01 10:50:15 -0700622 argsList = line.split(",")
623 for index, arguments in enumerate(argsList):
624 argMatch = re.search("(.*)\s+AS\s+(.*)",arguments,flags=0)
625 if argMatch:
626 argsKey = argMatch.group(1)
627 argsValue = argMatch.group(2)
628 paramsMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESPONSE|LAST_RESULT",argsValue,flags=0)
629 if not paramsMatch :
630 if index == len(argsList) - 1 :
631 subString = subString + argsKey + "=" + argsValue
632 else :
633 subString = subString + argsKey + "=" + argsValue + ","
634 else :
635 argString = self.translate_parameters(parameters=argsValue)
636 if index == len(argsList) - 1 :
637 subString = subString + argsKey + "=" + argString
638 else :
639 subString = subString + argsKey + "=" + argString + ","
640 else :
641 if index == len(argsList) - 1 :
642 subString = subString + arguments
643 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700644 subString = subString + arguments + ","
adminbae64d82013-08-01 10:50:15 -0700645 else :
646 argMatch = re.search("(.*)\s+AS\s+(.*)",args["ARGUMENTS"],flags=0)
647 if argMatch:
648 argsKey = argMatch.group(1)
649 argsValue = argMatch.group(2)
650 paramsMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESPONSE|LAST_RESULT",argsValue,flags=0)
651 if not paramsMatch :
652 subString = subString + argsKey + "=" + argsValue
653 else :
654 argString = self.translate_parameters(parameters=argsValue)
655 subString = subString + argsKey + "=" + argString
656 else :
657 paramsMatch = re.match("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESPONSE|LAST_RESULT",line,flags=0)
658 if paramsMatch :
659 subString = subString + self.translate_parameters(parameters=line)
660 else :
661 subString = subString + line
662 resultString = "(" + subString + ")"+ subSentence
663 return resultString
664
665
666 def translate_connect(self,**connectStatement):
667 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700668 This will translate the CONNECT <component_name> USING1 <arg1> AS <value1>, <arg2> AS <value2>
adminbae64d82013-08-01 10:50:15 -0700669 into python equivalent to resultString and returns resultString
670 '''
671 args = self.parse_args(["COMPONENT","ARGUMENTS"],**connectStatement)
672 resultString = ''
673 subString = self.translate_usingas(arguments=args["ARGUMENTS"])
Jon Hall4ba53f02015-07-29 13:07:41 -0700674 # convert the statement here
675 resultString = "main." + args["COMPONENT"] + ".connect(" + subString + ")"
adminbae64d82013-08-01 10:50:15 -0700676 return resultString
677
678
679 def translate_parameters(self,**parameterStatement):
680 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700681 This will translate the OpenSpeak Case and Params parameters into python equivalent
adminbae64d82013-08-01 10:50:15 -0700682 to resultString and returns resultString
683 '''
684 args = self.parse_args(["PARAMETERS"],**parameterStatement)
685 argument = args["PARAMETERS"]
686 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700687 ### match arguments
adminbae64d82013-08-01 10:50:15 -0700688 paramsMatch = re.search("PARAMS((\[(.*)\])*)",argument,flags=0)
689 stepsMatch = re.search("STEP((\[(.*)\])*)",argument,flags=0)
690 casesMatch = re.search("CASE((\[(.*)\])*)",argument,flags=0)
691 topoMatch = re.search("TOPO((\[(.*)\])*)",argument,flags=0)
692 lastResultMatch = re.match("LAST_RESULT",argument,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700693 lastResponseMatch = re.match("LAST_RESPONSE",argument,flags=0)
adminbae64d82013-08-01 10:50:15 -0700694 # convert the statement here
695 if paramsMatch :
696 params = paramsMatch.group(1)
Jon Hall4ba53f02015-07-29 13:07:41 -0700697 resultString = resultString + "main.params" + self._argsCheck(checkvar=params)
adminbae64d82013-08-01 10:50:15 -0700698 elif stepsMatch :
699 resultString = resultString +"main.params[\'" + self.CurrentCase +\
700 "\'][\'STEP" + str(self.CurrentStep) + "\']" +\
701 self._argsCheck(checkvar=stepsMatch.group(1))
702 elif casesMatch :
703 resultString = resultString + "main.params[\'" + self.CurrentCase + "\']" +\
704 self._argsCheck(checkvar=casesMatch.group(1))
705 elif topoMatch :
706 resultString = resultString + "main.componentDictionary" +\
707 self._argsCheck(checkvar=topoMatch.group(1))
708 elif lastResultMatch :
709 resultString = resultString + "main.last_result"
Jon Hall4ba53f02015-07-29 13:07:41 -0700710 elif lastResponseMatch :
711 resultString = resultString + "main.last_response"
adminbae64d82013-08-01 10:50:15 -0700712 return resultString
713
714 def _argsCheck(self,**args):
715 ''' This API will check if given argument is varibale reference or String and will translate accordingly.
716 It will return the tanslate form in resultString.
Jon Hall4ba53f02015-07-29 13:07:41 -0700717 '''
adminbae64d82013-08-01 10:50:15 -0700718 args = self.parse_args(["CHECKVAR"],**args)
719 params = args["CHECKVAR"]
720 argsList = params.split("]")
721 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700722 del argsList[len(argsList) - 1]
adminbae64d82013-08-01 10:50:15 -0700723 for index,paramArgs in enumerate(argsList) :
724 argsWidVariable = re.search("(\"|\')\s*(\w+)\s*(\'|\")",paramArgs,flags=0)
725 if argsWidVariable :
726 resultString = resultString + "[\'" + argsWidVariable.group(2) + "\']"
727 else :
728 resultString = resultString + paramArgs + "]"
729 return resultString
730
731 def translate_step(self,**stepStatement):
732 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700733 This will translate the STEP "DO SOMETHING HERE" into python equivalent
adminbae64d82013-08-01 10:50:15 -0700734 to resultString and returns resultString
735 '''
736 args = self.parse_args(["STEP"],**stepStatement)
737 resultString = ''
738 resultString = "main.step(\"" + args["STEP"] + "\")"
Jon Hall4ba53f02015-07-29 13:07:41 -0700739 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700740 return resultString
741
Jon Hall4ba53f02015-07-29 13:07:41 -0700742
adminbae64d82013-08-01 10:50:15 -0700743 def translate_comment(self,**commentStatement):
744 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700745 This will translate the COMMENT "DO SOMETHING HERE" into python equivalent
adminbae64d82013-08-01 10:50:15 -0700746 to resultString and returns resultString
747 '''
748 args = self.parse_args(["COMMENT"],**commentStatement)
749 resultString = ''
750 resultString = "#" + args["COMMENT"]
Jon Hall4ba53f02015-07-29 13:07:41 -0700751 # convert the statement here
752 return resultString
753
adminbae64d82013-08-01 10:50:15 -0700754 def translate_testcase_name(self,**nameStatement):
755 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700756 This method will convert NAME "<Testcase_name>" into python equivalent statement
757 to resultString and returns resultString
758 '''
adminbae64d82013-08-01 10:50:15 -0700759 args = self.parse_args(["TESTNAME"],**nameStatement)
Jon Hall4ba53f02015-07-29 13:07:41 -0700760
adminbae64d82013-08-01 10:50:15 -0700761 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700762 resultString = "main.case(\"" + args["TESTNAME"] + "\")"
763 # convert the statement here
764 return resultString
765
766
adminbae64d82013-08-01 10:50:15 -0700767 def translate_case_block(self,**caseBlock):
768 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700769 This method will translate the case block in test script .
adminbae64d82013-08-01 10:50:15 -0700770 It returns the translated equivalent python code for test script
771 '''
772 args = self.parse_args(["CASENUMBER"],**caseBlock)
773 resultString = ""
774 resultString = "def CASE" + str(args["CASENUMBER"]) + "(self,main) :\n"
Jon Hall4ba53f02015-07-29 13:07:41 -0700775 # process the caseBlock List translate all statements underlying the given case
adminbae64d82013-08-01 10:50:15 -0700776 return resultString
777
Jon Hall4ba53f02015-07-29 13:07:41 -0700778
779
adminbae64d82013-08-01 10:50:15 -0700780 def translate_loop_block(self,*loopBlock):
781 '''
782 This method will translate for loop block into its equivalent python code.
Jon Hall4ba53f02015-07-29 13:07:41 -0700783 Whole loop block will be passed into loopBlock List.
adminbae64d82013-08-01 10:50:15 -0700784 It returns the transalted reuslt as a string.
785 '''
786 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700787 # process the loopBlock List translate all statements underlying the given loop block
788 return resultString
789
790
adminbae64d82013-08-01 10:50:15 -0700791 def translate_conjuction(self,conjuctionStatement):
792 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700793 This will translate the AND conjuction statements into python equivalent
adminbae64d82013-08-01 10:50:15 -0700794 to resultString and returns resultString
795 '''
796 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700797 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700798 return resultString
799
800
801 def parse_args(self,args, **kwargs):
802 '''
803 It will accept the (key,value) pair and will return the (key,value) pairs with keys in uppercase.
804 '''
805 newArgs = {}
806 for key,value in kwargs.iteritems():
807 #currentKey = str.upper(key)
808 if isinstance(args,list) and str.upper(key) in args:
Jon Hall4ba53f02015-07-29 13:07:41 -0700809 for each in args:
adminbae64d82013-08-01 10:50:15 -0700810 if each==str.upper(key):
811 newArgs [str(each)] = value
812 elif each != str.upper(key) and (newArgs.has_key(str(each)) == False ):
813 newArgs[str(each)] = None
Jon Hall4ba53f02015-07-29 13:07:41 -0700814
815
816
adminbae64d82013-08-01 10:50:15 -0700817 return newArgs