blob: 37949108cf3abd5d9ab0ce58c60816ad5188cc91 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#/usr/bin/env python
2'''
3Created on 20-Dec-2012
Jon Hall4ba53f02015-07-29 13:07:41 -07004
adminbae64d82013-08-01 10:50:15 -07005@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
6
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
Jon Hall4ba53f02015-07-29 13:07:41 -070019 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070020
21
22'''
23import re
24import inspect
25
26
27class OpenSpeak:
28
29 def __init__(self):
30 self.default = ''
Jon Hall4ba53f02015-07-29 13:07:41 -070031 self.flag = 0
adminbae64d82013-08-01 10:50:15 -070032 self.CurrentStep = 0
33 self.grtrOrLssr = 0
34
35 def compiler(self,**compileParameters):
36 '''
Jon Hall4ba53f02015-07-29 13:07:41 -070037 This method will parse the openspeak file and will write to a python module with the equivalent translations.
38 It can accept OpenSpeak syntax in string or an OpenSpeak file as an input parameter.
adminbae64d82013-08-01 10:50:15 -070039 Translated form can be written into python module if attribute "WRITETOFILE" is set to 1.
40 '''
Jon Hall4ba53f02015-07-29 13:07:41 -070041
adminbae64d82013-08-01 10:50:15 -070042 args = self.parse_args(["OPENSPEAKFILE","TEXT","WRITETOFILE","FILEHANDLE"],**compileParameters)
43 resultString = ''
44 Test = "Mininet"
45 args["WRITETOFILE"] = args["WRITETOFILE"] if args["WRITETOFILE"] != None else 1
46 self.CurrentStep = 0
47 self.CurrentCase = ''
Jon Hall4ba53f02015-07-29 13:07:41 -070048
adminbae64d82013-08-01 10:50:15 -070049 ## here Open Speak file will be parsed by each line and translated.
50 if args["OPENSPEAKFILE"] !=None and args["TEXT"] ==None and args["FILEHANDLE"] == None:
51 self.openspeakfile = args["OPENSPEAKFILE"]
52 openSpeakFile = open(args["OPENSPEAKFILE"],"r").readlines()
Jon Hall4ba53f02015-07-29 13:07:41 -070053
54 elif args["OPENSPEAKFILE"] ==None and args["TEXT"] and args["FILEHANDLE"] == None:
55 openSpeakFile = args["TEXT"].split("\n")
adminbae64d82013-08-01 10:50:15 -070056 elif args["FILEHANDLE"] and args["OPENSPEAKFILE"] ==None and args["TEXT"] ==None:
57 openSpeakFile = args["FILEHANDLE"].readlines()
Jon Hall4ba53f02015-07-29 13:07:41 -070058
adminbae64d82013-08-01 10:50:15 -070059 index = 0
60 outputFile = []
61 testName = re.search("\/(.*)\.ospk$",self.openspeakfile,0)
62 testName = testName.group(1)
63 testName = testName.split("/")
64 testName = testName[len(testName)-1]
65 outputFile.append("\nclass " + testName + " :" + "\n")
66 outputFile.append("\n" + " " * 4 + "def __init__(self) :")
Jon Hall4ba53f02015-07-29 13:07:41 -070067 outputFile.append("\n" + " " * 8 + "self.default = \'\'" + "\n")
68
adminbae64d82013-08-01 10:50:15 -070069 while index < len(openSpeakFile):
70 ifelseMatch = re.match("\s+IF|\s+ELSE|\s+ELIF",openSpeakFile[index],flags=0)
71 line = openSpeakFile[index]
72 repeatMatch = re.match("\s*REPEAT", openSpeakFile[index], flags=0)
73 if ifelseMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -070074 result = self.verify_and_translate(line)
adminbae64d82013-08-01 10:50:15 -070075 initialSpaces = len(line) -len(line.lstrip())
Jon Hall4ba53f02015-07-29 13:07:41 -070076 self.outLoopSpace = initialSpaces
adminbae64d82013-08-01 10:50:15 -070077 nextLine = openSpeakFile[index+1]
78 nextinitialSpaces = len(nextLine) -len(nextLine.lstrip())
Jon Hall4ba53f02015-07-29 13:07:41 -070079
80
adminbae64d82013-08-01 10:50:15 -070081 while nextinitialSpaces > initialSpaces :
82 try :
83 elseMatch = re.match("\s*ELSE|\s*ELIF",nextLine,flags=0)
84 if elseMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -070085 self.flag = self.flag -1
86 result = result + self.verify_and_translate(nextLine)
adminbae64d82013-08-01 10:50:15 -070087 nextLine = openSpeakFile[index + 1]
88 nextinitialSpaces = len(nextLine) -len(nextLine.lstrip())
89 except IndexError:
Jon Hall4ba53f02015-07-29 13:07:41 -070090 pass
adminbae64d82013-08-01 10:50:15 -070091 index = index + 1
Jon Hall4ba53f02015-07-29 13:07:41 -070092 self.flag = 0
adminbae64d82013-08-01 10:50:15 -070093 elif repeatMatch:
94 self.flag = 0
95 result = self.verify_and_translate(line)
96 index = index + 1
97 endMatch = re.match("\s*END",openSpeakFile[index],flags=0)
98 while not endMatch :
99 try :
Jon Hall4ba53f02015-07-29 13:07:41 -0700100
adminbae64d82013-08-01 10:50:15 -0700101 self.flag = self.flag + 1
102 result = result + self.verify_and_translate(openSpeakFile[index])
103 index = index + 1
Jon Hall4ba53f02015-07-29 13:07:41 -0700104
adminbae64d82013-08-01 10:50:15 -0700105 except IndexError :
106 pass
Jon Hall4ba53f02015-07-29 13:07:41 -0700107
108
adminbae64d82013-08-01 10:50:15 -0700109 else :
110 self.flag = 0
111 result = self.verify_and_translate(line)
112 index = index + 1
113 outputFile.append(result)
114
115 if args["WRITETOFILE"] == 1 :
116 testscript = re.sub("ospk","py",self.openspeakfile,0)
117 testScript = open(testscript,"w")
118 for lines in outputFile :
119 testScript.write(lines)
120 testScript.close()
121 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700122
adminbae64d82013-08-01 10:50:15 -0700123 def verify_and_translate(self,line):
124 '''
125 It will accept the each line and calls the suitable API to conver into pyton equivalent syntax .
Jon Hall4ba53f02015-07-29 13:07:41 -0700126 It will return the translated python syntax .
127 '''
adminbae64d82013-08-01 10:50:15 -0700128 lineSpace = re.match("^\s+",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700129 initialSpaces = len(line) -len(line.lstrip())
130 line = re.sub("^\s+","",line) if lineSpace else line
131
132
adminbae64d82013-08-01 10:50:15 -0700133 resultString = None
134 resultString = "\n" + " " * 4 if str(inspect.stack()[1][3]) == "compiler" else "\n"
Jon Hall4ba53f02015-07-29 13:07:41 -0700135 indent = " " *(4 + 4 * self.flag) if self.flag > 0 else " " * 4
adminbae64d82013-08-01 10:50:15 -0700136 caseMatch = re.search("^CASE\s+(\d+)",line,flags=0)
137 nameMatch = re.match("^NAME\s+\"(.*)\"",line,flags=0)
138 commentMatch = re.match("^COMMENT\s+\"(.*)\"",line,flags=0)
139 stepMatch = re.match("^STEP\s+\"(.*)\"",line,flags=0)
140 connectMatch = re.match("^CONNECT\s+(\w+)\s+USING\s+(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700141 disconnectMatch = re.match("^DISCONNECT\s+(.*)",line,flags=0)
adminbae64d82013-08-01 10:50:15 -0700142 ondoMatch = re.match("^ON\s+(.*)\s+DO\s+(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700143
adminbae64d82013-08-01 10:50:15 -0700144 storeMatch = re.match("^STORE\s+(.*)\s+IN\s+(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700145 variableMatch = re.match("^(.*)\s+=\s+(.*)",line,flags=0)
adminbae64d82013-08-01 10:50:15 -0700146 assertMatch = re.match("^ASSERT\s+(\w+)\s+(.*)\s+(.*)\s+ONPASS\s+(.*)\s+ONFAIL\s+(.*)",line,flags=0)
147 logMatch = re.match("^(ERROR|INFO|DEBUG|CRITICAL|REPORT|EXACT|WARN)\s+(.*)",line,flags=0)
148 ifloop = re.match("IF\s+(\w+)\s*(..|\w+)\s*(.*)",line,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700149 elseloopMatch = re.match("ELSE\s*$",line,flags=0)
adminbae64d82013-08-01 10:50:15 -0700150 elifloop = re.match("ELSE\sIF\s+(\w+)\s*(..|\w+)\s*(.*)",line,flags=0)
151 forloopMatch = re.match("\s*REPEAT\s+(/d+)\s+TIMES",line,flags=0)
152 experimentalMatch = re.match("EXPERIMENTAL\s+MODE\s+(\w+)",line,flags=0)
153 repeatMatch = re.match("\s*REPEAT\s+(\d+)\s+TIMES", line, flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700154
adminbae64d82013-08-01 10:50:15 -0700155 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 -0700156
adminbae64d82013-08-01 10:50:15 -0700157 if caseMatch :
158 self.CurrentStep = 0
159 self.CurrentCase = "CASE" + caseMatch.group(1)
160 resultString = resultString + self.translate_case_block(casenumber=caseMatch.group(1))
161 elif repeatMatch:
162 resultString = resultString + indent + self.translate_repeat(repeat=repeatMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700163 elif nameMatch :
adminbae64d82013-08-01 10:50:15 -0700164 resultString = resultString + indent + self.translate_testcase_name(testname=nameMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700165 elif commentMatch :
adminbae64d82013-08-01 10:50:15 -0700166 resultString = resultString + indent + self.translate_comment(comment=commentMatch.group(1))
167 elif stepMatch :
168 self.CurrentStep = self.CurrentStep + 1
169 resultString = resultString + indent + self.translate_step(step=stepMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700170 elif connectMatch :
adminbae64d82013-08-01 10:50:15 -0700171 resultString = resultString + indent + self.translate_connect(component=connectMatch.group(1),
172 arguments=connectMatch.group(2) )
173 elif disconnectMatch :
174 resultString = resultString + indent + self.translate_disconnect(component=disconnectMatch.group(1))
175 elif ondoMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700176 resultString = resultString + indent + self.translate_onDOAs(component=ondoMatch.group(1),action=ondoMatch.group(2))
adminbae64d82013-08-01 10:50:15 -0700177 elif storeMatch :
178 resultString = resultString + indent + self.translate_store(variable=storeMatch.group(2),
Jon Hall4ba53f02015-07-29 13:07:41 -0700179 value=storeMatch.group(1))
adminbae64d82013-08-01 10:50:15 -0700180 elif variableMatch :
181 resultString = resultString + indent + self.translate_store(variable=variableMatch.group(1),
182 value=variableMatch.group(2))
183 elif assertMatch :
184 resultString = resultString + indent + self.translate_assertion(leftvalue=assertMatch.group(1),
185 operator=assertMatch.group(2),
186 rightvalue=assertMatch.group(3),
187 onpass=assertMatch.group(4),
Jon Hall4ba53f02015-07-29 13:07:41 -0700188 onfail=assertMatch.group(5))
adminbae64d82013-08-01 10:50:15 -0700189 elif logMatch :
190 resultString = resultString + indent + self.translate_logs(loglevel=logMatch.group(1),
191 message=logMatch.group(2))
192 elif ifloop :
Jon Hall4ba53f02015-07-29 13:07:41 -0700193
194 self.initSpace = initialSpaces
adminbae64d82013-08-01 10:50:15 -0700195 operand = ifloop.group(1)
196 operator = ifloop.group(2)
Jon Hall4ba53f02015-07-29 13:07:41 -0700197 value = ifloop.group(3)
198 resultString = resultString + indent + "if " + operand + self.translate_if_else_operator(conditionoperator=operator) + value + ":"
199 self.flag = self.flag + 1
adminbae64d82013-08-01 10:50:15 -0700200 elif experimentalMatch :
201 resultString = resultString + indent + self.translate_experimental_mode(mode=experimentalMatch.group(1))
Jon Hall4ba53f02015-07-29 13:07:41 -0700202
adminbae64d82013-08-01 10:50:15 -0700203 elif elseloopMatch :
204 if initialSpaces == self.initSpace or initialSpaces == self.outLoopSpace:
205 resultString = resultString + indent + "else :"
206 self.flag = self.flag + 1
207 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700208 indent = " " *(4 + 4 * (self.flag-1))
adminbae64d82013-08-01 10:50:15 -0700209 resultString = resultString + indent + "else :"
210 self.flag = self.flag + 1
Jon Hall4ba53f02015-07-29 13:07:41 -0700211
adminbae64d82013-08-01 10:50:15 -0700212 elif elifloop :
Jon Hall4ba53f02015-07-29 13:07:41 -0700213
adminbae64d82013-08-01 10:50:15 -0700214 operand = elifloop.group(1)
215 operator = elifloop.group(2)
Jon Hall4ba53f02015-07-29 13:07:41 -0700216 value = elifloop.group(3)
adminbae64d82013-08-01 10:50:15 -0700217 if initialSpaces == self.initSpace or initialSpaces == self.outLoopSpace:
Jon Hall4ba53f02015-07-29 13:07:41 -0700218 resultString = resultString + indent + "elif " + operand + self.translate_if_else_operator(conditionoperator=operator) + value + ":"
219 self.flag = self.flag + 1
adminbae64d82013-08-01 10:50:15 -0700220 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700221 indent = " " *(4 + 4 * (self.flag-1))
222 resultString = resultString + indent + "elif " + operand + self.translate_if_else_operator(conditionoperator=operator) + value + ":"
adminbae64d82013-08-01 10:50:15 -0700223 self.flag = self.flag + 1
224 elif response_pasrse :
225 output_string = response_pasrse.group(1)
226 req_format = response_pasrse.group(2)
227 store_in = response_pasrse.group(3)
Jon Hall4ba53f02015-07-29 13:07:41 -0700228 resultString = resultString + indent + store_in +'= main.response_parser('+output_string+",\""+req_format+"\")"
229 self.flag = self.flag + 1
adminbae64d82013-08-01 10:50:15 -0700230
231 return resultString
232
233 def translate_repeat(self,**repeatStatement):
234 '''
235 this will transalte the repeat statement into a python equivalen while loop
236 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700237
adminbae64d82013-08-01 10:50:15 -0700238 args = self.parse_args(["REPEAT"],**repeatStatement)
239 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700240
adminbae64d82013-08-01 10:50:15 -0700241 resultString = "i = 0"
242 resultString = resultString + "\n" + " " * 8 +"while i<" + args["REPEAT"] + " :"
243 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700244
adminbae64d82013-08-01 10:50:15 -0700245 def translate_if_else_operator(self,**loopBlock):
246 '''
247 This method will translate if-else loop block into its equivalent python code.
Jon Hall4ba53f02015-07-29 13:07:41 -0700248 Whole loop block will be passed into loopBlock List.
adminbae64d82013-08-01 10:50:15 -0700249 It returns the transalted reuslt as a string.
250 '''
251 args = self.parse_args(["CONDITIONOPERATOR"],**loopBlock)
252 resultString = ''
253 # process the loopBlock List translate all statements underlying the given loop block
254 equalsMatch = re.match("EQUALS$|==\s*$",args["CONDITIONOPERATOR"],flags=0)
255 greaterMatch = re.match("GREATER\s+THAN$|>\s*$",args["CONDITIONOPERATOR"],flags=0)
256 lesserMatch = re.match("LESSER\s+THAN$|<\s*$",args["CONDITIONOPERATOR"],flags=0)
257 greaterEqualMatch = re.match("GREATER\s+THAN\s+OR\s+EQUALS$|>=\s*$",args["CONDITIONOPERATOR"],flags=0)
258 lesserEqualMatch = re.match("LESSER\s+THAN\s+OR\s+EQUALS$|<=\s*$",args["CONDITIONOPERATOR"],flags=0)
259 if equalsMatch :
260 resultString = resultString + " == "
Jon Hall4ba53f02015-07-29 13:07:41 -0700261 elif greaterMatch :
adminbae64d82013-08-01 10:50:15 -0700262 resultString = resultString + " > "
Jon Hall4ba53f02015-07-29 13:07:41 -0700263 elif lesserMatch :
264 resultString = resultString + " < "
adminbae64d82013-08-01 10:50:15 -0700265 elif greaterEqualMatch:
266 resultString = resultString + " >= "
267 elif lesserEqualMatch :
268 resultString = resultString + " <= "
269 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700270 print "\n Error: Given Operator is not listed "
271
272 return resultString
273
adminbae64d82013-08-01 10:50:15 -0700274 def translate_experimental_mode(self,**modeType):
275 '''
276 This API will translate statment EXPERIMENTAL MODE ON/OFF into python equivalent.
277 It will return the transalted value.
278 '''
279 args = self.parse_args(["MODE"],**modeType)
280 resultString = ''
281 ONmatch = re.match("\s*ON",args["MODE"],flags=0)
282 OFFmatch = re.match("\sOFF",args["MODE"],flags=0)
283
284 if ONmatch :
285 resultString = "main.EXPERIMENTAL_MODE = main.TRUE"
286 elif OFFmatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700287 resultString = "main.EXPERIMENTAL_MODE = main.FALSE"
adminbae64d82013-08-01 10:50:15 -0700288
289 return resultString
290
291 def interpret(self,**interpetParameters):
292 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700293 This method will accept the OpenSpeak syntax into a string and will return
adminbae64d82013-08-01 10:50:15 -0700294 a python equivalent translations statement
295 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700296
adminbae64d82013-08-01 10:50:15 -0700297 args = self.parse_args(["TEXT","WRITETOFILE"],**interpetParameters)
298 resultString = ''
299 ## here Open Speak syntax will be translated into python equivalent.
300 resultString = self.verify_and_translate(args["TEXT"])
301 lineSpace = re.match("^\s+",resultString,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700302
303 resultString = re.sub("^\s+","",resultString) if lineSpace else resultString
adminbae64d82013-08-01 10:50:15 -0700304 return resultString
305
306 def translate_logs(self,**logStatement):
307 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700308 This will translate the OpenSpeak log message statements into python equivalent
adminbae64d82013-08-01 10:50:15 -0700309 to resultString and returns resultString
310 '''
311 args = self.parse_args(["LOGLEVEL","MESSAGE"],**logStatement)
312 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700313 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700314 message = self.translate_log_message(message=args["MESSAGE"])
315 if args["LOGLEVEL"] == "INFO" :
316 resultString = resultString + "main.log.info(" + message + ")"
317 elif args["LOGLEVEL"] == "ERROR" :
318 resultString = resultString + "main.log.error(" + message + ")"
319 elif args["LOGLEVEL"] == "DEBUG" :
320 resultString = resultString + "main.log.debug(" + message + ")"
321 elif args["LOGLEVEL"] == "REPORT" :
Jon Hall4ba53f02015-07-29 13:07:41 -0700322 resultString = resultString + "main.log.report(" + message + ")"
adminbae64d82013-08-01 10:50:15 -0700323 elif args["LOGLEVEL"] == "CRITICAL" :
324 resultString = resultString + "main.log.critical(" + message + ")"
325 elif args["LOGLEVEL"] == "WARN" :
326 resultString = resultString + "main.log.warn(" + args["MESSAGE"] + ")"
327 elif args["LOGLEVEL"] == "EXACT" :
Jon Hall4ba53f02015-07-29 13:07:41 -0700328 resultString = resultString + "main.log.exact(" + args["MESSAGE"] + ")"
adminbae64d82013-08-01 10:50:15 -0700329
Jon Hall4ba53f02015-07-29 13:07:41 -0700330
adminbae64d82013-08-01 10:50:15 -0700331 return resultString
332
333 def translate_log_message(self,**messageStatement) :
334 '''
335 This API will translate log messages if it is a string or Variable or combination
Jon Hall4ba53f02015-07-29 13:07:41 -0700336 of string and variable.
adminbae64d82013-08-01 10:50:15 -0700337 It will return the analysed and translate message.
338 '''
339 args = self.parse_args(["MESSAGE"],**messageStatement)
340 resultString = ''
341
342 paramsMatch = re.match("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESULT|LAST_RESPONSE",args["MESSAGE"],flags=0)
343 stringMatch = re.match("\s*\"(.*)\"\s*$",args["MESSAGE"],flags=0)
344 stringWidVariableMatch = re.match("\"(.*)\"\s+\+\s+(.*)",args["MESSAGE"],flags=0)
345 varRefMatch = re.search("\<(\w+)\>",args["MESSAGE"],flags=0)
346 if paramsMatch :
347 resultString = resultString + self.translate_parameters(parameters=args["MESSAGE"])
348 elif stringMatch :
349 resultString = resultString + args["MESSAGE"]
350 elif stringWidVariableMatch:
351 quoteWord = stringWidVariableMatch.group(1)
352 variableRef = stringWidVariableMatch.group(2)
353 varMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]",variableRef,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700354 varRefMatch = re.search("\<(\w+)\>",variableRef,flags=0)
adminbae64d82013-08-01 10:50:15 -0700355 if varMatch :
356 resultString = resultString + "\"" + quoteWord + "\"" + " + " + self.translate_parameters(parameters=variableRef)
357 elif varRefMatch :
358 resultString = resultString + "\"" + quoteWord + "\"" + " + " + varRefMatch.group(1)
359 elif varRefMatch:
360 resultString = resultString + varRefMatch.group(1)
Jon Hall4ba53f02015-07-29 13:07:41 -0700361 else :
362 print "\nError : Syntax error , Not defined way to give log message" + args["MESSAGE"]
adminbae64d82013-08-01 10:50:15 -0700363
Jon Hall4ba53f02015-07-29 13:07:41 -0700364 return resultString
365
adminbae64d82013-08-01 10:50:15 -0700366 def translate_assertion(self,**assertStatement):
367 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700368 This will translate the ASSERT <value1> <COMPARISON OPERATOR> <value2> into python
adminbae64d82013-08-01 10:50:15 -0700369 equivalent to resultString and returns resultString
370 '''
371 args = self.parse_args(["LEFTVALUE","OPERATOR","RIGHTVALUE","ONPASS","ONFAIL"],**assertStatement)
372 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700373 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700374 notOperatorMatch = re.search("NOT\s+(.*)",args["OPERATOR"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700375 notOperatorSymbMatch = re.search("\!(.*)",args["OPERATOR"],flags=0)
adminbae64d82013-08-01 10:50:15 -0700376 operator = ''
377 lastresultMatch = re.match("LAST_RESULT",args["RIGHTVALUE"],flags=0)
378 lastresponseMatch = re.match("LAST_RESPONSE",args["RIGHTVALUE"],flags=0)
379 if lastresultMatch :
380 operator = "main.last_result"
381 elif lastresponseMatch :
382 operator = "main.last_response"
383 else :
384 operator = args["RIGHTVALUE"]
Jon Hall4ba53f02015-07-29 13:07:41 -0700385
adminbae64d82013-08-01 10:50:15 -0700386 if args["OPERATOR"] == None or args["OPERATOR"] == "" :
387 print "\n Error : Operator has not been specified !!!"
388 elif notOperatorMatch or notOperatorSymbMatch:
Jon Hall4ba53f02015-07-29 13:07:41 -0700389
adminbae64d82013-08-01 10:50:15 -0700390 operators = notOperatorMatch.group(1) if notOperatorMatch else notOperatorSymbMatch.group(1)
391 operators = self.translate_operator(operator=operators)
392 if self.grtrOrLssr == 0 :
393 resultString = resultString + "utilities.assert_not_" + operators + "(expect=" +\
394 self.translate_response_result(operator=args["RIGHTVALUE"]) + ",actual=" + self.translate_response_result(operator=args["LEFTVALUE"]) +\
395 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
396 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
397 else :
398 resultString = resultString + "utilities.assert_not_" + operators + "(expect=" +\
399 self.translate_response_result(operator=args["LEFTVALUE"]) + ",actual=" + self.translate_response_result(operator=args["RIGHTVALUE"]) +\
400 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
401 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
402
Jon Hall4ba53f02015-07-29 13:07:41 -0700403 else :
adminbae64d82013-08-01 10:50:15 -0700404 operators = self.translate_operator(operator=args["OPERATOR"])
405 if self.grtrOrLssr == 0 :
406 resultString = resultString + "utilities.assert_" + operators + "(expect=" +\
407 self.translate_response_result(operator=args["RIGHTVALUE"]) +\
408 ",actual=" + self.translate_response_result(operator=args["LEFTVALUE"]) +\
409 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
410 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
411 else :
412 resultString = resultString + "utilities.assert_" + operators + "(expect=" +\
413 self.translate_response_result(operator=args["LEFTVALUE"]) +\
414 ",actual=" + self.translate_response_result(operator=args["RIGHTVALUE"]) +\
415 ",onpass=" + self.translate_assertMessage(message=args["ONPASS"]) +\
416 ",onfail=" + self.translate_assertMessage(message=args["ONFAIL"]) + ")"
Jon Hall4ba53f02015-07-29 13:07:41 -0700417
418
adminbae64d82013-08-01 10:50:15 -0700419 return resultString
420
421 def translate_response_result(self,**operatorStatement):
422 '''
423 It will translate the LAST_RESPONSE or LAST_RESULT statement into its equivalent.
424 It returns the translate form in resulString.
425 '''
426 args = self.parse_args(["OPERATOR"],**operatorStatement)
427 resultString = ''
428 lastResultMatch = re.match("LAST_RESULT",args["OPERATOR"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700429 lastResponseMatch = re.match("LAST_RESPONSE",args["OPERATOR"],flags=0)
adminbae64d82013-08-01 10:50:15 -0700430 if lastResultMatch :
431 resultString = resultString + "main.last_result"
432 elif lastResponseMatch:
433 resultString = resultString + "main.last_response"
434 else :
435 resultString = resultString + args["OPERATOR"]
436 return resultString
437
Jon Hall4ba53f02015-07-29 13:07:41 -0700438
adminbae64d82013-08-01 10:50:15 -0700439 def translate_assertMessage(self,**messageStatement) :
440 '''
441 This API will facilitate the translation of assert ONPASS or ONFAIL messages . The message can be
442 a string or calling another API in OpenSpeak syntax.
443 It will return the translated message
444 '''
445 args = self.parse_args(["MESSAGE"],**messageStatement)
Jon Hall4ba53f02015-07-29 13:07:41 -0700446
adminbae64d82013-08-01 10:50:15 -0700447 connectMatch = re.search("CONNECT\s+(\w+)\s+USING\s+(.*)",args["MESSAGE"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700448 disconnectMatch = re.search("DISCONNECT\s+(.*)",args["MESSAGE"],flags=0)
adminbae64d82013-08-01 10:50:15 -0700449 ondoMatch = re.search("ON\s+(.*)\s+DO\s+(.*)",args["MESSAGE"],flags=0)
450 paramsMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]",args["MESSAGE"],flags=0)
451 stringMatch = re.search("\"(.*)\"|\'(.*)\'",args["MESSAGE"],flags=0)
452 variableMatch = re.search("\<(.*)\>",args["MESSAGE"],flags=0)
453
454 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700455 if connectMatch :
adminbae64d82013-08-01 10:50:15 -0700456 resultString = resultString + self.translate_connect(component=connectMatch.group(1),
457 arguments=connectMatch.group(2) )
458 elif disconnectMatch :
459 resultString = resultString + self.translate_disconnect(component=disconnectMatch.group(1))
460 elif ondoMatch :
461 resultString = resultString + self.translate_onDOAs(component=ondoMatch.group(1),
462 action=ondoMatch.group(2))
463 elif paramsMatch :
464 resultString = resultString + self.translate_parameters(parameters=args["MESSAGE"])
Jon Hall4ba53f02015-07-29 13:07:41 -0700465 elif stringMatch :
adminbae64d82013-08-01 10:50:15 -0700466 resultString = resultString + "\"" + stringMatch.group(1) + "\""
467 elif variableMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700468 resultString = resultString + variableMatch.group(1)
adminbae64d82013-08-01 10:50:15 -0700469 elif args["MESSAGE"] == None :
Jon Hall4ba53f02015-07-29 13:07:41 -0700470 print "\n Error : Please pass a message or action for assertion "
471
472 return resultString
473
adminbae64d82013-08-01 10:50:15 -0700474 def translate_operator(self,**operatorStatement) :
475 '''
476 It will translate the operator for assertion , by ensuring against given arguments.
477 It will return the translated assertion operator.
478 '''
479 args = self.parse_args(["OPERATOR"],**operatorStatement)
Jon Hall4ba53f02015-07-29 13:07:41 -0700480
adminbae64d82013-08-01 10:50:15 -0700481 resultString = ''
482 equalsMatch = re.match("EQUALS$|==$",args["OPERATOR"],flags=0)
483 greaterMatch = re.match("GREATER\s+THAN$|>$",args["OPERATOR"],flags=0)
484 lesserMatch = re.match("LESSER\s+THAN$|<$",args["OPERATOR"],flags=0)
485 stringMatch = re.match("MATCHES|~$",args["OPERATOR"],flags=0)
486 greaterEqualMatch = re.match("GREATER\s+THAN\s+OR\s+EQUALS$|>=$",args["OPERATOR"],flags=0)
487 lesserEqualMatch = re.match("LESSER\s+THAN\s+OR\s+EQUALS$|<=$",args["OPERATOR"],flags=0)
488 if equalsMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700489
adminbae64d82013-08-01 10:50:15 -0700490 resultString = resultString + "equals"
Jon Hall4ba53f02015-07-29 13:07:41 -0700491 elif greaterMatch :
adminbae64d82013-08-01 10:50:15 -0700492 self.grtrOrLssr = self.grtrOrLssr + 1
493 resultString = resultString + "greater"
Jon Hall4ba53f02015-07-29 13:07:41 -0700494 elif lesserMatch :
adminbae64d82013-08-01 10:50:15 -0700495 self.grtrOrLssr = self.grtrOrLssr + 1
496 resultString = resultString + "lesser"
497 elif stringMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700498
adminbae64d82013-08-01 10:50:15 -0700499 resultString = resultString + "matches"
500 elif greaterEqualMatch:
Jon Hall4ba53f02015-07-29 13:07:41 -0700501
adminbae64d82013-08-01 10:50:15 -0700502 resultString = resultString + "greater_equals"
503 elif lesserEqualMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700504
adminbae64d82013-08-01 10:50:15 -0700505 resultString = resultString + "lesser_equals"
506 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700507 print "\n Error: Given Operator is not listed for assertion"
508 return resultString
adminbae64d82013-08-01 10:50:15 -0700509
510 def translate_store(self,**storeStatement):
511 '''
512 This will translate the STORE <variable> IN <value> or <variable> = <value>
513 into python equivalent to resultString and returns resultString
514 '''
515 args = self.parse_args(["VARIABLE","VALUE"],**storeStatement)
516 resultString = ''
517 # convert the statement here
518 ondoMatch = re.match("^\s*ON\s+(.*)\s+DO\s+(.*)",args["VALUE"],flags=0)
519 paramsMatch = re.match("^\s*PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESULT|LAST_RESPONSE",args["VALUE"],flags=0)
520 if paramsMatch :
521 argString = self.translate_parameters(parameters=args["VALUE"])
522 resultString = args["VARIABLE"] + " = " + argString
523 elif ondoMatch :
524 resultString = args["VARIABLE"] + " = " + self.translate_onDOAs(component=ondoMatch.group(1),action=ondoMatch.group(2))
525 else :
526 resultString = args["VARIABLE"] + " = " + args["VALUE"]
527
528
529 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700530
adminbae64d82013-08-01 10:50:15 -0700531 def translate_disconnect(self,**disconnectStatement):
532 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700533 This will translate the DISCONNECT <component_name> into python
adminbae64d82013-08-01 10:50:15 -0700534 equivalent to resultString and returns resultString
535 '''
536 args = self.parse_args(["COMPONENT"],**disconnectStatement)
537 resultString = ''
538 # convert the statement here
Jon Hall4ba53f02015-07-29 13:07:41 -0700539 resultString = "main." + args["COMPONENT"] + ".disconnect()"
adminbae64d82013-08-01 10:50:15 -0700540 return resultString
Jon Hall4ba53f02015-07-29 13:07:41 -0700541
adminbae64d82013-08-01 10:50:15 -0700542 def translate_onDOAs(self,**onDoStatement):
543 '''
544 This will translate the ON <component> DO <action> USING <arg1> AS <value1>,<arg2> AS <value2>
545 into python equivalent to resultString and returns resultString
546 '''
547 args = self.parse_args(["COMPONENT","ACTION","ARGUMENTS"],**onDoStatement)
548 subString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700549
adminbae64d82013-08-01 10:50:15 -0700550 usingMatch = re.match("\s*(.*)\s+USING\s+(.*)",args["ACTION"],flags=0)
551 action = ''
552 if usingMatch :
553 action = usingMatch.group(1)
554 arguments = usingMatch.group(2)
555 subString = self.translate_usingas(arguments=arguments)
Jon Hall4ba53f02015-07-29 13:07:41 -0700556
adminbae64d82013-08-01 10:50:15 -0700557 else :
558 andCheck = re.search ("(.*)\s+AND\s+(.*)",args["ACTION"],flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700559
adminbae64d82013-08-01 10:50:15 -0700560 action = action + "()"
561 if andCheck:
562 action = andCheck.group(1) + "()"
563 subString = subString + self.handle_conjuction(statement=andCheck.group(2))
564 else :
565 action = args["ACTION"]
566 action = action + "()"
Jon Hall4ba53f02015-07-29 13:07:41 -0700567 # convert the statement here
568 resultString = "main." + args["COMPONENT"] + "." + action + subString
adminbae64d82013-08-01 10:50:15 -0700569 return resultString
570
Jon Hall4ba53f02015-07-29 13:07:41 -0700571
adminbae64d82013-08-01 10:50:15 -0700572 def handle_conjuction(self,**conjuctStatement):
573 '''
574 This will handle the conjuctions
575 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700576
adminbae64d82013-08-01 10:50:15 -0700577 args = self.parse_args(["STATEMENT"],**conjuctStatement)
578 subSentence = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700579
adminbae64d82013-08-01 10:50:15 -0700580 storeMatch = re.match("\s*STORE\s+(.*)\s+IN\s+(.*)",args["STATEMENT"],flags=0)
581 assertMatch = re.match("\s*ASSERT\s+(\w+)\s+(.*)\s+(.*)\s+ONPASS\s+(.*)\s+ONFAIL\s+(.*)",args["STATEMENT"],flags=0)
582 if storeMatch :
583 subSentence = "\n" + " " * 8 + self.translate_store(variable=storeMatch.group(2),
584 value=storeMatch.group(1))
585 elif assertMatch :
586 subSentence = "\n" + " " * 8 + self.translate_assertion(leftvalue=assertMatch.group(1),
587 operator=assertMatch.group(2),
588 rightvalue=assertMatch.group(3),
589 onpass=assertMatch.group(4),
590 onfail=assertMatch.group(5))
591 return subSentence
592
593 def translate_usingas(self,**argumentAS) :
594 '''
595 This will tranlate USING argument AS value Statement into equivalent argument passing.
596 It will return translated form into resultString
597 '''
598 args = self.parse_args(["ARGUMENTS"],**argumentAS)
599 resultString = ''
600 argsList = []
601 subString = ''
602 subSentence = ''
603 line = ''
604 andCheck = re.search ("(.*)\s+AND\s+(.*)",args["ARGUMENTS"],flags=0)
605 if andCheck:
606 line = andCheck.group(1)
607 subSentence = self.handle_conjuction(statement=andCheck.group(2))
608 else :
609 line = args["ARGUMENTS"]
Jon Hall4ba53f02015-07-29 13:07:41 -0700610
611
612
adminbae64d82013-08-01 10:50:15 -0700613 argsMatch = re.search("(.*),(.*)",line,flags=0)
614
615
616 if args["ARGUMENTS"] == None or args["ARGUMENTS"] == '' :
617 subString = ''
618 elif argsMatch :
Jon Hall4ba53f02015-07-29 13:07:41 -0700619
adminbae64d82013-08-01 10:50:15 -0700620 argsList = line.split(",")
621 for index, arguments in enumerate(argsList):
622 argMatch = re.search("(.*)\s+AS\s+(.*)",arguments,flags=0)
623 if argMatch:
624 argsKey = argMatch.group(1)
625 argsValue = argMatch.group(2)
626 paramsMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESPONSE|LAST_RESULT",argsValue,flags=0)
627 if not paramsMatch :
628 if index == len(argsList) - 1 :
629 subString = subString + argsKey + "=" + argsValue
630 else :
631 subString = subString + argsKey + "=" + argsValue + ","
632 else :
633 argString = self.translate_parameters(parameters=argsValue)
634 if index == len(argsList) - 1 :
635 subString = subString + argsKey + "=" + argString
636 else :
637 subString = subString + argsKey + "=" + argString + ","
638 else :
639 if index == len(argsList) - 1 :
640 subString = subString + arguments
641 else :
Jon Hall4ba53f02015-07-29 13:07:41 -0700642 subString = subString + arguments + ","
adminbae64d82013-08-01 10:50:15 -0700643 else :
644 argMatch = re.search("(.*)\s+AS\s+(.*)",args["ARGUMENTS"],flags=0)
645 if argMatch:
646 argsKey = argMatch.group(1)
647 argsValue = argMatch.group(2)
648 paramsMatch = re.search("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESPONSE|LAST_RESULT",argsValue,flags=0)
649 if not paramsMatch :
650 subString = subString + argsKey + "=" + argsValue
651 else :
652 argString = self.translate_parameters(parameters=argsValue)
653 subString = subString + argsKey + "=" + argString
654 else :
655 paramsMatch = re.match("PARAMS\[(.*)\]|STEP\[(.*)\]|TOPO\[(.*)\]|CASE\[(.*)\]|LAST_RESPONSE|LAST_RESULT",line,flags=0)
656 if paramsMatch :
657 subString = subString + self.translate_parameters(parameters=line)
658 else :
659 subString = subString + line
660 resultString = "(" + subString + ")"+ subSentence
661 return resultString
662
663
664 def translate_connect(self,**connectStatement):
665 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700666 This will translate the CONNECT <component_name> USING1 <arg1> AS <value1>, <arg2> AS <value2>
adminbae64d82013-08-01 10:50:15 -0700667 into python equivalent to resultString and returns resultString
668 '''
669 args = self.parse_args(["COMPONENT","ARGUMENTS"],**connectStatement)
670 resultString = ''
671 subString = self.translate_usingas(arguments=args["ARGUMENTS"])
Jon Hall4ba53f02015-07-29 13:07:41 -0700672 # convert the statement here
673 resultString = "main." + args["COMPONENT"] + ".connect(" + subString + ")"
adminbae64d82013-08-01 10:50:15 -0700674 return resultString
675
676
677 def translate_parameters(self,**parameterStatement):
678 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700679 This will translate the OpenSpeak Case and Params parameters into python equivalent
adminbae64d82013-08-01 10:50:15 -0700680 to resultString and returns resultString
681 '''
682 args = self.parse_args(["PARAMETERS"],**parameterStatement)
683 argument = args["PARAMETERS"]
684 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700685 ### match arguments
adminbae64d82013-08-01 10:50:15 -0700686 paramsMatch = re.search("PARAMS((\[(.*)\])*)",argument,flags=0)
687 stepsMatch = re.search("STEP((\[(.*)\])*)",argument,flags=0)
688 casesMatch = re.search("CASE((\[(.*)\])*)",argument,flags=0)
689 topoMatch = re.search("TOPO((\[(.*)\])*)",argument,flags=0)
690 lastResultMatch = re.match("LAST_RESULT",argument,flags=0)
Jon Hall4ba53f02015-07-29 13:07:41 -0700691 lastResponseMatch = re.match("LAST_RESPONSE",argument,flags=0)
adminbae64d82013-08-01 10:50:15 -0700692 # convert the statement here
693 if paramsMatch :
694 params = paramsMatch.group(1)
Jon Hall4ba53f02015-07-29 13:07:41 -0700695 resultString = resultString + "main.params" + self._argsCheck(checkvar=params)
adminbae64d82013-08-01 10:50:15 -0700696 elif stepsMatch :
697 resultString = resultString +"main.params[\'" + self.CurrentCase +\
698 "\'][\'STEP" + str(self.CurrentStep) + "\']" +\
699 self._argsCheck(checkvar=stepsMatch.group(1))
700 elif casesMatch :
701 resultString = resultString + "main.params[\'" + self.CurrentCase + "\']" +\
702 self._argsCheck(checkvar=casesMatch.group(1))
703 elif topoMatch :
704 resultString = resultString + "main.componentDictionary" +\
705 self._argsCheck(checkvar=topoMatch.group(1))
706 elif lastResultMatch :
707 resultString = resultString + "main.last_result"
Jon Hall4ba53f02015-07-29 13:07:41 -0700708 elif lastResponseMatch :
709 resultString = resultString + "main.last_response"
adminbae64d82013-08-01 10:50:15 -0700710 return resultString
711
712 def _argsCheck(self,**args):
713 ''' This API will check if given argument is varibale reference or String and will translate accordingly.
714 It will return the tanslate form in resultString.
Jon Hall4ba53f02015-07-29 13:07:41 -0700715 '''
adminbae64d82013-08-01 10:50:15 -0700716 args = self.parse_args(["CHECKVAR"],**args)
717 params = args["CHECKVAR"]
718 argsList = params.split("]")
719 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700720 del argsList[len(argsList) - 1]
adminbae64d82013-08-01 10:50:15 -0700721 for index,paramArgs in enumerate(argsList) :
722 argsWidVariable = re.search("(\"|\')\s*(\w+)\s*(\'|\")",paramArgs,flags=0)
723 if argsWidVariable :
724 resultString = resultString + "[\'" + argsWidVariable.group(2) + "\']"
725 else :
726 resultString = resultString + paramArgs + "]"
727 return resultString
728
729 def translate_step(self,**stepStatement):
730 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700731 This will translate the STEP "DO SOMETHING HERE" into python equivalent
adminbae64d82013-08-01 10:50:15 -0700732 to resultString and returns resultString
733 '''
734 args = self.parse_args(["STEP"],**stepStatement)
735 resultString = ''
736 resultString = "main.step(\"" + args["STEP"] + "\")"
Jon Hall4ba53f02015-07-29 13:07:41 -0700737 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700738 return resultString
739
Jon Hall4ba53f02015-07-29 13:07:41 -0700740
adminbae64d82013-08-01 10:50:15 -0700741 def translate_comment(self,**commentStatement):
742 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700743 This will translate the COMMENT "DO SOMETHING HERE" into python equivalent
adminbae64d82013-08-01 10:50:15 -0700744 to resultString and returns resultString
745 '''
746 args = self.parse_args(["COMMENT"],**commentStatement)
747 resultString = ''
748 resultString = "#" + args["COMMENT"]
Jon Hall4ba53f02015-07-29 13:07:41 -0700749 # convert the statement here
750 return resultString
751
adminbae64d82013-08-01 10:50:15 -0700752 def translate_testcase_name(self,**nameStatement):
753 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700754 This method will convert NAME "<Testcase_name>" into python equivalent statement
755 to resultString and returns resultString
756 '''
adminbae64d82013-08-01 10:50:15 -0700757 args = self.parse_args(["TESTNAME"],**nameStatement)
Jon Hall4ba53f02015-07-29 13:07:41 -0700758
adminbae64d82013-08-01 10:50:15 -0700759 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700760 resultString = "main.case(\"" + args["TESTNAME"] + "\")"
761 # convert the statement here
762 return resultString
763
764
adminbae64d82013-08-01 10:50:15 -0700765 def translate_case_block(self,**caseBlock):
766 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700767 This method will translate the case block in test script .
adminbae64d82013-08-01 10:50:15 -0700768 It returns the translated equivalent python code for test script
769 '''
770 args = self.parse_args(["CASENUMBER"],**caseBlock)
771 resultString = ""
772 resultString = "def CASE" + str(args["CASENUMBER"]) + "(self,main) :\n"
Jon Hall4ba53f02015-07-29 13:07:41 -0700773 # process the caseBlock List translate all statements underlying the given case
adminbae64d82013-08-01 10:50:15 -0700774 return resultString
775
Jon Hall4ba53f02015-07-29 13:07:41 -0700776
777
adminbae64d82013-08-01 10:50:15 -0700778 def translate_loop_block(self,*loopBlock):
779 '''
780 This method will translate for loop block into its equivalent python code.
Jon Hall4ba53f02015-07-29 13:07:41 -0700781 Whole loop block will be passed into loopBlock List.
adminbae64d82013-08-01 10:50:15 -0700782 It returns the transalted reuslt as a string.
783 '''
784 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700785 # process the loopBlock List translate all statements underlying the given loop block
786 return resultString
787
788
adminbae64d82013-08-01 10:50:15 -0700789 def translate_conjuction(self,conjuctionStatement):
790 '''
Jon Hall4ba53f02015-07-29 13:07:41 -0700791 This will translate the AND conjuction statements into python equivalent
adminbae64d82013-08-01 10:50:15 -0700792 to resultString and returns resultString
793 '''
794 resultString = ''
Jon Hall4ba53f02015-07-29 13:07:41 -0700795 # convert the statement here
adminbae64d82013-08-01 10:50:15 -0700796 return resultString
797
798
799 def parse_args(self,args, **kwargs):
800 '''
801 It will accept the (key,value) pair and will return the (key,value) pairs with keys in uppercase.
802 '''
803 newArgs = {}
804 for key,value in kwargs.iteritems():
805 #currentKey = str.upper(key)
806 if isinstance(args,list) and str.upper(key) in args:
Jon Hall4ba53f02015-07-29 13:07:41 -0700807 for each in args:
adminbae64d82013-08-01 10:50:15 -0700808 if each==str.upper(key):
809 newArgs [str(each)] = value
810 elif each != str.upper(key) and (newArgs.has_key(str(each)) == False ):
811 newArgs[str(each)] = None
Jon Hall4ba53f02015-07-29 13:07:41 -0700812
813
814
adminbae64d82013-08-01 10:50:15 -0700815 return newArgs