Best Python code snippet using lisa_python
validate.py
Source:validate.py
1#! /usr/bin/env python32import os3import unittest4import sys5PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))6APP_PATH = os.path.join(PROJECT_PATH, "app")7PYTHON = os.path.join(PROJECT_PATH, "env/bin/python3")8sys.path.append(APP_PATH)9for p in os.listdir(os.path.join(PROJECT_PATH, "env/lib/")):10 PYTHON_LIB = os.path.join(PROJECT_PATH, "env/lib/%s/site-packages" % p)11 sys.path.append(PYTHON_LIB)12from app import (13 configs,14)15class TestValidateMatchboxAssets(unittest.TestCase):16 cwd = os.path.dirname(os.path.abspath(__file__))17 matchbox = os.getenv("CHECK_MATCHBOX_PATH", "%s/matchbox" % cwd)18 assets = "%s/assets" % matchbox19 def test_discoveryC(self):20 rule = "%s/%s/serve" % (self.assets, self.test_discoveryC.__name__.replace("test_", ""))21 list_dir = os.listdir(rule)22 self.assertIn("discoveryC", list_dir)23 def test_enjoliver_agent(self):24 rule = "%s/%s/serve" % (self.assets, self.test_enjoliver_agent.__name__.replace("test_", "").replace("_", "-"))25 list_dir = os.listdir(rule)26 self.assertIn("enjoliver-agent", list_dir)27 def test_coreos(self):28 rule = "%s/%s/serve" % (self.assets, self.test_coreos.__name__.replace("test_", ""))29 list_dir = os.listdir(rule)30 self.assertIn("coreos_production_image.bin.bz2", list_dir)31 self.assertIn("coreos_production_image.bin.bz2.sig", list_dir)32 self.assertIn("coreos_production_image_verity.txt", list_dir)33 self.assertIn("coreos_production_pxe.vmlinuz", list_dir)34 self.assertIn("coreos_production_pxe.vmlinuz.sig", list_dir)35 self.assertIn("coreos_production_pxe_image.cpio.gz", list_dir)36 self.assertIn("coreos_production_pxe_image.cpio.gz.sig", list_dir)37 self.assertIn("version.txt", list_dir)38@unittest.skipIf(os.getenv("SKIP_ACSERVER"), "skip acserver storage")39class TestValidateAcserverStorage(unittest.TestCase):40 cwd = os.path.dirname(os.path.abspath(__file__))41 acserver_d = os.path.join(cwd, "runtime/acserver.d/enjoliver.local")42 ec = configs.EnjoliverConfig(importer=__file__)43 @staticmethod44 def format_image_url(image_url: str):45 image_url = image_url.replace("enjoliver.local/", "")46 image_url = image_url.replace(":", "-")47 return "%s-linux-amd64.aci" % image_url48 def test_cni(self):49 list_dir = os.listdir(os.path.join(self.acserver_d, "cni"))50 self.assertEqual(1, len(list_dir))51 def test_etcd(self):52 list_dir = os.listdir(os.path.join(self.acserver_d, "etcd"))53 self.assertEqual(1, len(list_dir))54 def test_fleet(self):55 list_dir = os.listdir(os.path.join(self.acserver_d, "fleet"))56 self.assertEqual(1, len(list_dir))57 def test_hyperkube(self):58 list_dir = os.listdir(os.path.join(self.acserver_d, "hyperkube"))59 self.assertIn(self.format_image_url(self.ec.hyperkube_image_url), list_dir)60 self.assertEqual(1, len(list_dir))61 def test_lldp(self):62 list_dir = os.listdir(os.path.join(self.acserver_d, "lldp"))63 self.assertIn(self.format_image_url(self.ec.lldp_image_url), list_dir)64 self.assertEqual(1, len(list_dir))65 def test_iproute2(self):66 list_dir = os.listdir(os.path.join(self.acserver_d, "iproute2"))67 self.assertEqual(1, len(list_dir))68 def test_rkt(self):69 list_dir = os.listdir(os.path.join(self.acserver_d, "rkt"))70 self.assertEqual(1, len(list_dir))71 def test_vault(self):72 list_dir = os.listdir(os.path.join(self.acserver_d, "vault"))73 self.assertEqual(1, len(list_dir))74 def test_ceph_tools(self):75 list_dir = os.listdir(os.path.join(self.acserver_d, "ceph-tools"))76 self.assertIn(self.format_image_url(self.ec.cephtools_image_url), list_dir)77 self.assertEqual(1, len(list_dir))78 def test_dnsmasq(self):79 list_dir = os.listdir(os.path.join(self.acserver_d, "dnsmasq"))80 self.assertEqual(1, len(list_dir))81 def test_tiller(self):82 list_dir = os.listdir(os.path.join(self.acserver_d, "tiller"))83 self.assertEqual(1, len(list_dir))84 def test_heapster(self):85 list_dir = os.listdir(os.path.join(self.acserver_d, "heapster"))86 self.assertEqual(1, len(list_dir))87 def test_node_exporter(self):88 list_dir = os.listdir(os.path.join(self.acserver_d, "node-exporter"))89 self.assertEqual(1, len(list_dir))90 def test_kube_state_metrics(self):91 list_dir = os.listdir(os.path.join(self.acserver_d, "kube-state-metrics"))92 self.assertEqual(1, len(list_dir))93 def test_prometheus(self):94 list_dir = os.listdir(os.path.join(self.acserver_d, "prometheus"))95 self.assertEqual(1, len(list_dir))96 def test_haproxy(self):97 list_dir = os.listdir(os.path.join(self.acserver_d, "haproxy"))98 self.assertEqual(1, len(list_dir))99class TestValidateRuntime(unittest.TestCase):100 cwd = os.path.dirname(os.path.abspath(__file__))101 runtime_d = os.path.join(cwd, "runtime")102 def test_rkt(self):103 self.assertTrue(os.path.isfile(os.path.join(self.runtime_d, "rkt", "rkt")))104 self.assertTrue(os.path.isfile(os.path.join(self.runtime_d, "stage1.d", "coreos.json")))105 self.assertTrue(os.path.isfile(os.path.join(self.runtime_d, "paths.d", "paths.json")))106 def test_helm(self):107 self.assertTrue(os.path.isfile(os.path.join(self.runtime_d, "helm", "helm")))108 def test_acserver(self):109 self.assertTrue(os.path.isfile(os.path.join(self.runtime_d, "acserver", "acserver")))110 def test_matchbox(self):111 self.assertTrue(os.path.isfile(os.path.join(self.runtime_d, "matchbox", "matchbox")))112if __name__ == '__main__':...
gen_lists.py
Source:gen_lists.py
1import argparse2import os3from os import path as osp4import sys5def gen_list(data_root, data_dir, list_dir, phase, list_type, suffix='.jpg'):6 phase_dir = osp.join(data_root, data_dir, phase)7 if not osp.exists(phase_dir):8 raise ValueError('Can not find folder {}'.format(phase_dir))9 images = sorted([osp.join(data_dir, phase, n)10 for n in os.listdir(phase_dir)11 if n[-len(suffix):] == suffix])12 print('Found', len(images), 'items in', data_dir, phase)13 out_path = osp.join(list_dir, '{}_{}.txt'.format(phase, list_type))14 if not osp.exists(list_dir):15 os.makedirs(list_dir)16 print('Writing', out_path)17 with open(out_path, 'w') as fp:18 fp.write('\n'.join(images))19def gen_images(data_root, list_dir, image_type='100k'):20 for phase in ['train', 'val', 'test']:21 gen_list(data_root, osp.join('images', image_type),22 list_dir, phase, 'images', '.jpg')23def gen_drivable(data_root):24 image_type = '100k'25 label_dir = 'drivable_maps/labels'26 list_dir = 'lists/100k/drivable'27 gen_images(data_root, list_dir, image_type)28 for p in ['train', 'val']:29 gen_list(data_root, label_dir, list_dir, p, 'labels',30 'drivable_id.png')31def gen_seg(data_root):32 image_type = '10k'33 label_dir = 'seg_maps/labels'34 list_dir = 'lists/10k/seg'35 gen_images(data_root, list_dir, image_type)36 for p in ['train', 'val']:37 gen_list(data_root, label_dir, list_dir, p, 'labels',38 'train_id.png')39if __name__ == '__main__':40 gen_drivable(sys.argv[1])...
create_dataset.py
Source:create_dataset.py
1#===================================================2## Author: Reza Azad (rezazad68@gmail.com)3#===================================================4from shutil import copyfile5import os6import numpy as np7ADD = "/reza/data/data-multi-subject/derivatives/labels/"8ADD2 = "/reza/data/data-multi-subject/"9Destination_path = 'dataset/'10list_dir = os.listdir(ADD)11Total = 012for idx in range (len(list_dir)): 13 ## Copy the T1 disc label 14 src1 = ADD+list_dir[idx] + '/anat/'+list_dir[idx]+'_T1w_labels-disc-manual.nii.gz'15 dst1 = list_dir[idx] + '/' +list_dir[idx]+'_T1w_labels-disc-manual.nii.gz'16 17 ## Copy the T2 disc label 18 src2 = ADD+list_dir[idx] + '/anat/'+list_dir[idx]+'_T2w_labels-disc-manual.nii.gz'19 dst2 = list_dir[idx] + '/' +list_dir[idx]+'_T2w_labels-disc-manual.nii.gz' 20 21 ## Copy the T1 file 22 src3 = ADD2+list_dir[idx] + '/anat/'+list_dir[idx]+'_T1w.nii.gz'23 dst3 = list_dir[idx] + '/' +list_dir[idx]+'_T1w.nii.gz' 24 25 ## Copy the T2 file 26 src4 = ADD2+list_dir[idx] + '/anat/'+list_dir[idx]+'_T2w.nii.gz'27 dst4 = list_dir[idx] + '/' +list_dir[idx]+'_T2w.nii.gz' 28 29 if os.path.exists(src1):30 if not os.path.exists('dataset/'+list_dir[idx]):31 os.makedirs(Destination_path+list_dir[idx])32 copyfile(src1, Destination_path+dst1)33 copyfile(src2, Destination_path+dst2)34 copyfile(src3, Destination_path+dst3)35 copyfile(src4, Destination_path+dst4)36 Total += 1...
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!!