Best Python code snippet using refurb_python
ordered_db.py
Source:ordered_db.py
...11from json import load12from utils import error, success, DB_FILE13# Test which checks whether the data.json file is sorted by key and14# any lists within those keys. Success signified by exit code.15def sort_errors(list, stype, root=""):16 """17 Checks if a list of 'stype' strings has sorting errors, case insensitive.18 Takes as optional string 'root' as a root value for use with sublists.19 """20 has_errors = False21 reference = sorted(list, key=lambda item: item.lower())22 for i in range(len(list)):23 if list[i] == reference[i]:24 continue25 correct_index = reference.index(list[i])26 has_errors = True27 if root == "":28 error_msg = "{} '{}' not correctly ordred"29 else:30 error_msg = "{} '{}' of '{}' not correctly ordred"31 error(error_msg.format(stype, list[i], root))32 print("Should be placed at {} instead of {}".format(correct_index, i))33 return has_errors34with open(DB_FILE, 'r') as db_obj:35 data = load(db_obj, object_pairs_hook=OrderedDict)36has_errors = sort_errors(list(data.keys()), "Database entry")37for key, value in data.items():38 if value.get("android") and sort_errors(value["android"], "Android icon"):39 has_errors = True40 if value.get("linux"):41 symlinks = value["linux"].get("symlinks")42 if symlinks and sort_errors(symlinks, "Linux symlink", key):43 has_errors = True44 if value.get("osx") and sort_errors(value["osx"], "OSX icon"):45 has_errors = True46 if value.get("tags") and sort_errors(value["tags"], "Icon tag"):47 has_errors = True48if not has_errors:49 success("Database is properly sorted")...
build-analyze.py
Source:build-analyze.py
2from util import log, run_cmd_throw, run_cmd3from util import verify_started_in_right_directory4from buildbot import extract_analyze_errors, strip_empty_lines56def sort_errors(lines, rel_path_start):7 if len(lines) == 0: return ([], [], [])8 sumatra_errors = []9 mupdf_errors = []10 ext_errors = []11 for l in lines:12 l = l[rel_path_start:]13 if l.startswith("src\\"): sumatra_errors.append(l)14 elif l.startswith("mupdf\\"): mupdf_errors.append(l)15 elif l.startswith("ext\\"): ext_errors.append(l)16 else: assert(False)17 return (sumatra_errors, mupdf_errors, ext_errors)1819def print_lines(lines):20 for l in lines: print("%s\n" % l)2122def pretty_print_errors(s):23 lines = extract_analyze_errors(s)24 (sumatra, mupdf, ext) = sort_errors(lines, len(os.getcwd()) + 1)25 print("******** EXT warnings\n")26 print_lines(ext)27 print("******** MUPDF warnings\n")28 print_lines(mupdf)29 print("******** SUMATRA warnings\n")30 print_lines(sumatra)31 print("Sumatra: %d, mupdf: %d, ext: %d" % (len(sumatra), len(mupdf), len(ext)))3233def main():34 verify_started_in_right_directory()35 config = "CFG=rel"36 obj_dir = "obj-rel"37 ver = "1000" # doesn't matter what version we claim38 extcflags = "EXTCFLAGS=-DSVN_PRE_RELEASE_VER=%s" % ver
...
rank_errors.py
Source:rank_errors.py
1import sys2import re3logfile = sys.argv[1]4errors = {}5with open(logfile) as f:6 for line in f:7 if "ERROR" not in line:8 continue9 pattern1 = r"ERROR: "10 errorIndex = re.search(pattern1, line)11 pattern2 = r"\((\w+)\)$"12 nameIndex = re.search(pattern2, line)13 msgStart = errorIndex.span()[1]14 msgEnd = nameIndex.span()[0]15 errMsg = line[msgStart:msgEnd]16 errors[errMsg.strip()] = errors.get(errMsg.strip(), 0)+117sort_errors = sorted(errors.items(), key=lambda x: x[1], reverse=True)...
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!!