How to use printErrors method in green

Best Python code snippet using green

fbchisellldbbase.py

Source:fbchisellldbbase.py Github

copy

Full Screen

1#!/usr/bin/python2# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved3#4# This source code is licensed under the MIT license found in the5# LICENSE file in the root directory of this source tree.6import json7import shlex8import lldb9class FBCommandArgument: # noqa B90310 def __init__(11 self, short="", long="", arg="", type="", help="", default="", boolean=False12 ):13 self.shortName = short14 self.longName = long15 self.argName = arg16 self.argType = type17 self.help = help18 self.default = default19 self.boolean = boolean20class FBCommand:21 def name(self):22 return None23 def options(self):24 return []25 def args(self):26 return []27 def description(self):28 return ""29 def lex(self, commandLine):30 return shlex.split(commandLine)31 def run(self, arguments, option):32 pass33def isSuccess(error):34 # When evaluating a `void` expression, the returned value will indicate an35 # error. This error is named: kNoResult. This error value does *not* mean36 # there was a problem. This logic follows what the builtin `expression`37 # command does. See: https://git.io/vwpjl (UserExpression.h)38 kNoResult = 0x100139 return error.success or error.value == kNoResult40def importModule(frame, module):41 options = lldb.SBExpressionOptions()42 options.SetLanguage(lldb.eLanguageTypeObjC)43 value = frame.EvaluateExpression("@import " + module, options)44 return isSuccess(value.error)45# evaluates expression in Objective-C++ context, so it will work even for46# Swift projects47def evaluateExpressionValue(48 expression,49 printErrors=True,50 language=lldb.eLanguageTypeObjC_plus_plus,51 tryAllThreads=False,52):53 frame = (54 lldb.debugger.GetSelectedTarget()55 .GetProcess()56 .GetSelectedThread()57 .GetSelectedFrame()58 )59 options = lldb.SBExpressionOptions()60 options.SetLanguage(language)61 # Allow evaluation that contains a @throw/@catch.62 # By default, ObjC @throw will cause evaluation to be aborted. At the time63 # of a @throw, it's not known if the exception will be handled by a @catch.64 # An exception that's caught, should not cause evaluation to fail.65 options.SetTrapExceptions(False)66 # Give evaluation more time.67 options.SetTimeoutInMicroSeconds(5000000) # 5s68 # Most Chisel commands are not multithreaded.69 options.SetTryAllThreads(tryAllThreads)70 value = frame.EvaluateExpression(expression, options)71 error = value.GetError()72 # Retry if the error could be resolved by first importing UIKit.73 if (74 error.type == lldb.eErrorTypeExpression75 and error.value == lldb.eExpressionParseError76 and importModule(frame, "UIKit")77 ):78 value = frame.EvaluateExpression(expression, options)79 error = value.GetError()80 if printErrors and not isSuccess(error):81 print(error)82 return value83def evaluateInputExpression(expression, printErrors=True):84 # HACK85 if expression.startswith("(id)"):86 return evaluateExpressionValue(expression, printErrors=printErrors).GetValue()87 frame = (88 lldb.debugger.GetSelectedTarget()89 .GetProcess()90 .GetSelectedThread()91 .GetSelectedFrame()92 )93 options = lldb.SBExpressionOptions()94 options.SetTrapExceptions(False)95 value = frame.EvaluateExpression(expression, options)96 error = value.GetError()97 if printErrors and error.Fail():98 print(error)99 return value.GetValue()100def evaluateIntegerExpression(expression, printErrors=True):101 output = evaluateExpression("(int)(" + expression + ")", printErrors).replace(102 "'", ""103 )104 if output.startswith("\\x"): # Booleans may display as \x01 (Hex)105 output = output[2:]106 elif output.startswith("\\"): # Or as \0 (Dec)107 output = output[1:]108 return int(output, 0)109def evaluateBooleanExpression(expression, printErrors=True):110 return (111 int(evaluateIntegerExpression("(BOOL)(" + expression + ")", printErrors)) != 0112 )113def evaluateExpression(expression, printErrors=True):114 return evaluateExpressionValue(expression, printErrors=printErrors).GetValue()115def describeObject(expression, printErrors=True):116 return evaluateExpressionValue(117 "(id)(" + expression + ")", printErrors118 ).GetObjectDescription()119def evaluateEffect(expression, printErrors=True):120 evaluateExpressionValue("(void)(" + expression + ")", printErrors=printErrors)121def evaluateObjectExpression(expression, printErrors=True):122 return evaluateExpression("(id)(" + expression + ")", printErrors)123def evaluateCStringExpression(expression, printErrors=True):124 ret = evaluateExpression(expression, printErrors)125 process = lldb.debugger.GetSelectedTarget().GetProcess()126 error = lldb.SBError()127 ret = process.ReadCStringFromMemory(int(ret, 16), 256, error)128 if error.Success():129 return ret130 else:131 if printErrors:132 print(error)133 return None134RETURN_MACRO = """135#define IS_JSON_OBJ(obj)\136 (obj != nil && ((bool)[NSJSONSerialization isValidJSONObject:obj] ||\137 (bool)[obj isKindOfClass:[NSString class]] ||\138 (bool)[obj isKindOfClass:[NSNumber class]]))139#define RETURN(ret) ({\140 if (!IS_JSON_OBJ(ret)) {\141 (void)[NSException raise:@"Invalid RETURN argument" format:@""];\142 }\143 NSDictionary *__dict = @{@"return":ret};\144 NSData *__data = (id)[NSJSONSerialization dataWithJSONObject:__dict options:0 error:NULL];\145 NSString *__str = (id)[[NSString alloc] initWithData:__data encoding:4];\146 (char *)[__str UTF8String];})147#define RETURNCString(ret)\148 ({NSString *___cstring_ret = [NSString stringWithUTF8String:ret];\149 RETURN(___cstring_ret);})150"""151def check_expr(expr):152 return expr.strip().split(";")[-2].find("RETURN") != -1153# evaluate a batch of Objective-C expressions, the last expression154# must contain a RETURN marco and it will automatic transform the155# Objective-C object to Python object156# Example:157# >>> fbchisellldbbase.evaluate('NSString *str = @"hello world"; RETURN(@{@"key": str});')158# {u'key': u'hello world'}159def evaluate(expr):160 if not check_expr(expr):161 raise Exception(162 "Invalid Expression, the last expression not include a RETURN family marco"163 )164 command = "({" + RETURN_MACRO + "\n" + expr + "})"165 ret = evaluateExpressionValue(command, printErrors=True)166 if not ret.GetError().Success():167 print(ret.GetError())168 return None169 else:170 process = lldb.debugger.GetSelectedTarget().GetProcess()171 error = lldb.SBError()172 ret = process.ReadCStringFromMemory(int(ret.GetValue(), 16), 2**20, error)173 if not error.Success():174 print(error)175 return None176 else:177 ret = json.loads(ret)178 return ret["return"]179def currentLanguage():180 return (181 lldb.debugger.GetSelectedTarget()182 .GetProcess()183 .GetSelectedThread()184 .GetSelectedFrame()185 .GetCompileUnit()186 .GetLanguage()...

Full Screen

Full Screen

lldbbase.py

Source:lldbbase.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3################################################################################4#5# Copyright (c) 2016 Baidu.com, Inc. All Rights Reserved6#7################################################################################8"""9This module provide configure file management service in i18n environment.10Authors: liyingpeng(liyingpeng@baidu.com)11Date: 2016/01/20 17:23:0612"""13import lldb14class CommandArgument:15 def __init__(self, short='', long='', arg='', type='', help='', default='', boolean=False):16 self.shortName = short17 self.longName = long18 self.argName = arg19 self.argType = type20 self.help = help21 self.default = default22 self.boolean = boolean23class Command:24 def name(self):25 return None26 def options(self):27 return []28 def args(self):29 return []30 def description(self):31 return ''32 def run(self, arguments, option):33 pass34def evaluateExpressionValueWithLanguage(expression, language, printErrors):35 # lldb.frame is supposed to contain the right frame, but it doesnt :/ so36 # do the dance37 frame = lldb.debugger.GetSelectedTarget().GetProcess(38 ).GetSelectedThread().GetSelectedFrame()39 expr_options = lldb.SBExpressionOptions()40 # requires lldb r210874 (2014-06-13) / Xcode 641 expr_options.SetLanguage(language)42 value = frame.EvaluateExpression(expression, expr_options)43 if printErrors and value.GetError() is not None and str(value.GetError()) != 'success':44 print value.GetError()45 return value46def evaluateExpressionValueInFrameLanguage(expression, printErrors=True):47 # lldb.frame is supposed to contain the right frame, but it doesnt :/ so48 # do the dance49 frame = lldb.debugger.GetSelectedTarget().GetProcess(50 ).GetSelectedThread().GetSelectedFrame()51 # requires lldb r222189 (2014-11-17)52 language = frame.GetCompileUnit().GetLanguage()53 return evaluateExpressionValueWithLanguage(expression, language, printErrors)54# evaluates expression in Objective-C++ context, so it will work even for55# Swift projects56def evaluateExpressionValue(expression, printErrors=True):57 return evaluateExpressionValueWithLanguage(expression, lldb.eLanguageTypeObjC_plus_plus, printErrors)58def evaluateIntegerExpression(expression, printErrors=True):59 output = evaluateExpression(60 '(int)(' + expression + ')', printErrors).replace('\'', '')61 if output.startswith('\\x'): # Booleans may display as \x01 (Hex)62 output = output[2:]63 elif output.startswith('\\'): # Or as \0 (Dec)64 output = output[1:]65 return int(output, 16)66def evaluateBooleanExpression(expression, printErrors=True):67 return (int(evaluateIntegerExpression('(BOOL)(' + expression + ')', printErrors)) != 0)68def evaluateExpression(expression, printErrors=True):69 return evaluateExpressionValue(expression, printErrors).GetValue()70def evaluateObjectExpression(expression, printErrors=True):...

Full Screen

Full Screen

fblldbbase.py

Source:fblldbbase.py Github

copy

Full Screen

1#!/usr/bin/python2# Copyright (c) 2014, Facebook, Inc.3# All rights reserved.4#5# This source code is licensed under the BSD-style license found in the6# LICENSE file in the root directory of this source tree. An additional grant7# of patent rights can be found in the PATENTS file in the same directory.8import lldb9class FBCommandArgument:10 def __init__(self, short='', long='', arg='', type='', help='', default='', boolean=False):11 self.shortName = short12 self.longName = long13 self.argName = arg14 self.argType = type15 self.help = help16 self.default = default17 self.boolean = boolean18class FBCommand:19 def name(self):20 return None21 def options(self):22 return []23 def args(self):24 return []25 def description(self):26 return ''27 def run(self, arguments, option):28 pass29def evaluateExpressionValue(expression, printErrors = True):30 # lldb.frame is supposed to contain the right frame, but it doesnt :/ so do the dance31 frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame()32 value = frame.EvaluateExpression(expression)33 if printErrors and value.GetError() is not None and str(value.GetError()) != 'success':34 print value.GetError()35 return value36def evaluateIntegerExpression(expression, printErrors = True):37 output = evaluateExpression('(int)(' + expression + ')', printErrors).replace('\'', '')38 if output.startswith('\\x'): # Booleans may display as \x01 (Hex)39 output = output[2:]40 elif output.startswith('\\'): # Or as \0 (Dec)41 output = output[1:]42 return int(output, 16)43def evaluateBooleanExpression(expression, printErrors = True):44 return (int(evaluateIntegerExpression('(BOOL)(' + expression + ')', printErrors)) != 0)45def evaluateExpression(expression, printErrors = True):46 return evaluateExpressionValue(expression, printErrors).GetValue()47def evaluateObjectExpression(expression, printErrors = True):...

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 green 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