How to use __write method in avocado

Best Python code snippet using avocado_python

dump.py

Source:dump.py Github

copy

Full Screen

...28 """29 def __init__(self):30 self.__outputFile = None31 self.__outputFP = None32 def __write(self, data, n=True, rFile=False):33 if n:34 print data35 self.__outputFP.write("%s\n" % data)36 # TODO: do not duplicate queries output in the text file, check37 # before if the data is already within the text file content38 if rFile and conf.rFile:39 rFile = filePathToString(conf.rFile)40 rFileFP = open("%s%s%s" % (conf.filePath, os.sep, rFile), "w")41 rFileFP.write(data)42 rFileFP.close()43 else:44 print data,45 self.__outputFP.write("%s " % data)46 self.__outputFP.flush()47 conf.loggedToOut = True48 def setOutputFile(self):49 self.__outputFile = "%s%slog" % (conf.outputPath, os.sep)50 self.__outputFP = open(self.__outputFile, "a")51 def string(self, header, data):52 if isinstance(data, (list, tuple, set)):53 self.lister(header, data)54 return55 if data:56 data = data.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")57 data = data.replace("__START__", "").replace("__STOP__", "")58 data = data.replace("__DEL__", ", ")59 if "\n" in data:60 self.__write("%s:\n---\n%s---\n" % (header, data), rFile=header)61 else:62 self.__write("%s: '%s'\n" % (header, data))63 else:64 self.__write("%s:\tNone\n" % header)65 def lister(self, header, elements):66 if elements:67 self.__write("%s [%d]:" % (header, len(elements)))68 try:69 elements = set(elements)70 elements = list(elements)71 elements.sort(key=lambda x: x.lower())72 except:73 pass74 for element in elements:75 if isinstance(element, str):76 self.__write("[*] %s" % element)77 elif isinstance(element, (list, tuple, set)):78 self.__write("[*] " + ", ".join(e for e in element))79 if elements:80 self.__write("")81 def userSettings(self, header, userSettings, subHeader):82 self.__areAdmins = set()83 if userSettings:84 self.__write("%s:" % header)85 if isinstance(userSettings, (tuple, list, set)):86 self.__areAdmins = userSettings[1]87 userSettings = userSettings[0]88 users = userSettings.keys()89 users.sort(key=lambda x: x.lower())90 for user in users:91 settings = userSettings[user]92 if user in self.__areAdmins:93 self.__write("[*] %s (administrator) [%d]:" % (user, len(settings)))94 else:95 self.__write("[*] %s [%d]:" % (user, len(settings)))96 settings.sort()97 for setting in settings:98 self.__write(" %s: %s" % (subHeader, setting))99 print100 def dbTables(self, dbTables):101 maxlength = 0102 for tables in dbTables.values():103 for table in tables:104 maxlength = max(maxlength, len(table))105 lines = "-" * (int(maxlength) + 2)106 for db, tables in dbTables.items():107 tables.sort(key=lambda x: x.lower())108 self.__write("Database: %s" % db)109 if len(tables) == 1:110 self.__write("[1 table]")111 else:112 self.__write("[%d tables]" % len(tables))113 self.__write("+%s+" % lines)114 for table in tables:115 blank = " " * (maxlength - len(table))116 self.__write("| %s%s |" % (table, blank))117 self.__write("+%s+\n" % lines)118 def dbTableColumns(self, tableColumns):119 for db, tables in tableColumns.items():120 if not db:121 db = "All"122 for table, columns in tables.items():123 maxlength1 = 0124 maxlength2 = 0125 colList = columns.keys()126 colList.sort(key=lambda x: x.lower())127 for column in colList:128 colType = columns[column]129 maxlength1 = max(maxlength1, len(column))130 maxlength2 = max(maxlength2, len(colType))131 maxlength1 = max(maxlength1, len("COLUMN"))132 maxlength2 = max(maxlength2, len("TYPE"))133 lines1 = "-" * (int(maxlength1) + 2)134 lines2 = "-" * (int(maxlength2) + 2)135 self.__write("Database: %s\nTable: %s" % (db, table))136 if len(columns) == 1:137 self.__write("[1 column]")138 else:139 self.__write("[%d columns]" % len(columns))140 self.__write("+%s+%s+" % (lines1, lines2))141 blank1 = " " * (maxlength1 - len("COLUMN"))142 blank2 = " " * (maxlength2 - len("TYPE"))143 self.__write("| Column%s | Type%s |" % (blank1, blank2))144 self.__write("+%s+%s+" % (lines1, lines2))145 for column in colList:146 colType = columns[column]147 blank1 = " " * (maxlength1 - len(column))148 blank2 = " " * (maxlength2 - len(colType))149 self.__write("| %s%s | %s%s |" % (column, blank1, colType, blank2))150 self.__write("+%s+%s+\n" % (lines1, lines2))151 def dbTableValues(self, tableValues):152 db = tableValues["__infos__"]["db"]153 if not db:154 db = "All"155 table = tableValues["__infos__"]["table"]156 if not conf.multipleTargets:157 dumpDbPath = "%s%s%s" % (conf.dumpPath, os.sep, db)158 if not os.path.isdir(dumpDbPath):159 os.makedirs(dumpDbPath, 0755)160 dumpFileName = "%s%s%s.csv" % (dumpDbPath, os.sep, table)161 dumpFP = open(dumpFileName, "w")162 count = int(tableValues["__infos__"]["count"])163 separator = ""164 field = 1165 fields = len(tableValues) - 1166 columns = tableValues.keys()167 columns.sort(key=lambda x: x.lower())168 for column in columns:169 if column != "__infos__":170 info = tableValues[column]171 lines = "-" * (int(info["length"]) + 2)172 separator += "+%s" % lines173 separator += "+"174 self.__write("Database: %s\nTable: %s" % (db, table))175 if count == 1:176 self.__write("[1 entry]")177 else:178 self.__write("[%d entries]" % count)179 self.__write(separator)180 for column in columns:181 if column != "__infos__":182 info = tableValues[column]183 maxlength = int(info["length"])184 blank = " " * (maxlength - len(column))185 self.__write("| %s%s" % (column, blank), n=False)186 if not conf.multipleTargets and field == fields:187 dataToDumpFile(dumpFP, "\"%s\"" % column)188 else:189 dataToDumpFile(dumpFP, "\"%s\"," % column)190 field += 1191 self.__write("|\n%s" % separator)192 if not conf.multipleTargets:193 dataToDumpFile(dumpFP, "\n")194 for i in range(count):195 field = 1196 for column in columns:197 if column != "__infos__":198 info = tableValues[column]199 value = info["values"][i]200 if re.search("^[\ *]*$", value):201 value = "NULL"202 maxlength = int(info["length"])203 blank = " " * (maxlength - len(value))204 self.__write("| %s%s" % (value, blank), n=False)205 if field == fields:206 dataToDumpFile(dumpFP, "\"%s\"" % value)207 else:208 dataToDumpFile(dumpFP, "\"%s\"," % value)209 field += 1210 self.__write("|")211 if not conf.multipleTargets:212 dataToDumpFile(dumpFP, "\n")213 self.__write("%s\n" % separator)214 if not conf.multipleTargets:215 dataToDumpFile(dumpFP, "\n")216 dumpFP.close()217 logger.info("Table '%s.%s' dumped to CSV file '%s'" % (db, table, dumpFileName))218# object to manage how to print the retrieved queries output to219# standard output and sessions file...

Full Screen

Full Screen

mypl_print_visitor.py

Source:mypl_print_visitor.py Github

copy

Full Screen

...11 def __indent(self):12 """Get default indent of four spaces"""13 return ' ' * self.indent14 15 def __write(self, msg):16 self.output_stream.write(msg)17 18 def visit_stmt_list(self, stmt_list):19 for stmt in stmt_list.stmts:20 stmt.accept(self)21 22 def visit_expr_stmt(self, expr_stmt):23 self.__write(self.__indent())24 expr_stmt.expr.accept(self)25 self.__write(';\n')26 def visit_var_decl_stmt(self, var_decl_stmt):27 self.__write(self.__indent())28 self.__write('var ' + var_decl_stmt.var_id.lexeme)29 if var_decl_stmt.var_type is not None:30 self.__write(': ' + var_decl_stmt.var_type.lexeme)31 self.__write(' = ')32 var_decl_stmt.var_expr.accept(self)33 self.__write(';\n')34 def visit_assign_stmt(self, assign_stmt):35 self.__write(self.__indent())36 self.__write('set ')37 assign_stmt.lhs.accept(self)38 self.__write(' = ')39 assign_stmt.rhs.accept(self)40 self.__write(';\n')41 def visit_lvalue(self, lvalue):42 pathLength = len(lvalue.path)43 if pathLength == 1:44 self.__write(lvalue.path[0].lexeme)45 else:46 self.__write(lvalue.path[0].lexeme)47 for token in lvalue.path[1:]:48 self.__write('.')49 self.__write(token.lexeme)50 51 def visit_struct_decl_stmt(self, struct_decl_stmt):52 self.__write('\nstruct ' + struct_decl_stmt.struct_id.lexeme + '\n')53 self.indent += 454 for stmt in struct_decl_stmt.var_decls:55 stmt.accept(self)56 self.indent -= 457 self.__write('end\n\n')58 59 def visit_fun_decl_stmt(self, fun_decl_stmt):60 self.__write('\nfun ')61 if fun_decl_stmt.return_type is not None:62 self.__write(fun_decl_stmt.return_type.lexeme + ' ')63 self.__write(fun_decl_stmt.fun_name.lexeme +'(')64 numParams = len(fun_decl_stmt.params)65 if numParams >= 1:66 fun_decl_stmt.params[0].accept(self)67 if numParams > 1:68 for stmt in fun_decl_stmt.params[1:]:69 self.__write(', ')70 stmt.accept(self)71 self.__write(')\n')72 self.indent += 473 fun_decl_stmt.stmt_list.accept(self)74 self.indent -= 475 self.__write('end\n\n')76 def visit_fun_param(self, fun_param):77 self.__write(fun_param.param_name.lexeme + ': ')78 self.__write(fun_param.param_type.lexeme)79 def visit_return_stmt(self, return_stmt):80 self.__write(self.__indent())81 self.__write('return')82 if return_stmt.return_expr is not None:83 self.__write(' ')84 return_stmt.return_expr.accept(self)85 self.__write(';\n')86 def visit_while_stmt(self, while_stmt):87 self.__write(self.__indent())88 self.__write('while ')89 while_stmt.bool_expr.accept(self)90 self.__write(' do\n')91 self.indent += 492 while_stmt.stmt_list.accept(self)93 self.indent -= 494 self.__write(self.__indent())95 self.__write('end\n')96 def visit_if_stmt(self, if_stmt):97 self.__write(self.__indent())98 self.__write('if ')99 if_stmt.if_part.bool_expr.accept(self)100 self.__write(' then\n')101 self.indent += 4102 if_stmt.if_part.stmt_list.accept(self)103 self.indent -= 4104 for basicIf in if_stmt.elseifs:105 self.__write(self.__indent())106 self.__write('elif ')107 basicIf.bool_expr.accept(self)108 self.__write(' then\n')109 self.indent += 4110 basicIf.stmt_list.accept(self)111 self.indent -= 4112 if if_stmt.has_else:113 self.__write(self.__indent())114 self.__write('else\n')115 self.indent += 4116 if_stmt.else_stmts.accept(self)117 self.indent -= 4118 self.__write(self.__indent())119 self.__write('end\n')120 def visit_simple_expr(self, simple_expr):121 simple_expr.term.accept(self)122 def visit_simple_rvalue(self, simple_rvalue):123 if simple_rvalue.val.tokentype == token.STRINGVAL:124 self.__write('"' + simple_rvalue.val.lexeme + '"')125 else:126 self.__write(simple_rvalue.val.lexeme)127 def visit_new_rvalue(self, new_rvalue):128 self.__write(new_rvalue.struct_type.lexeme)129 def visit_call_rvalue(self, call_rvalue):130 self.__write(call_rvalue.fun.lexeme + '(')131 numParams = len(call_rvalue.args)132 if numParams >= 1:133 call_rvalue.args[0].accept(self)134 if numParams > 1:135 for param in call_rvalue.args[1:]:136 self.__write(', ')137 param.accept(self)138 self.__write(')')139 def visit_id_rvalue(self, id_rvalue):140 path = id_rvalue.path141 numInPath = len(path)142 self.__write(path[0].lexeme)143 if numInPath > 1:144 for ID in path[1:]:145 self.__write('.' + ID.lexeme)146 def visit_complex_expr(self, complex_expr):147 self.__write('(')148 complex_expr.first_operand.accept(self)149 self.__write(' ' + complex_expr.math_rel.lexeme + ' ')150 complex_expr.rest.accept(self)151 self.__write(')')152 def visit_bool_expr(self, bool_expr):153 if bool_expr.rest is not None:154 self.__write('(')155 if bool_expr.negated:156 self.__write("not ")157 if bool_expr.second_expr is not None:158 self.__write('(')159 bool_expr.first_expr.accept(self)160 self.__write(" " + bool_expr.bool_rel.lexeme + " ")161 bool_expr.second_expr.accept(self)162 self.__write(')')163 else:164 bool_expr.first_expr.accept(self)165 if bool_expr.rest is not None:166 self.__write(" " + bool_expr.bool_connector.lexeme + " ")167 bool_expr.rest.accept(self)...

Full Screen

Full Screen

sample.py

Source:sample.py Github

copy

Full Screen

...19 '''20 21 def __init__(self):22 pass23 def __write(self, field, text = ""):24 print("%-15s - %s" % (field, text))25 def on_init(self):26 self.__write("on_init")27 28 def on_send(self, command, gline):29 self.__write("on_send", command)30 31 def on_recv(self, line):32 self.__write("on_recv", line.strip())33 34 def on_connect(self):35 self.__write("on_connect")36 37 def on_disconnect(self):38 self.__write("on_disconnect")39 40 def on_error(self, error):41 self.__write("on_error", error)42 43 def on_online(self):44 self.__write("on_online")45 46 def on_temp(self, line):47 self.__write("on_temp", line)48 49 def on_start(self, resume):50 self.__write("on_start", "true" if resume else "false")51 52 def on_end(self):53 self.__write("on_end")54 55 def on_layerchange(self, layer):56 self.__write("on_layerchange", "%f" % (layer))57 def on_preprintsend(self, gline, index, mainqueue):58 self.__write("on_preprintsend", gline)59 60 def on_printsend(self, gline):...

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