Best Python code snippet using avocado_python
test_iperf.py
Source: test_iperf.py
...24 25 def tearDown(self):26 self.log.close()27 28 def test_iperf(self):29 fail = False30 network_devices = get_target.get_all()31 for device in network_devices:32 print("Destination: " + device[1] + "\n")33 self.log.write("Destination: " + device[1] + "\n")34 print("starting iperf on server")35 start_iperf(device[1])36 print("running traceroute on server")37 traceroute = subprocess.Popen(["traceroute", "-n", device[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)38 print("starting iperf on client") 39 iperf = subprocess.Popen(["iperf", "--client", device[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)40 print("logging") 41 self.log.write(traceroute.communicate()[0])42 self.log.write(iperf.communicate()[0])43 print("stopping iperf on server")44 stop_iperf(device[1])45 self.assertFalse(fail)46#The following is the stress tests... they may not be appropriate.47"""48class testStressFunctions(unittest.TestCase):49 def setUp(self):50 num = 151 date_string = time.strftime("%Y-%m-%d")52 metric_dir = "logs/"+date_string+"("+str(num)+")"53 while os.path.isdir("logs/"+date_string+"("+str(num+1)+")"):54 num += 155 metric_dir = "logs/"+date_string+"("+str(num)+")"56 self.log = open(metric_dir+"/iperf", "a")57 self.log.write(time.strftime("Test Time: %Y-%m-%d %H:%M:%S") + "\n")58 59 def tearDown(self):60 self.log.close()61 def run_iperf(self, device, other=None):62 self.log.write("Destination: " + device[1] + "\n")63 start_iperf(device[1])64 traceroute = subprocess.Popen(["traceroute", "-n", device[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)65 iperf = subprocess.Popen(["iperf", "-c", device[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)66 self.log.write(traceroute.communicate()[0])67 self.log.write(iperf.communicate()[0])68 stop_iperf(device[1])69 70 def test_iperf(self):71 network_devices = get_target.get_all()72 files = get_target.get_all("test_files")73 for device in network_devices:74 for stress_num in stress.stressors:75 self.log.write("Stress Testing")76 self.log.write(str(stress_num)+" of wget processes")77 for f_loc in files:78 t1 = Thread(target=self.run_iperf, args=(device[1], ""))79 t2 = Thread(target=stress.stress_network, args=(stress_num, f_loc[1]))80 t1.start()81 t2.start()82 t1.join()83 t2.join()84 ...
run_tests.py
Source: run_tests.py
1"""2Evaluation tests for Commotion Networks.3"""4import unittest5import time6import logging7import sys8import os9from tests import test_connection10from tests import test_load11from tests import test_leases12from tests import test_iperf13def create_metric_dir():14 num = 115 date_string = time.strftime("%Y-%m-%d")16 metric_dir = "logs/"+date_string+"("+str(num)+")"17 while os.path.isdir(metric_dir):18 num += 119 metric_dir = "logs/"+date_string+"("+str(num)+")"20 os.makedirs(metric_dir, 0x1C0)21 return metric_dir22def create_runner(suite_type, verbosity_level=None, runner_type="text"):23 """creates a testing runner.24 suite_type: (string) suites to run [acceptable values = suite_types in build_suite()]25 runner_type: (string) type of runner to create. [implemented values = 'text']26 """27 metric_dir = create_metric_dir()28 f = None29 if runner_type == "text":30 runner = unittest.TextTestRunner(verbosity=verbosity_level)31 else:32 log_file = metric_dir+"/testSuite"33 f = open(log_file, "w")34 runner = unittest.TextTestRunner(f, verbosity=verbosity_level)35 print("LOGFILE: -> "+metric_dir)36 test_suite = build_suite(suite_type)37 runner.run (test_suite)38 if f:39 f.close()40def build_suite(suite_type):41 suite = unittest.TestSuite()42 suite_types = {43 "iperf": [test_iperf.testFunctions],44 "lease": [test_leases.testFunctions],45 "connection": [test_connection.testFunctions],46 "all": [test_iperf.testFunctions,47 test_leases.testFunctions,48 test_connection.testFunctions]}49 for test_case in suite_types[suite_type]:50 suite.addTest (unittest.makeSuite(test_case))51 return suite52if __name__ == '__main__':53 """Creates argument parser for required arguments and calls test runner"""54 import argparse55 parser = argparse.ArgumentParser(description='openThreads test suite')56 parser.add_argument("-s", "--suite", nargs="?", default="all", const="all", dest="suite_type", metavar="SUITE", help="Pick a specific test suite")57 parser.add_argument("-v", "--verbosity", nargs="?", default=None, const=2, dest="verbosity_level", metavar="VERBOSITY", help="make test_suite verbose")58 parser.add_argument("-l", "--logfile", nargs="?", default="text", const="commotion_test.log", dest="logfile", metavar="LOGFILE", help="Specify an alternative logfile name")59 args = parser.parse_args()...
driver_tests.py
Source: driver_tests.py
...22 return True23"""24Test case for testing the iperf functionality.25"""26def test_iperf():27 try:28 child_output = subprocess.check_output(['sudo', 'iperf3', '-B', '10.50.0.1', '-c', '10.60.1.1', '-t', '60', '-i', '10', '-O', '5'])29 child_output = child_output.decode()30 # print(child_output)31 except subprocess.CalledProcessError as e:32 print(e)33 return False34 return True...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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!!