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:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
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.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
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.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!