How to use suite_setup method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

Test.py

Source:Test.py Github

copy

Full Screen

1import winpexpect2from robot.running import TestSuite3import subprocess4import sys5import re6import os7from robot import utils8from robot.reporting import ResultWriter9import dataStructure10import tempfile11import postProcess12import signal13import yaml14class testInfo(object):15 def __init__(self, scriptName):16 self.scriptName = scriptName17 self.tcInfo = dataStructure.nestedDict()18 self.currentTcid = 'suite_setup'19 self.variableFile = variableFile()20 self.scriptResult = 'FAIL'21 def appendLog(self, msg, timestamp, tcid=None):22 if tcid is None:23 tcid = self.currentTcid24 if 'msgList' not in self.tcInfo[tcid]:25 self.tcInfo[tcid]['msgList'] = []26 self.tcInfo[tcid]['timestamps'] = []27 self.variableFile.initTcInfo(tcid)28 self.tcInfo[tcid]['msgList'].append(msg)29 self.tcInfo[tcid]['timestamps'].append(timestamp)30 self.variableFile.appendLog(tcid, msg, timestamp)31 def setScriptResult(self, status):32 self.scriptResult = status33 def setResult(self, status, tcid=None):34 if tcid is None:35 tcid = self.currentTcid36 self.tcInfo[tcid]['result'] = status37 self.variableFile.setResult(tcid, status)38 def setTcid(self, id):39 self.currentTcid = id40 def setLogFile(self, fileName):41 self.logFileName = fileName42 def flush(self):43 self.variableFile.flush()44 45class variableFile(object):46 def __init__(self):47 self.file = tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=True, suffix='.py')48 self.name = self.file.name49 self.file.write('# coding=utf-8\n')50 self.file.write('import dataStructure\n')51 self.file.write('testcaseInfo = dataStructure.nestedDict()\n')52 self.file.write('setupLog = dataStructure.nestedDict()\n')53 self.file.write('cleanupLog = dataStructure.nestedDict()\n')54 def initTcInfo(self, tcid):55 if tcid is 'suite_setup':56 self.file.write('setupLog["msgList"] = []\n')57 self.file.write('setupLog["timestamps"] = []\n')58 elif tcid is 'suite_cleanup':59 self.file.write('cleanupLog["msgList"] = []\n')60 self.file.write('cleanupLog["timestamps"] = []\n')61 else:62 self.file.write('testcaseInfo["%s"]["msgList"] = []\n' %tcid)63 self.file.write('testcaseInfo["%s"]["timestamps"] = []\n' %tcid)64 def appendLog(self, tcid, msg, timestamp):65 if tcid is 'suite_setup':66 self.file.write('setupLog["msgList"].append("%s")\n' %msg)67 self.file.write('setupLog["timestamps"].append("%s")\n' %timestamp)68 elif tcid is 'suite_cleanup':69 self.file.write('cleanupLog["msgList"].append("%s")\n' %msg)70 self.file.write('cleanupLog["timestamps"].append("%s")\n' %timestamp)71 else:72 self.file.write('testcaseInfo["%s"]["msgList"].append("%s")\n' %(tcid, msg))73 self.file.write('testcaseInfo["%s"]["timestamps"].append("%s")\n' %(tcid, timestamp))74 def setResult(self, tcid, status):75 if tcid is 'suite_setup':76 self.file.write('setupLog["result"] = "%s"\n' %status)77 elif tcid is 'suite_cleanup':78 self.file.write('cleanupLog["result"] = "%s"\n' %status)79 else:80 self.file.write('testcaseInfo["%s"]["result"] = "%s"\n' %(tcid, status))81 def flush(self):82 self.file.flush()83 def close(self):84 self.file.close()85 # This will remove the .pyc file created for the variable file86 if os.path.isfile(self.name+'c'):87 os.remove(self.name+'c')88def createRobotSuite(testcaseInfo):89 suite = TestSuite(os.path.basename(testcaseInfo.scriptName))90 suite.imports.library('logModule')91 suite.imports.variables(testcaseInfo.variableFile.name)92 tcList = [val for val in testcaseInfo.tcInfo.keys() if val not in ['suite_setup', 'suite_cleanup']]93 if tcList:94 ## This suite has f10 testcases defined95 ## suite_setup should precede suite_cleanup. Otherwise, both will be set as None.96 if 'suite_setup' in testcaseInfo.tcInfo.keys():97 suite.keywords.create('setup_log', args=['${setupLog}'], type='setup')98 if 'suite_cleanup' in testcaseInfo.tcInfo.keys():99 suite.keywords.create('cleanup_log', args=['${cleanupLog}'], type='teardown')100 else:101 ## This suite has no f10 testcases defined in the script. Entire script should be treated as one testcase102 if 'suite_cleanup' in testcaseInfo.tcInfo.keys():103 suite.keywords.create('cleanup_log', args=['${cleanupLog}'], type='teardown')104 test = suite.tests.create(testcaseInfo.scriptName, tags=None)105 test.keywords.create('testcase_log', args=['${setupLog}', 'result=%s' %testcaseInfo.scriptResult])106 107 for tcid in testcaseInfo.tcInfo.keys():108 if tcid in ['suite_setup', 'suite_cleanup']:109 pass110 else:111 test = suite.tests.create(tcid, tags=None)112 print testcaseInfo113 test.keywords.create('testcase_log', args=['${testcaseInfo}', 'tcid=%s' %tcid])114 return suite115def scriptExecutionMonitor(output):116 global testcaseInfo117 global testcaseInfoList118 global bufferLine119 global yamlCont120 121 if 'bufferLine' not in globals():122 bufferLine = ''123 tempOut = bufferLine + output124 for line in tempOut.split('\n')[0:-1]:125 try:126 scriptStart = re.search(yamlCont["scriptStart"], line)127 if scriptStart:128 scriptName = scriptStart.group(1)129 testcaseInfo = testInfo(scriptName)130 testcaseInfoList.append(testcaseInfo)131 except:132 pass133 134 try:135 scriptCleanup = re.search(yamlCont["scriptCleanup"], line)136 if scriptCleanup:137 testcaseInfo.setTcid('suite_cleanup')138 except:139 pass140 141 try:142 scriptCleanup = re.search(yamlCont["scriptStartup"], line)143 if scriptCleanup:144 testcaseInfo.setTcid('suite_startup')145 except:146 pass147 148 try:149 testcaseStart = re.search(yamlCont["testcaseStart"], line)150 if testcaseStart:151 testcaseInfo.setTcid("%s" %(testcaseStart.group(1)))152 except:153 pass154 try:155 testcaseResult = re.search(yamlCont["testcaseResult"], line)156 if testcaseResult:157 testcaseInfo.setResult(testcaseResult.group(1).upper())158 except:159 pass160 161 try:162 scriptResult = re.search(yamlCont["scriptResult"], line)163 if scriptResult:164 testcaseInfo.setScriptResult(scriptResult.group(1).upper())165 except:166 pass167 168 line = line.strip('\r')169 line = line.replace("\"", "\\\"")170 timestamp = utils.get_timestamp()171 ## only if testcaseInfo is initialized, test logs can be added.172 if 'testcaseInfo' in globals():173 testcaseInfo.appendLog(msg=line, timestamp=timestamp)174 bufferLine = tempOut.split('\n')[-1]175 return output176def executeScript(inputScript, scriptOptionalArgs, inputFile=None):177 global testcaseInfoList178 global testcaseInfo179 global yamlCont180 testcaseInfoList = []181 yamlCont = {}182 if inputFile != None:183 fil = open(inputFile, "r")184 yamlCont = yaml.load(fil)185# inputFileType = re.search('(.*).yaml', inputFile).group(1)186 if re.search("\.log\.", inputScript):187 cmd = "python /work/swtest01_1/sgsubramaniam/sw-test/special_script/demoScript/slowcat.py -d 0.002 %s" %inputScript188 else:189 cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))190 if re.search("\.flist$", inputScript):191 inputFileType = 'flist'192 cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))193 elif re.search("\.f10$", inputScript):194 inputFileType = 'f10'195 cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))196 else:197 inputFileType = 'unknown'198 if inputFile != None:199 inputFileType = re.search('(.*).yaml', inputFile).group(1)200 cmd = "%s %s;echo '----------'" %(inputScript, ' '.join(scriptOptionalArgs))201 ps = winpexpect.winspawn(cmd)202 ps.logfile_read = sys.stdout203 ## Initialize testcaseInfo if the script is not a flist.204 if inputFileType in ['f10', 'unknown']:205 scriptName = inputScript206 testcaseInfo = testInfo(scriptName)207 testcaseInfoList.append(testcaseInfo)208 timeout = -1209 ps.interact(output_filter=scriptExecutionMonitor)210 if inputFileType is 'flist' or 'rspec':211 ## creates a nested suite212 suiteList = []213 for testcaseInfo in testcaseInfoList:214 testcaseInfo.flush()215 suite = createRobotSuite(testcaseInfo)216 suiteList.append(suite)217 suite = TestSuite(inputScript)218 suite.suites = suiteList219 result = suite.run(output='output.xml', loglevel='debug')220 for testcaseInfo in testcaseInfoList:221 testcaseInfo.variableFile.close()222 else:223 ## creates a single suite224 for testcaseInfo in testcaseInfoList:225 testcaseInfo.flush()226 print testcaseInfo227 suite = createRobotSuite(testcaseInfo)228 result = suite.run(output='output.xml', loglevel='debug')229 testcaseInfo.variableFile.close()230 # Generating log files requires processing the earlier generated output XML.231 ResultWriter('output.xml').write_results()232 pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)233 pp.close()234if __name__ == "__main__":235 if len(sys.argv) < 2:236 print 'usage : %s <inputScript> <script optional args>' %sys.argv[0]237 sys.exit()238 if re.search(".yaml", sys.argv[1]):239 inputFile = sys.argv[1]240 inputScript = sys.argv[2]241 scriptOptionalArgs = sys.argv[3:]242 executeScript(inputScript, scriptOptionalArgs, inputFile)243 else:244 inputScript = sys.argv[1]245 scriptOptionalArgs = sys.argv[2:]...

Full Screen

Full Screen

scriptLauncher.py

Source:scriptLauncher.py Github

copy

Full Screen

1import winpexpect2from robot.running import TestSuite3import subprocess4import sys5import re6import os7from robot import utils8from robot.reporting import ResultWriter9import dataStructure10import tempfile11import postProcess12import signal13import yaml14class testInfo(object):15 def __init__(self, scriptName):16 self.scriptName = scriptName17 self.tcInfo = dataStructure.nestedDict()18 self.currentTcid = 'suite_setup'19 self.variableFile = variableFile()20 self.scriptResult = 'FAIL'21 def appendLog(self, msg, timestamp, tcid=None):22 if tcid is None:23 tcid = self.currentTcid24 if 'msgList' not in self.tcInfo[tcid]:25 self.tcInfo[tcid]['msgList'] = []26 self.tcInfo[tcid]['timestamps'] = []27 self.variableFile.initTcInfo(tcid)28 self.tcInfo[tcid]['msgList'].append(msg)29 self.tcInfo[tcid]['timestamps'].append(timestamp)30 self.variableFile.appendLog(tcid, msg, timestamp)31 def setScriptResult(self, status):32 self.scriptResult = status33 def setResult(self, status, tcid=None):34 if tcid is None:35 tcid = self.currentTcid36 self.tcInfo[tcid]['result'] = status37 self.variableFile.setResult(tcid, status)38 def setTcid(self, id):39 self.currentTcid = id40 def setLogFile(self, fileName):41 self.logFileName = fileName42 def flush(self):43 self.variableFile.flush()44 45class variableFile(object):46 def __init__(self):47 #self.file = tempfile.NamedTemporaryFile(dir=None, delete=True, suffix='.py')48 self.file = open("tempFile.py", "w+")49 self.name = self.file.name50 print self.name51 self.file.write('# coding=utf-8\n')52 self.file.write('import dataStructure\n')53 self.file.write('testcaseInfo = dataStructure.nestedDict()\n')54 self.file.write('setupLog = dataStructure.nestedDict()\n')55 self.file.write('cleanupLog = dataStructure.nestedDict()\n')56 def initTcInfo(self, tcid):57 if tcid is 'suite_setup':58 self.file.write('setupLog["msgList"] = []\n')59 self.file.write('setupLog["timestamps"] = []\n')60 elif tcid is 'suite_cleanup':61 self.file.write('cleanupLog["msgList"] = []\n')62 self.file.write('cleanupLog["timestamps"] = []\n')63 else:64 self.file.write('testcaseInfo["%s"]["msgList"] = []\n' %tcid)65 self.file.write('testcaseInfo["%s"]["timestamps"] = []\n' %tcid)66 def appendLog(self, tcid, msg, timestamp):67 if tcid is 'suite_setup':68 self.file.write('setupLog["msgList"].append("%s")\n' %msg)69 self.file.write('setupLog["timestamps"].append("%s")\n' %timestamp)70 elif tcid is 'suite_cleanup':71 self.file.write('cleanupLog["msgList"].append("%s")\n' %msg)72 self.file.write('cleanupLog["timestamps"].append("%s")\n' %timestamp)73 else:74 self.file.write('testcaseInfo["%s"]["msgList"].append("%s")\n' %(tcid, msg))75 self.file.write('testcaseInfo["%s"]["timestamps"].append("%s")\n' %(tcid, timestamp))76 def setResult(self, tcid, status):77 if tcid is 'suite_setup':78 self.file.write('setupLog["result"] = "%s"\n' %status)79 elif tcid is 'suite_cleanup':80 self.file.write('cleanupLog["result"] = "%s"\n' %status)81 else:82 self.file.write('testcaseInfo["%s"]["result"] = "%s"\n' %(tcid, status))83 def flush(self):84 self.file.flush()85 def close(self):86 self.file.close()87 # This will remove the .pyc file created for the variable file88 if os.path.isfile(self.name+'c'):89 os.remove(self.name+'c')90def createRobotSuite(testcaseInfo):91 suite = TestSuite(os.path.basename(testcaseInfo.scriptName))92 suite.imports.library('logModule')93 suite.imports.variables(testcaseInfo.variableFile.name)94 tcList = [val for val in testcaseInfo.tcInfo.keys() if val not in ['suite_setup', 'suite_cleanup']]95 if tcList:96 ## This suite has f10 testcases defined97 ## suite_setup should precede suite_cleanup. Otherwise, both will be set as None.98 if 'suite_setup' in testcaseInfo.tcInfo.keys():99 suite.keywords.create('setup_log', args=['${setupLog}'], type='setup')100 if 'suite_cleanup' in testcaseInfo.tcInfo.keys():101 suite.keywords.create('cleanup_log', args=['${cleanupLog}'], type='teardown')102 else:103 ## This suite has no f10 testcases defined in the script. Entire script should be treated as one testcase104 if 'suite_cleanup' in testcaseInfo.tcInfo.keys():105 suite.keywords.create('cleanup_log', args=['${cleanupLog}'], type='teardown')106 test = suite.tests.create(testcaseInfo.scriptName, tags=None)107 test.keywords.create('testcase_log', args=['${setupLog}', 'result=%s' %testcaseInfo.scriptResult])108 109 for tcid in testcaseInfo.tcInfo.keys():110 if tcid in ['suite_setup', 'suite_cleanup']:111 pass112 else:113 test = suite.tests.create(tcid, tags=None)114 print testcaseInfo115 test.keywords.create('testcase_log', args=['${testcaseInfo}', 'tcid=%s' %tcid])116 return suite117def scriptExecutionMonitor(output):118 global testcaseInfo119 global testcaseInfoList120 global bufferLine121 global yamlCont122 123 if 'bufferLine' not in globals():124 bufferLine = ''125 tempOut = bufferLine + output126 for line in tempOut.split('\n')[0:-1]:127 try:128 scriptStart = re.search(yamlCont["scriptStart"], line)129 if scriptStart:130 scriptName = scriptStart.group(1)131 print132 testcaseInfo = testInfo(scriptName)133 testcaseInfoList.append(testcaseInfo)134 except:135 pass136 137 try:138 scriptCleanup = re.search(yamlCont["scriptCleanup"], line)139 if scriptCleanup:140 testcaseInfo.setTcid('suite_cleanup')141 except:142 pass143 144 try:145 scriptCleanup = re.search(yamlCont["scriptStartup"], line)146 if scriptCleanup:147 testcaseInfo.setTcid('suite_startup')148 except:149 pass150 151 try:152 testcaseStart = re.search(yamlCont["testcaseStart"], line)153 if testcaseStart:154 testcaseInfo.setTcid("%s" %(testcaseStart.group(1)))155 except:156 pass157 try:158 testcaseResult = re.search(yamlCont["testcaseResult"], line)159 if testcaseResult:160 testcaseInfo.setResult(testcaseResult.group(1).upper())161 except:162 pass163 164 try:165 scriptResult = re.search(yamlCont["scriptResult"], line)166 if scriptResult:167 testcaseInfo.setScriptResult(scriptResult.group(1).upper())168 except:169 pass170 171 line = line.strip('\r')172 line = line.replace("\"", "\\\"")173 timestamp = utils.get_timestamp()174 ## only if testcaseInfo is initialized, test logs can be added.175 if 'testcaseInfo' in globals():176 testcaseInfo.appendLog(msg=line, timestamp=timestamp)177 bufferLine = tempOut.split('\n')[-1]178 return output179def executeScript(inputScript, scriptOptionalArgs, inputFile=None):180 global testcaseInfoList181 global testcaseInfo182 global yamlCont183 testcaseInfoList = []184 yamlCont = {}185 if inputFile != None:186 fil = open(inputFile, "r")187 yamlCont = yaml.load(fil)188# inputFileType = re.search('(.*).yaml', inputFile).group(1)189 inputFileType = 'unknown'190 if inputFile != None:191 inputFileType = re.search('(.*).yaml', inputFile).group(1)192 cmd = "%s %s" %(inputScript, ' '.join(scriptOptionalArgs))193 #inputFileType = 'unknown'194 print "@@@@@@@@@@@@@@@"195 print cmd196 print "@@@@@@@@@@@@@@@"197 ps = winpexpect.winspawn(cmd)198 ps.logfile_read = sys.stdout199 ## Initialize testcaseInfo if the script is not a flist.200 if inputFileType in ['unknown']:201 scriptName = inputScript202 testcaseInfo = testInfo(scriptName)203 testcaseInfoList.append(testcaseInfo)204 timeout = -1205 ps.interact(output_filter=scriptExecutionMonitor)206 if inputFileType is 'unknown':207 ## creates a nested suite208 suiteList = []209 for testcaseInfo in testcaseInfoList:210 testcaseInfo.flush()211 suite = createRobotSuite(testcaseInfo)212 suiteList.append(suite)213 suite = TestSuite(inputScript)214 suite.suites = suiteList215 result = suite.run(output='output.xml', loglevel='debug')216 for testcaseInfo in testcaseInfoList:217 testcaseInfo.variableFile.close()218 else:219 ## creates a single suite220 for testcaseInfo in testcaseInfoList:221 testcaseInfo.flush()222 print testcaseInfo223 suite = createRobotSuite(testcaseInfo)224 result = suite.run(output='output.xml', loglevel='debug')225 testcaseInfo.variableFile.close()226 # Generating log files requires processing the earlier generated output XML.227 ResultWriter('output.xml').write_results()228 pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)229 pp.close()230if __name__ == "__main__":231 if len(sys.argv) < 2:232 print 'usage : %s <inputScript> <script optional args>' %sys.argv[0]233 sys.exit()234 if re.search(".yaml", sys.argv[1]):235 inputFile = sys.argv[1]236 inputScript = sys.argv[2]237 scriptOptionalArgs = sys.argv[3:]238 print scriptOptionalArgs239 executeScript(inputScript, scriptOptionalArgs, inputFile)240 else:241 inputScript = sys.argv[1]242 scriptOptionalArgs = sys.argv[2:]...

Full Screen

Full Screen

tokens.py

Source:tokens.py Github

copy

Full Screen

1# Copyright 2008-2015 Nokia Networks2# Copyright 2016- Robot Framework Foundation3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15from robot.utils import py2to316from robot.variables import VariableIterator17@py2to318class Token(object):19 """Token representing piece of Robot Framework data.20 Each token has type, value, line number, column offset and end column21 offset in :attr:`type`, :attr:`value`, :attr:`lineno`, :attr:`col_offset`22 and :attr:`end_col_offset` attributes, respectively. Tokens representing23 error also have their error message in :attr:`error` attribute.24 Token types are declared as class attributes.25 """26 SETTING_HEADER = 'SETTING_HEADER'27 VARIABLE_HEADER = 'VARIABLE_HEADER'28 TESTCASE_HEADER = 'TESTCASE_HEADER'29 KEYWORD_HEADER = 'KEYWORD_HEADER'30 COMMENT_HEADER = 'COMMENT_HEADER'31 TESTCASE_NAME = 'TESTCASE_NAME'32 KEYWORD_NAME = 'KEYWORD_NAME'33 DOCUMENTATION = 'DOCUMENTATION'34 SUITE_SETUP = 'SUITE_SETUP'35 SUITE_TEARDOWN = 'SUITE_TEARDOWN'36 METADATA = 'METADATA'37 TEST_SETUP = 'TEST_SETUP'38 TEST_TEARDOWN = 'TEST_TEARDOWN'39 TEST_TEMPLATE = 'TEST_TEMPLATE'40 TEST_TIMEOUT = 'TEST_TIMEOUT'41 FORCE_TAGS = 'FORCE_TAGS'42 DEFAULT_TAGS = 'DEFAULT_TAGS'43 LIBRARY = 'LIBRARY'44 RESOURCE = 'RESOURCE'45 VARIABLES = 'VARIABLES'46 SETUP = 'SETUP'47 TEARDOWN = 'TEARDOWN'48 TEMPLATE = 'TEMPLATE'49 TIMEOUT = 'TIMEOUT'50 TAGS = 'TAGS'51 ARGUMENTS = 'ARGUMENTS'52 RETURN = 'RETURN'53 NAME = 'NAME'54 VARIABLE = 'VARIABLE'55 ARGUMENT = 'ARGUMENT'56 ASSIGN = 'ASSIGN'57 KEYWORD = 'KEYWORD'58 WITH_NAME = 'WITH_NAME'59 FOR = 'FOR'60 FOR_SEPARATOR = 'FOR_SEPARATOR'61 OLD_FOR_INDENT = 'OLD_FOR_INDENT'62 END = 'END'63 SEPARATOR = 'SEPARATOR'64 COMMENT = 'COMMENT'65 CONTINUATION = 'CONTINUATION'66 EOL = 'EOL'67 EOS = 'EOS'68 ERROR = 'ERROR'69 FATAL_ERROR = 'FATAL_ERROR'70 NON_DATA_TOKENS = (71 SEPARATOR,72 COMMENT,73 CONTINUATION,74 EOL,75 EOS76 )77 SETTING_TOKENS = (78 DOCUMENTATION,79 SUITE_SETUP,80 SUITE_TEARDOWN,81 METADATA,82 TEST_SETUP,83 TEST_TEARDOWN,84 TEST_TEMPLATE,85 TEST_TIMEOUT,86 FORCE_TAGS,87 DEFAULT_TAGS,88 LIBRARY,89 RESOURCE,90 VARIABLES,91 SETUP,92 TEARDOWN,93 TEMPLATE,94 TIMEOUT,95 TAGS,96 ARGUMENTS,97 RETURN98 )99 HEADER_TOKENS = (100 SETTING_HEADER,101 VARIABLE_HEADER,102 TESTCASE_HEADER,103 KEYWORD_HEADER,104 COMMENT_HEADER105 )106 ALLOW_VARIABLES = (107 NAME,108 ARGUMENT,109 TESTCASE_NAME,110 KEYWORD_NAME111 )112 __slots__ = ['type', 'value', 'lineno', 'col_offset', 'error']113 def __init__(self, type=None, value='', lineno=-1, col_offset=-1, error=None):114 self.type = type115 self.value = value116 self.lineno = lineno117 self.col_offset = col_offset118 self.error = error119 @property120 def end_col_offset(self):121 if self.col_offset == -1:122 return -1123 return self.col_offset + len(self.value)124 def set_error(self, error, fatal=False):125 self.type = Token.ERROR if not fatal else Token.FATAL_ERROR126 self.error = error127 def tokenize_variables(self):128 """Tokenizes possible variables in token value.129 Yields the token itself if the token does not allow variables (see130 :attr:`Token.ALLOW_VARIABLES`) or its value does not contain131 variables. Otherwise yields variable tokens as well as tokens132 before, after, or between variables so that they have the same133 type as the original token.134 """135 if self.type not in Token.ALLOW_VARIABLES:136 return self._tokenize_no_variables()137 variables = VariableIterator(self.value)138 if not variables:139 return self._tokenize_no_variables()140 return self._tokenize_variables(variables)141 def _tokenize_no_variables(self):142 yield self143 def _tokenize_variables(self, variables):144 lineno = self.lineno145 col_offset = self.col_offset146 remaining = ''147 for before, variable, remaining in variables:148 if before:149 yield Token(self.type, before, lineno, col_offset)150 col_offset += len(before)151 yield Token(Token.VARIABLE, variable, lineno, col_offset)152 col_offset += len(variable)153 if remaining:154 yield Token(self.type, remaining, lineno, col_offset)155 def __unicode__(self):156 return self.value157 def __repr__(self):158 error = '' if not self.error else ', %r' % self.error159 return 'Token(%s, %r, %s, %s%s)' % (self.type, self.value,160 self.lineno, self.col_offset,161 error)162 def __eq__(self, other):163 if not isinstance(other, Token):164 return False165 return (self.type == other.type and166 self.value == other.value and167 self.lineno == other.lineno and168 self.col_offset == other.col_offset and169 self.error == other.error)170 def __ne__(self, other):171 return not self == other172class EOS(Token):173 """Token representing end of statement."""174 __slots__ = []175 def __init__(self, lineno=-1, col_offset=-1):176 Token.__init__(self, Token.EOS, '', lineno, col_offset)177 @classmethod178 def from_token(cls, token):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful