Best Python code snippet using hypothesis
fetch.py
Source: fetch.py
1import subprocess2import csv3import os4import time5import signal6import tempfile7import multiprocessing8import sys9def run(cmd, timeout, test):10 try:11 timeout = timeout * 10012 result = {}13 result['test'] = test14 outfile = tempfile.NamedTemporaryFile(mode='w+b')15 p = subprocess.Popen(cmd, shell=True, stdout=outfile, stderr=subprocess.STDOUT, preexec_fn=os.setsid, close_fds=True)16 result['curtime'] = time.time()17 result['endtime'] = result['curtime'] + timeout18 sleep_time = 019 finish = False20 while sleep_time < timeout:21 if p.poll() is not None:22 finish = True23 break24 sleep_time += 125 time.sleep(.01)26 result['finish'] = finish27 outfile.seek(0)28 result['output'] = outfile.readlines()29 return result30 except Exception as e:31 print str(e)32 return None33 finally:34 if p is not None and p.poll() is None:35 print 'killing %s' % test36 os.killpg(os.getpgid(p.pid), signal.SIGKILL)37def finish(result):38 try:39 test = result['test']40 if not result['finish']:41 print CRED + "[Hanged ] " + test + CEND42 current_hanged[test] = 143 else:44 reported = False45 count = 146 for output in result['output']:47 tokens = output.split()48 if len(tokens) < 2:49 continue50 # Drop this line so that we get consistent offsets51 if output == "WARNING: no physical memory support, process creation may be slow.\n":52 continue53 if tokens[1].isdigit():54 test_subtest = test + "," + tokens[1]55 count = int(tokens[1]) + 156 else:57 test_subtest = test + "," + str(count)58 count = count + 159 if "TINFO" in output or test_subtest in current_passed or test_subtest in current_failed or test in current_hanged or test_subtest in current_broken:60 continue61 if output:62 output = output.strip()63 print >>f1, output64 if "TFAIL" in output:65 print >>failed_tests_fh, test_subtest66 print CRED + "[Fail ] " + test_subtest + CEND67 current_failed[test_subtest] = 168 reported = True69 elif "TPASS" in output or "PASS:" in output:70 print >>passed_tests_fh, test_subtest71 print CGREEN + "[Pass ] " + test_subtest + CEND72 current_passed[test_subtest] = 173 reported = True74 elif "TCONF" in output or "TBROK" in output or "BROK" in output or "error" in output:75 print >>broken_tests_fh, test_subtest76 # Syscall not implemented or test preparation failed77 print "[Broken(a) ] " + test_subtest + CEND78 current_broken[test_subtest] = 179 reported = True80 if (not reported):81 print >>broken_tests_fh, test82 print CRED + "[Broken(b) ] " + test + CEND83 for output in result['output']:84 print output85 current_broken[test] = 186 except Exception as e:87 print str(e)88CRED = '\033[91m'89CGREEN = '\033[92m'90CEND = '\033[0m'91DEFAULT_TIMEOUT = 3092resultfile = "run_output"93stablePass = "PASSED"94timeouts = "TIMEOUTS"95failed_tests_file = "Failed.csv"96passed_tests_file = "Passed.csv"97broken_tests_file = "Broken.csv"98f1 = open(resultfile, 'w')99failed_tests_fh = open(failed_tests_file, 'w', 0)100passed_tests_fh = open(passed_tests_file, 'w', 0)101broken_tests_fh = open(broken_tests_file, 'w', 0)102failed_tests_fh.write("Test,Subtest number,Status\n")103passed_tests_fh.write("Test,Subtest number\n")104broken_tests_fh.write("Test,Subtest number,Status\n")105current_passed = dict()106current_failed = dict()107current_broken = dict()108current_hanged = dict()109timeouts_dict = dict()110with open(timeouts, 'rb') as csvfile:111 test_timeout = csv.reader(csvfile)112 test_timeout.next()113 for row in test_timeout:114 test = row[0]115 timeout = row[1]116 timeouts_dict[test] = int(timeout)117os.chdir("opt/ltp/testcases/bin")118pool = multiprocessing.Pool()119with open('../../../../syscalls.graphene') as testcases:120 for line in testcases:121 line = line.strip('\r\n\t')122 tokens = line.split( )123 if (tokens[1] == "SGX") :124 test = tokens[2]125 else :126 test = tokens[1]127 if test=="seq":128 test = tokens[6] #splice02129 try: 130 timeout = timeouts_dict[test]131 except KeyError:132 timeout = DEFAULT_TIMEOUT133 pool.apply_async(run, args=([line], timeout, test), callback=finish)134os.chdir("../../../..")135pool.close()136pool.join()137 138stable_passed = dict()139with open(stablePass, 'rb') as csvfile:140 test_subtest = csv.reader(csvfile)141 test_subtest.next()142 for row in test_subtest:143 tst = row[0] + "," + row[1]144 stable_passed[tst] = 1145print "\n\nRESULT [Difference] :\n---------------------\n"146rv = 0147for test in sorted(stable_passed):148 if not test in current_passed:149 print CRED + "Test '" + test + "' did not pass in the current run!!" + CEND150 rv = -1151for test in sorted(current_passed):152 if not test in stable_passed:153 print CGREEN + "Test '" + test + "' passed in the current run!!" + CEND154print "\n"...
Check out the latest blogs from LambdaTest on this topic:
With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.
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.
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!!