Best Python code snippet using avocado_python
dataframe_operator.py
Source: dataframe_operator.py
...26 print(path.absolute())27 dataframe.to_csv(path, index=True)28def export_dataframe_to_csv(dataframe, filename):29 dataframe_to_csv_file(dataframe, filename + '.csv')30 data_written = file_has_content(filename + '.csv')31 if data_written:32 return True33 else:34 return False35def export_dataframe_to_html(dataframe, filename):36 dataframe_to_html_file(dataframe, filename + '.html')37 prettify_html(filename + '.html')38 data_written = file_has_content(filename + '.html')39 if data_written:40 return True41 else:42 return False43def export_dataframe_to_files(dataframe, filename):44 """Writes a dataframe to CSV and prettified HTML"""45 export_dataframe_to_csv(dataframe, filename)46 export_dataframe_to_html(dataframe, filename)47def file_has_content(path):48 return Path(path).stat().st_size > 049def prettify_html(filename):50 content = Path("./" + filename).read_text()51 soup = BeautifulSoup(content, features='lxml')52 css = soup.new_tag('link')53 css['rel'] = 'stylesheet'54 css['href'] = './mvp.css'55 head = soup.new_tag('head')56 head.insert(1, css)57 html = soup.find('html')58 html.insert(1, head)59 with open(Path("./" + filename), 'w') as f:...
analyzer.py
Source: analyzer.py
1'''2Analyze the flow pass through switches3Interested fields included:4- Throughput5- Goodput ?6- PPS (Packet Per Second) ?7'''8from scapy.all import *9import os10import json11InterfaceNames = []12Throughtputs = []13PacketCounts = []14PPS = []15packet_count = 016throughtput = 017currentTime = 018accumulatedPPS = 019def doStatistic(packet):20 global packet_count, throughtput21 global currentTime, accumulatedPPS, PPS22 # filter out those stupid ICMP protocol unreachiable23 if IP in packet:24 if packet[IP].proto == 1:25 return26 packet_count += 127 throughtput += len(packet)28 # PPS staticists29 # init current time30 if currentTime == 0:31 currentTime = packet.time32 # accmulate count within one sec33 if packet.time > currentTime + 1:34 PPS.append(str(accumulatedPPS))35 accumulatedPPS = 036 currentTime = packet.time37 accumulatedPPS += 138if __name__ == "__main__":39 for filename in os.listdir('pcaps/'):40 if filename.endswith(".pcap"):41 # InterfaceNames.append(filename[:-5])42 43 packet_count = 044 throughtput = 045 46 location = "pcaps/" + filename47 # print(location)48 file_has_content = True49 try:50 sniff(offline=location, prn=doStatistic, store=False)51 except:52 # print(location)53 file_has_content = False54 continue55 if file_has_content:56 InterfaceNames.append(filename[:-5])57 PacketCounts.append(packet_count)58 Throughtputs.append(throughtput)59 dst = "logs/" + filename[:-5] +".json"60 with open(dst, "w") as f:61 print(location)62 json.dump(PPS, f)63 PPS = []64 currentTime = 065 for i in range(len(InterfaceNames)):...
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!!