Best Python code snippet using Airtest
deviceconfig.py
Source:deviceconfig.py
...47 """48 Read the optional package versions into a dictionary.49 """50 output = OrderedDict()51 output["Pytorch Ignite"] = get_package_version("ignite")52 output["Nibabel"] = get_package_version("nibabel")53 output["scikit-image"] = get_package_version("skimage")54 output["Pillow"] = get_package_version("PIL")55 output["Tensorboard"] = get_package_version("tensorboard")56 output["gdown"] = get_package_version("gdown")57 output["TorchVision"] = get_package_version("torchvision")58 output["tqdm"] = get_package_version("tqdm")59 output["lmdb"] = get_package_version("lmdb")60 output["psutil"] = psutil_version61 output["pandas"] = get_package_version("pandas")62 output["einops"] = get_package_version("einops")63 output["transformers"] = get_package_version("transformers")64 return output65def print_config(file=sys.stdout):66 """67 Print the package versions to `file`.68 Args:69 file: `print()` text stream file. Defaults to `sys.stdout`.70 """71 for k, v in get_config_values().items():72 print(f"{k} version: {v}", file=file, flush=True)73 print(f"MONAI flags: HAS_EXT = {HAS_EXT}, USE_COMPILED = {USE_COMPILED}")74 print(f"MONAI rev id: {monai.__revision_id__}")75 print("\nOptional dependencies:", file=file, flush=True)76 for k, v in get_optional_config_values().items():77 print(f"{k} version: {v}", file=file, flush=True)...
find_k8s.py
Source:find_k8s.py
...52 for x in inventory.items():53 server_id = x[0]54 server_csp_id = x[1]["server_metadata"]["csp_account_id"] if "csp_account_id" in x[1]["server_metadata"] else "" # NOQA55 server_instance_id = x[1]["server_metadata"]["csp_instance_id"] if "csp_instance_id" in x[1]["server_metadata"] else "" # NOQA56 kubectl_version = get_package_version(x[1]["packages"], "kubectl")57 kubeadm_version = get_package_version(x[1]["packages"], "kubeadm")58 kubelet_version = get_package_version(x[1]["packages"], "kubelet")59 kube_procs = get_kube_procs(x[1]["processes"])60 kubectl_vulnerable = is_kube_vulnerable(kube_min_ver, kubectl_version)61 kubeadm_vulnerable = is_kube_vulnerable(kube_min_ver, kubeadm_version)62 kubelet_vulnerable = is_kube_vulnerable(kube_min_ver, kubelet_version)63 print("{}{}{}{}{}{}{}{}{}\n{}\n\n".format(server_id.ljust(40),64 server_csp_id.ljust(40),65 server_instance_id.ljust(40),66 kubectl_version.ljust(16),67 kubeadm_version.ljust(16),68 kubelet_version.ljust(16),69 kubectl_vulnerable.ljust(20),70 kubeadm_vulnerable.ljust(20),71 kubelet_vulnerable.ljust(20),72 kube_procs))73 dump_to_csv(inventory, kube_min_ver)74 dump_to_json(inventory)75def dump_to_csv(inventory, comparisons):76 with open("out.csv", "w") as out_file:77 fieldnames = ["csp_account_id", "csp_instance_id", "halo_id",78 "kubectl_version", "kubeadm_version", "kubelet_version",79 "processes", "kubectl_vulnerable", "kubeadm_vulnerable",80 "kubelet_vulnerable"]81 writer = csv.DictWriter(out_file, fieldnames=fieldnames)82 writer.writeheader()83 for workload_id, meta in inventory.items():84 kubectl_version = get_package_version(meta["packages"], "kubectl")85 kubeadm_version = get_package_version(meta["packages"], "kubeadm")86 kubelet_version = get_package_version(meta["packages"], "kubelet")87 dataz = {"halo_id": workload_id,88 "csp_account_id": meta["server_metadata"]["csp_account_id"] if "csp_account_id" in meta["server_metadata"] else "", # NOQA89 "csp_instance_id": meta["server_metadata"]["csp_instance_id"] if "csp_instance_id" in meta["server_metadata"] else "", # NOQA90 "kubectl_version": kubectl_version,91 "kubeadm_version": kubeadm_version,92 "kubelet_version": kubelet_version,93 "processes": "\n".join([x["command"] for x in meta["processes"] if "kube" in x["process_name"]]), # NOQA94 "kubectl_vulnerable": is_kube_vulnerable(comparisons,95 kubectl_version),96 "kubeadm_vulnerable": is_kube_vulnerable(comparisons,97 kubeadm_version),98 "kubelet_vulnerable": is_kube_vulnerable(comparisons,99 kubelet_version)}100 writer.writerow(dataz)101 print("Wrote out.csv")102 return103def dump_to_json(inventory):104 with open("out.json", "w") as out_file:105 json.dump(inventory, out_file)106 print("Wrote out.json")107def merge_server_lists(list_1, list_2):108 observed = set({})109 list_1.extend(list_2)110 cleaned = []111 for server in list_1:112 if server["id"] in observed:113 continue114 else:115 cleaned.append(server)116 observed.add(server["id"])117 return cleaned118def get_kube_procs(procs):119 kube_procs = [" {}".format(x["command"]) for x in procs120 if "kube" in x["process_name"]]121 return "\n".join(kube_procs)122def get_package_version(packages, package_name):123 for p_name, p_version in packages.items():124 if p_name.startswith(package_name):125 return(p_version)126 return "NONE"127def is_kube_vulnerable(comparisons, actual):128 try:129 if actual == "NONE":130 return "INDETERMINATE"131 majorminor = str(".".join(actual.split(".")[:2]))132 # We know all these are vulnerable133 if majorminor in ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5",134 "1.6", "1.7", "1.8", "1.9"]:135 return "YES"136 comparator = comparisons[majorminor]...
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!!