Best Python code snippet using avocado_python
test_convert2voc_format.py
Source: test_convert2voc_format.py
...38 path = root.find('path')39 assert folder_name == DATASET_NAME40 assert file_name == tmp_file.with_suffix(TARGET_IMG_FORMAT).name41 assert path == None42def test_get_output_file_name():43 rand = randint(0, 100)44 EXPECTED = Path('%s/%05d%s' % (TEST_OUTPUT_DIR, rand, TARGET_IMG_FORMAT))45 output_file_name = _get_output_file_name(TEST_OUTPUT_DIR, rand, TARGET_IMG_FORMAT)46 assert output_file_name == EXPECTED47@pytest.mark.skipif(app_env=='CI', reason="CI environment doesn't have tmp dir")48def test_convert(tmpdir):49 source_annot_dir = Path(TEST_ANNOT_DIR)50 source_img_dir = Path(TEST_IMG_DIR)51 source_annot_paths = [annot_path for annot_path in source_annot_dir.glob(ANNOT_REG_EXP)]52 tmp_annot_dir = tmpdir.mkdir('annotations')53 tmp_img_dir = tmpdir.mkdir('images')54 _convert(source_annot_paths, source_img_dir, tmp_annot_dir, tmp_img_dir, DATASET_NAME)55 for index in range(len(source_annot_paths)):56 target_annot_path = _get_output_file_name(tmp_annot_dir, index, ANNOT_FORMAT)57 target_img_path = _get_output_file_name(tmp_img_dir, index, TARGET_IMG_FORMAT)58 assert target_annot_path.exists()59 assert target_img_path.exists()60@pytest.mark.skipif(app_env=='CI', reason="CI environment doesn't have tmp dir")61def test_prepare_dirs(tmpdir):62 EXPECTED_BASE_DIR = Path(tmpdir, TRAIN_DIR)63 EXPECTED_ANNOT_DIR = Path(EXPECTED_BASE_DIR, TARGET_ANNOT_DIR)64 EXPECTED_IMG_DIR = Path(EXPECTED_BASE_DIR, TARGET_IMG_DIR)65 target_aanot_dir, target_img_dir = _prepare_dirs(tmpdir, TRAIN_DIR)66 assert EXPECTED_ANNOT_DIR.exists()67 assert EXPECTED_IMG_DIR.exists()68 assert target_aanot_dir == EXPECTED_ANNOT_DIR69 assert target_img_dir == EXPECTED_IMG_DIR70@pytest.mark.skipif(app_env=='CI', reason="CI environment doesn't have tmp dir")71def test_convert2voc_format(tmpdir):72 source_annot_dir = Path(TEST_ANNOT_DIR)73 source_annot_paths_len = len([annot_path for annot_path in source_annot_dir.glob(ANNOT_REG_EXP)])74 tmp_annot_dir = Path(tmpdir, DATASET_NAME, TRAIN_DIR, TARGET_ANNOT_DIR)75 tmp_img_dir = Path(tmpdir, DATASET_NAME, TRAIN_DIR, TARGET_IMG_DIR)76 convert2voc_format(TEST_DATASET_DIR, tmpdir, DATASET_NAME)77 for index in range(source_annot_paths_len):78 target_annot_path = _get_output_file_name(tmp_annot_dir, index, ANNOT_FORMAT)79 target_img_path = _get_output_file_name(tmp_img_dir, index, TARGET_IMG_FORMAT)80 assert target_annot_path.exists()...
base_generator.py
Source: base_generator.py
...25 print(f"Building book titled {self.title}")26 for (file_data, file_name) in self._read_chapters():27 data = self._format_data_pre_conversion(file_data) or file_data28 print(f"Checking contents for chapter file {file_name}")29 output_file_name = self._get_output_file_name(file_name)30 if has_hash_changed(data, file_name) is True or not os.path.exists(output_file_name):31 print(f"Content has changed for {file_name}, regenerating chapter")32 self._generate_chapter(file_name, data)33 write_new_hash(data, file_name)34 else:35 print(f"Content of {file_name} has not changed, skipping")36 def _read_chapters(self):37 for file_name in os.listdir(self.chapters_dir):38 file_path = f"{self.chapters_dir}/{file_name}"39 with open(file_path, "r") as fr:40 yield (fr.read(), file_name)41 @abstractmethod42 def _format_data_pre_conversion(self, file_data): 43 """Hook method to tranform data before being pushed to pypandoc44 """45 pass46 def _get_file_path(self, file_name):47 return f"{self.chapters_dir}/{file_name}"48 def _get_output_file_name(self, file_name):49 base_file_name = file_name.split(".")[0]50 return f"{self.output_dir}/{base_file_name}.pdf"51 def _generate_chapter(self, file_name, file_data):52 file_path = self._get_file_path(file_name)53 output_file_name = self._get_output_file_name(file_name)54 print(f"Generating file {output_file_name} with format {self.FILE_FORMAT}")55 try:56 output = pypandoc.convert_file(file_path, self.FILE_FORMAT, outputfile=output_file_name)57 except RuntimeError as e:58 err = str(e)...
minify.py
Source: minify.py
...5 '--remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype ' + \6 '{} -o {}'7clean_css_cmd = 'cleancss -O2 {} -o {}'8uglify_js_cmd = 'uglifyjs {} -o {} --compress --mangle'9def _get_output_file_name(input_file):10 if len(sys.argv) < 2 or sys.argv[1] != '--deploy':11 return input_file.parent / (input_file.stem + '.min' + input_file.suffix)12 return input_file13if __name__ == '__main__':14 for f in filter(15 lambda x: x.suffix in {'.html', '.css', '.js'} and '.min' not in set(x.suffixes) and x.is_file(),16 sorted(Path('./WebContent').iterdir()) + sorted(Path('./WebContent/js').iterdir()) + \17 sorted(Path('./WebContent/css').iterdir())18 ):19 print('minifying {}'.format(f.name))20 f = f.absolute()21 if f.suffix == '.html':22 if os.system(html_minify_cmd.format(f, _get_output_file_name(f))) != 0:23 exit(os.system(html_minify_cmd.format(f, _get_output_file_name(f))))24 elif f.suffix == '.css':25 if os.system(clean_css_cmd.format(f, _get_output_file_name(f))) != 0:26 exit(os.system(clean_css_cmd.format(f, _get_output_file_name(f))))27 else: # .js28 if os.system(uglify_js_cmd.format(f, _get_output_file_name(f))) != 0:...
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!!