Best Python code snippet using autotest_python
bibauthorid_general_utils.py
Source: bibauthorid_general_utils.py
...39 if fileout:40 FO = True41 if stdout:42 FO = False43def set_stdout():44 if FO:45 try:46 sys.stdout = pidfiles[PID()]47 except KeyError:48 pidfiles[PID()] = open('/tmp/bibauthorid_log_pid_'+str(PID()),'w')49 sys.stdout = pidfiles[PID()]50 print 'REDIRECTING TO PIDFILE '51#python2.4 compatibility layer.52try:53 any([True])54except:55 def any(x):56 for element in x:57 if element:58 return True59 return False60bai_any = any61try:62 all([True])63except:64 def all(x):65 for element in x:66 if not element:67 return False68 return True69bai_all = all70#end of python2.4 compatibility. Please remove this horror as soon as all systems will have71#been ported to python2.6+72def __print_func(*args):73 set_stdout()74 if PRINT_TS:75 print datetime.now(),76 for arg in args:77 print arg,78 print ""79 sys.stdout.flush()80def __dummy_print(*args):81 pass82def __create_conditional_print(cond):83 if cond:84 return __print_func85 else:86 return __dummy_print87bibauthor_print = __create_conditional_print(bconfig.DEBUG_OUTPUT)88name_comparison_print = __create_conditional_print(bconfig.DEBUG_NAME_COMPARISON_OUTPUT)89metadata_comparison_print = __create_conditional_print(bconfig.DEBUG_METADATA_COMPARISON_OUTPUT)90wedge_print = __create_conditional_print(bconfig.DEBUG_WEDGE_OUTPUT)91if bconfig.DEBUG_OUTPUT:92 status_len = 2093 comment_len = 4094 def padd(stry, l):95 return stry[:l].ljust(l)96 def update_status(percent, comment="", print_ts=False):97 set_stdout()98 filled = int(percent * status_len-2)99 bar = "[%s%s] " % ("#" * filled, "-" * (status_len-2 - filled))100 percent = ("%.2f%% done" % (percent * 100))101 progress = padd(bar + percent, status_len)102 comment = padd(comment, comment_len)103 if print_ts or PRINT_TS_US:104 print datetime.now(),105 print 'pid:',PID(),106 print progress, comment, TERMINATOR,107 sys.stdout.flush()108 def update_status_final(comment=""):109 set_stdout()110 update_status(1., comment, print_ts=PRINT_TS)111 print ""112 sys.stdout.flush()113else:114 def update_status(percent, comment=""):115 pass116 def update_status_final(comment=""):117 pass118def print_tortoise_memory_log(summary, fp):119 stry = "PID:\t%s\tPEAK:\t%s,%s\tEST:\t%s\tBIBS:\t%s\n" % (summary['pid'], summary['peak1'], summary['peak2'], summary['est'], summary['bibs'])120 fp.write(stry)121def parse_tortoise_memory_log(memfile_path):122 f = open(memfile_path)123 lines = f.readlines()...
log.py
Source:log.py
...36 # create formatter37 self.formatter = logging.Formatter()38 # Default is to print to stdout39 self.ch = None40 self.set_stdout()41 def write(self, data):42 self.log.info(data)43 def flush(self):44 try:45 self.ch.flush()46 except Exception, e:47 pass48 def close(self):49 try:50 self.ch.close()51 except Exception, e:52 pass53 def set_quiet(self, state=True):54 level = logging.INFO55 if state:56 level = logging.ERROR57 self.log.setLevel(level)58 def set_debug(self, state=True):59 level = logging.INFO60 if state:61 level = logging.DEBUG62 self.log.setLevel(level)63 def set_logfile(self, filename, mode='w'):64 ch = logging.FileHandler(filename, mode=mode)65 ch.setFormatter(self.formatter)66 if self.ch:67 self.log.removeHandler(self.ch)68 self.log.addHandler(ch)69 self.ch = ch70 def set_fileobj(self, fileobj):71 pass72 def set_stdout(self):73 ch = logging.StreamHandler()74 ch.setFormatter(self.formatter)75 if self.ch:76 self.log.removeHandler(self.ch)77 self.log.addHandler(ch)78 self.ch = ch79# Singleton80logger = logger()81# Set the module functions.82log = logger.log.info83debug = logger.log.debug84info = logger.log.info85warn = logger.log.warn86error = logger.log.error...
notepad_pp.py
Source:notepad_pp.py
...23 oResults.error = True24 oResults.set_violations(False)25 oResults.set_text(oInputArguments.text)26 sOutput = e.message27 oResults.set_stdout(sOutput)28 return oResults29 oVhdlFile.set_indent_map(oConfig.dIndent)30 oRules = rule_list.rule_list(oVhdlFile, oConfig.severity_list, commandLineArguments.local_rules)31 try:32 apply_rules.configure_rules(oConfig, oRules, oConfig.dIndent, iIndex, sFileName)33 except vsg.exceptions.ConfigurationError as e:34 oResults.error = True35 oResults.set_violations(False)36 oResults.set_text(oInputArguments.text)37 sOutput = e.message38 oResults.set_stdout(sOutput)39 return oResults40 oRules.fix(commandLineArguments.fix_phase, commandLineArguments.skip_phase, oConfig.dFixOnly)41 sOutput = '\n'.join(oVhdlFile.get_lines()[1:])42 oResults.set_text(sOutput)43 oRules.clear_violations()44 oRules.check_rules(45 bAllPhases=commandLineArguments.all_phases,46 lSkipPhase=commandLineArguments.skip_phase,47 )48 sStdOut, sIgnore = oRules.report_violations(commandLineArguments.output_format)49 oResults.set_stdout(sStdOut)50 oResults.set_violations(oRules.violations)51 return oResults52class InputArguments():53 def __init__(self):54 self.filename = str(None)55 self.text = None56 self.style = None57 self.configuration = []58 def set_text(self, sText):59 self.text = sText60 def set_style(self, sText):61 self.style = sText62 def add_configuration(self, sText):63 self.configuration.append(sText)64class Results():65 def __init__(self):66 self.text = None67 self.stdout = None68 self.violations = True69 self.error = False70 def set_text(self, sText):71 self.text = sText72 def get_text(self):73 return self.text74 def set_stdout(self, sText):75 self.stdout = sText76 def get_stdout(self):77 return self.stdout78 def has_violations(self):79 return self.violations80 def set_violations(self, bViolations):81 self.violations = bViolations82 def error_status(self):83 return self.error84class command_line_args():85 def __init__(self):86 self.fix = False87 self.style = None88 self.configuration = None...
Check out the latest blogs from LambdaTest on this topic:
Selenium, a project hosted by the Apache Software Foundation, is an umbrella open-source project comprising a variety of tools and libraries for test automation. Selenium automation framework enables QA engineers to perform automated web application testing using popular programming languages like Python, Java, JavaScript, C#, Ruby, and PHP.
Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
As everyone knows, the mobile industry has taken over the world and is the fastest emerging industry in terms of technology and business. It is possible to do all the tasks using a mobile phone, for which earlier we had to use a computer. According to Statista, in 2021, smartphone vendors sold around 1.43 billion smartphones worldwide. The smartphone penetration rate has been continuously rising, reaching 78.05 percent in 2020. By 2025, it is expected that almost 87 percent of all mobile users in the United States will own a smartphone.
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!!