Best Python code snippet using tempest_python
find_error.py
Source:find_error.py
...97 text = open(fn, 'U').read()98 text = text.strip('\n') + '\n'99 tokens = []100 states = []101 def show_token(tok, state):102 reprs = map(repr, tok)103 print(' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0], end=' ')104 if debug_lexer:105 print(' ' + ' ' * (29-len(reprs[0])) + repr(state), end=' ')106 print()107 for type, val in lx.get_tokens(text):108 lno += val.count('\n')109 if type == Error:110 print('Error parsing', fn, 'on line', lno)111 print('Previous tokens' + (debug_lexer and ' and states' or '') + ':')112 if showall:113 for tok, state in map(None, tokens, states):114 show_token(tok, state)115 else:116 for i in range(max(len(tokens) - num, 0), len(tokens)):117 show_token(tokens[i], states[i])118 print('Error token:')119 l = len(repr(val))120 print(' ' + repr(val), end=' ')121 if debug_lexer and hasattr(lx, 'statestack'):122 print(' ' * (60-l) + repr(lx.statestack), end=' ')123 print()124 print()125 return 1126 tokens.append((type, val))127 if debug_lexer:128 if hasattr(lx, 'statestack'):129 states.append(lx.statestack[:])130 else:131 states.append(None)132 if showall:133 for tok, state in map(None, tokens, states):134 show_token(tok, state)135 return 0136num = 10137showall = False138lexer = None139options = {}140if __name__ == '__main__':141 import getopt142 opts, args = getopt.getopt(sys.argv[1:], 'n:l:aO:')143 for opt, val in opts:144 if opt == '-n':145 num = int(val)146 elif opt == '-a':147 showall = True148 elif opt == '-l':...
keep-test.py
Source:keep-test.py
1import sys2import gkeepapi3import getpass4TECH_ERR = " Technical Error Message: "5class KeepLoginException(Exception):6 def __init__(self, msg):7 self.msg = msg8 def __str__(self):9 return self.msg10def keep_init():11 keepapi = gkeepapi.Keep()12 return keepapi13def keep_login(keepapi, userid, pw):14 keepapi.login(userid, pw)15 keep_token = keepapi.getMasterToken()16 return keep_token17def ui_login(keepapi, show_token):18 try:19 userid = input('\r\nEnter your Google account username: ')20 21 pw = getpass.getpass(prompt='Enter your Google Password: ', stream=None) 22 ktoken = keep_login(keepapi, userid, pw)23 if ktoken:24 if show_token:25 print (ktoken)26 print ("Test worked!! You've succesfully logged into Google Keep! Please try running Keep-it-Markdown or KIM!")27 else:28 raise Exception29 #print ("Invalid Google userid or pw! Please try again.")30 return (ktoken)31 except Exception as e:32 raise KeepLoginException("Login attempt failed\r\n" + TECH_ERR + repr(e))33def main(argv):34 try:35 show_token = False36 if len(argv) > 1:37 if argv[1] == "-t":38 show_token = True39 kapi = keep_init()40 ui_login(kapi, show_token)41 except Exception as e:42 print (e)43 print ("Please start your browswer and copy-paste this URL in the address bar: https://accounts.google.com/DisplayUnlockCaptcha - then, try logging in again.")44 45if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!