Best Python code snippet using avocado_python
task.py
Source:task.py
...118 self.status_services,119 self.category,120 self.job_id,121 )122 def are_dependencies_available(self, runners_registry=None):123 """Verifies if dependencies needed to run this task are available.124 This currently checks the runner command only, but can be expanded once125 the handling of other types of dependencies are implemented. See126 :doc:`/blueprints/BP002`.127 """128 if runners_registry is None:129 runners_registry = RUNNERS_REGISTRY_STANDALONE_EXECUTABLE130 return self.runnable.runner_command(runners_registry)131 def setup_output_dir(self, output_dir=None):132 if not self.runnable.output_dir:133 output_dir = output_dir or tempfile.mkdtemp(prefix=".avocado-task-")134 self.runnable.output_dir = output_dir135 @classmethod136 def from_recipe(cls, task_path):...
filter_packages_using_github_linguist.py
Source:filter_packages_using_github_linguist.py
...5import shutil6from pathlib import Path7import delegator8from .utils import tmp_cwd, git_cxt9def are_dependencies_available():10 """11 Check if git and github-linguist are available12 """13 dependencies = ["git", "github-linguist"]14 for dependency in dependencies:15 if shutil.which(dependency) is None:16 print(f"{dependency} is not installed")17 return False18 return True19def create_argument_parser():20 parser = argparse.ArgumentParser()21 parser.add_argument("-pd", "--packages-dir", type=str, required=True,22 help="Directory with all extracted package directories to test")23 parser.add_argument("-o", "--output", type=str, required=True, help="File to write dump output to")24 return parser25def is_package_implemented_in_c(package_dir):26 """27 Check if package is mainly implemented in C using github-linguist. Requires creating a git repository.28 """29 is_c_package = False30 with tmp_cwd(package_dir), git_cxt() as git_cxt_res:31 if not git_cxt_res:32 return "Failed"33 # try running github-linguist34 c = delegator.run("github-linguist")35 if c.return_code != 0:36 print(f"github-linguist exited with error code {c.return_code}")37 return "Failed"38 # parse the output39 linguist_output = c.out.strip()40 if linguist_output != "":41 try:42 percentages = dict(entry.replace(' ', '').split('%') for entry in linguist_output.split(os.linesep))43 except ValueError:44 print(f"failed to compute language percentage")45 return "Failed"46 is_c_package = (percentages[max(percentages.keys(), key=float)] == 'C')47 return is_c_package48def main(packages_dir, output):49 if not are_dependencies_available():50 return51 extracted_packages_dir = Path(packages_dir)52 output_file = Path(output).absolute()53 if not extracted_packages_dir.is_dir():54 print(f"{extracted_packages_dir} is not a valid directory.")55 return56 packages_list = next(os.walk(extracted_packages_dir))[1]57 if packages_list == []:58 print(f"No extracted packages found in {extracted_packages_dir}")59 return60 classified_output = {"c": [], "not-c": [], "failed": []}61 total = len(packages_list)62 print(f"Found {total} packages")63 for count, package_dir in enumerate(packages_list, 1):...
find_c_packages.py
Source:find_c_packages.py
...5import os6import shutil7from pathlib import Path8import delegator9def are_dependencies_available():10 """11 Check if git and github-linguist are available12 """13 dependencies = ["git", "github-linguist"]14 for dependency in dependencies:15 if shutil.which(dependency) is None:16 print(f"{dependency} is not installed")17 return False18 return True19def create_argument_parser():20 parser = argparse.ArgumentParser()21 parser.add_argument("-pd", "--packages-dir", type=str, required=True,22 help="Directory with all extracted package directories to test")23 parser.add_argument("-o", "--output", type=str, required=True, help="File to write dump output to")24 return parser25def is_package_implemented_in_c(package_dir):26 """27 Check if package is mainly implemented in C using github-linguist. Requires creating a git repository.28 """29 os.chdir(package_dir)30 git_commands = ["git init", "git add .", "git commit -m 'blah'"]31 cleanup_git_command = "rm -rf .git"32 for command in git_commands:33 c = delegator.run(command)34 if c.return_code != 0:35 print(f"failed to create git repo")36 delegator.run(cleanup_git_command)37 return "Failed"38 is_c_package = False39 c = delegator.run("github-linguist")40 if c.return_code != 0:41 print(f"github-linguist exited with error code {c.return_code}")42 delegator.run(cleanup_git_command)43 return "Failed"44 else:45 linguist_output = c.out.strip()46 if linguist_output != "":47 try:48 percentages = dict(entry.replace(' ', '').split('%') for entry in linguist_output.split(os.linesep))49 except ValueError:50 print(f"failed to compute language percentage")51 delegator.run(cleanup_git_command)52 return "Failed"53 is_c_package = (percentages[max(percentages.keys(), key=float)] == 'C')54 delegator.run(cleanup_git_command)55 return is_c_package56def main():57 if not are_dependencies_available():58 return59 arg_parser = create_argument_parser()60 args = arg_parser.parse_args()61 extracted_packages_dir = Path(args.packages_dir)62 output_file = Path(args.output).absolute()63 if not extracted_packages_dir.is_dir():64 print(f"{extracted_packages_dir} is not a valid directory.")65 return66 packages_list = next(os.walk(extracted_packages_dir))[1]67 if packages_list == []:68 print(f"No extracted packages found in {extracted_packages_dir}")69 return70 classified_output = {"c": [], "not-c": [], "failed": []}71 total = len(packages_list)...
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!!