Best Python code snippet using tempest_python
dataset.py
Source: dataset.py
1DEFAULT_NUM = 0.982class Dataset:3 def __init__(self, size_window_left=None, size_window_right=None):4 self.output_file = None5 self.size_window_left = size_window_left6 self.size_window_right = size_window_right7 self.file_swarm = None8 self.file_swarm_lines = None9 self.current_file_swarm_line = None10 def load_samples(self, swarm_file):11 try:12 self.file_swarm = open(swarm_file, 'r')13 self.file_swarm_lines = self.file_swarm.readline()14 self.current_file_swarm_line = self.file_swarm_lines15 except FileNotFoundError:16 print("File swarm not found!")17 exit()18 def load_next_peer(self):19 list_peer_snapshots = []20 while True:21 if self.file_swarm_lines[0] == "#":22 self.file_swarm_lines = self.file_swarm.readline()23 continue #skipt #commented line24 line_loaded = self.file_swarm_lines.split(' ')25 line_file_read = [int(line_loaded[2]), int(line_loaded[0]), 1]26 list_peer_snapshots.append(line_file_read)27 self.file_swarm_lines = self.file_swarm.readline()28 try:29 if self.file_swarm_lines == "":30 return list_peer_snapshots, 031 if int(self.file_swarm_lines.split(' ')[2]) != line_file_read[0]:32 return list_peer_snapshots, 133 except IndexError:34 return list_peer_snapshots, 135 def load_next_peer_mif(self):36 POS_PEER = 037 POS_SNAPSHOT = 138 list_peer_snapshots = []39 while True:40 if self.current_file_swarm_line[0] == "#":41 self.current_file_swarm_line = self.file_swarm.readline()42 continue #skip it #commented line43 # peer snapshot44 line_split = self.current_file_swarm_line.split(' ')45 peer = int(line_split[POS_PEER]) #46 snapshot = int(line_split[POS_SNAPSHOT]) #47 line_file_read = [peer, snapshot, 1] #TODO: check48 list_peer_snapshots.append(line_file_read)49 self.current_file_swarm_line = self.file_swarm.readline()50 try:51 if self.current_file_swarm_line == "":52 return list_peer_snapshots, 053 #if the next line is about another peer, get out54 if int(self.current_file_swarm_line.split(' ')[POS_PEER]) != peer:55 return list_peer_snapshots, 156 except IndexError:57 return list_peer_snapshots, 158 def load_next_peer2(self):59 list_peer_snapshots = []60 while True:61 self.file_swarm_lines = self.file_swarm.readline()62 # linha comentada63 if self.file_swarm_lines[0] == "#":64 self.file_swarm_lines = self.file_swarm.readline()65 continue #skipt #commented line66 #linha vazia/ bugada67 try:68 if self.file_swarm_lines == "":69 return list_peer_snapshots, 070 if int(self.file_swarm_lines.split(' ')[2]) != line_file_read[0]:71 return list_peer_snapshots, 172 except IndexError:73 return list_peer_snapshots, 174 # linha ok75 line_loaded = self.file_swarm_lines.split(' ')76 line_file_read = [int(line_loaded[2]), int(line_loaded[0]), 1]77 list_peer_snapshots.append(line_file_read)78 @staticmethod79 def fill_gaps_per_peer(list_snapshots):80 #print('snapshots input : {}'.format(list_snapshots))81 list_snapshots.sort(key=lambda x: x[1])82 if not len(list_snapshots[-1]) != 0:83 return 084 iterator, iterator_list, temporary_list = list_snapshots[0][1], 0, []85 while iterator < int(list_snapshots[-1][1]):86 if list_snapshots[iterator_list][1] != iterator:87 temporary_list.append([int(list_snapshots[1][0]), int(iterator), 0])88 else:89 temporary_list.append(list_snapshots[iterator_list])90 iterator_list += 191 iterator += 192 temporary_list.append(list_snapshots[-1])93 #print('snapshots output: {}'.format(temporary_list))94 #sys.exit()95 return temporary_list96 def filling_borders(self, list_snapshots):97 window_left = [[list_snapshots[0][0], -1, 0]] * self.size_window_left98 window_right = [[list_snapshots[0][0], -1, 0]] * self.size_window_left99 return window_left + list_snapshots + window_right100 def create_windows(self, list_snapshots):101 list_x, list_y, list_support = [], [], []102 try:103 for i in range(self.size_window_left, len(list_snapshots) - self.size_window_right):104 list_x.append(list_snapshots[(i - self.size_window_left):(i + self.size_window_right + 1)])105 list_y.append(list_snapshots[i][2])106 list_support.append(list_snapshots[i])107 return list_x, list_y, list_support108 except IndexError:109 return [], []110 @staticmethod111 def get_samples_vectorized(sample, out):112 sample_vectorized = []113 for i in range(len(sample)):114 sample_vectorized.append(float(sample[i][2]))115 return sample_vectorized, float(out)116 def create_sample_training(self, list_snapshots):117 sample_x, sample_y = [], []118 list_x, list_y, list_support = self.create_windows(list_snapshots)119 for i in range(len(list_x)):120 x, y = self.get_samples_vectorized(list_x[i], list_y[i])121 sample_x.append(x)122 sample_y.append(float(y))123 return sample_x, sample_y, list_support124 def get_training_samples(self, list_snapshots):125 x, y, support_samples = self.create_sample_training(list_snapshots)126 for i in range(len(x)):127 true_position_left = False128 for j in range(2):129 if x[i][self.size_window_left-j-1] > DEFAULT_NUM:130 true_position_left = True131 true_position_right = False132 for j in range(2):133 if x[i][self.size_window_left + j+1] > DEFAULT_NUM:134 true_position_right = True135 if (not true_position_left) or (not true_position_right):136 y[i] = float(0)137 if x[i][self.size_window_left-1] > DEFAULT_NUM and x[i][self.size_window_left+1] > DEFAULT_NUM:138 y[i] = float(1)139 x[i][self.size_window_left] = float(0)140 x[i] = [float(i) for i in x[i]]141 return x, y, support_samples142 def get_predict_samples(self, list_snapshots):143 x, y, support_samples = self.create_sample_training(list_snapshots)144 for i in range(len(x)):145 x[i][self.size_window_left] = float(0)146 x[i] = [float(i) for i in x[i]]147 return x, y, support_samples148 def create_file_results(self, file_results):149 self.output_file = open(file_results, 'w')150 def write_swarm(self, values):151 for i in values:152 output_result_format = str(i[1]) + ' ' + str(i[0]) + ' ' + str(i[2]) + '\n'...
aciconfigdb_test.py
Source: aciconfigdb_test.py
...45 self.fake_out = FakeStdio()46 sys.stdout = self.fake_out47 def tearDown(self):48 sys.stdout = self.stdout49 def test_basic_list_snapshots(self):50 """51 Test the basic snapshot52 """53 # Set the arguments to just list the snapshot versions54 self.args.list_snapshots = True55 # Call the tool to list the snapshots56 aciconfigdb.main(self.args)57 # Check the output58 self.assertEquals(self.fake_out.output[0], 'Versions')59 self.assertEquals(self.fake_out.output[1], '\n')60 def test_basic_snapshot_v1(self):61 """62 Test the basic snapshot63 """...
Check out the latest blogs from LambdaTest on this topic:
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.
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.
In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.
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!!