Best Python code snippet using avocado_python
test_utils_diff_validator.py
Source: test_utils_diff_validator.py
...15 f.write("")16 with open(self.files[1], "w") as f:17 f.write("")18 def tearDown(self):19 diff_validator.del_temp_file_copies(self.change.get_target_files())20 self.tmpdir.cleanup()21 def test_change_success(self):22 files = self.files23 with open(files[0], "w") as f:24 f.write("this line is removed\n")25 with open(files[1], "w") as f:26 f.write("this line is not removed\n")27 change = self.change28 change.add_validated_files(files)29 change.append_expected_add(files[0], "this is a new line")30 change.append_expected_remove(files[0], "this line is removed")31 change.append_expected_add(files[1], "this is a new line again")32 diff_validator.make_temp_file_copies(change.get_target_files())33 with open(files[0], "w") as f:34 f.write("this is a new line")35 with open(files[1], "w") as f:36 f.write("this line is not removed\nthis is a new line again\n")37 changes = diff_validator.extract_changes(change.get_target_files())38 change_success = diff_validator.assert_change(changes, change.files_dict)39 change_dict = diff_validator.assert_change_dict(changes, change.files_dict)40 self.assertTrue(change_success, "The change must be valid:\n%s" % diff_validator.create_diff_report(change_dict))41 def test_change_wrong_no_change(self):42 files = self.files43 with open(files[0], "w") as f:44 f.write("this line is removed\n")45 change = self.change46 change.add_validated_files(files)47 change.append_expected_add(files[0], "this is a new line")48 change.append_expected_remove(files[0], "this line is removed")49 diff_validator.make_temp_file_copies(change.get_target_files())50 changes = diff_validator.extract_changes(change.get_target_files())51 change_success = diff_validator.assert_change(changes, change.files_dict)52 change_dict = diff_validator.assert_change_dict(changes, change.files_dict)53 self.assertFalse(change_success, "The change must not be valid:\n%s" % diff_validator.create_diff_report(change_dict))54 def test_change_wrong_add(self):55 files = self.files56 with open(files[0], "w") as f:57 f.write("this line is removed\n")58 change = self.change59 change.add_validated_files(files)60 change.append_expected_add(files[0], "this is a new line")61 change.append_expected_remove(files[0], "this line is removed")62 diff_validator.make_temp_file_copies(change.get_target_files())63 with open(files[0], "w") as f:64 f.write("this is a wrong new line\n")65 changes = diff_validator.extract_changes(change.get_target_files())66 change_success = diff_validator.assert_change(changes, change.files_dict)67 change_dict = diff_validator.assert_change_dict(changes, change.files_dict)68 self.assertFalse(change_success, "The change must not be valid:\n%s" % diff_validator.create_diff_report(change_dict))69 def test_change_unexpected_remove(self):70 files = self.files71 with open(files[0], "w") as f:72 f.write("this line is removed\n")73 change = self.change74 change.add_validated_files(files)75 change.append_expected_add(files[0], "this is a new line")76 diff_validator.make_temp_file_copies(change.get_target_files())77 with open(files[0], "w") as f:78 f.write("this is a new line\n")79 changes = diff_validator.extract_changes(change.get_target_files())80 change_success = diff_validator.assert_change(changes, change.files_dict)81 change_dict = diff_validator.assert_change_dict(changes, change.files_dict)82 self.assertFalse(change_success, "The change must not be valid:\n%s" % diff_validator.create_diff_report(change_dict))83 def test_change_unexpected_add(self):84 files = self.files85 with open(files[0], "w") as f:86 f.write("this line is removed\n")87 change = self.change88 change.add_validated_files(files)89 change.append_expected_remove(files[0], "this line is removed")90 diff_validator.make_temp_file_copies(change.get_target_files())91 with open(files[0], "w") as f:92 f.write("this is an unexpected new line\n")93 changes = diff_validator.extract_changes(change.get_target_files())94 change_success = diff_validator.assert_change(changes, change.files_dict)95 change_dict = diff_validator.assert_change_dict(changes, change.files_dict)96 self.assertFalse(change_success, "The change must not be valid:\n%s" % diff_validator.create_diff_report(change_dict))97if __name__ == '__main__':...
python.py
Source: python.py
1import os2import re3import pandas as pd4resource_dir = ".resoutces/sources/"5def get_target_files(prefix):6 """Get the target files."""7 target_files = [file for file in os.listdir(resource_dir) if file.startswith(prefix)]8 return target_files9def concat_df(file_names):10 """Read in each csv file and concatenate into one dataframe."""11 all_dfs = [pd.read_csv(resource_dir + f) for f in file_names]12 return pd.concat(all_dfs)13def extract_payment(string):14 payment_reg = r"monthly payment:\s*\${0,1}(\d*)"15 match = re.search(payment_reg, string, re.I)16 try:17 payment = match.group(1)18 return payment19 except AttributeError:20 print(f"Failed to edtract payment. No match for string: {string}")21 return None22def main():23 # get all target file names24 file_names = get_target_files(prefix="20")25# file_names = get_target_files('2018')26 27 # combine all files into one df28 combined_df=concat_df(file_names)29 # assign new column using regex for extraction30 combined_df['payment'] = combined_df['comments'].apply(extract_payment)31 32 # save to csv33 combined_df.to_csv("result.csv", index=False)...
findEvent.py
Source: findEvent.py
...13 value = (value ^ np.uint32(ord(c))) * prime_32_const14 if toUint16:15 value = np.uint16(value)16 return value17def get_target_files():18 x = glob.glob('**/*.[ch]??', recursive=True)19 x = filter(lambda y: "CMake" not in y, x)20 x = filter(lambda y: "TESTS" not in y, x)21 x = filter(lambda y: "extern" not in y, x)22 return x23def get_event_map():24 tgts = get_target_files()25 event_names = []26 event_map = defaultdict(list)27 for f in tgts:28 with open(f) as fp:29 for line in fp:30 m = re.match("\s*DECLARE_\w+\((\w+)\)", line)31 if m:32 #print(m)33 event_names.append(m.group(1))34 for evt in event_names:35 x = mHash_fnv1a(evt)36 event_map[x].append(evt)37 pprint(event_map)38 return event_map...
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!!