How to use _clean_up method in fMBT

Best Python code snippet using fMBT_python

test_cases.py

Source:test_cases.py Github

copy

Full Screen

...58 time.sleep(10)59 cmd_start = 'virsh --connect qemu:///system start ' + img_file60 os.system(cmd_start)61 time.sleep(WAIT_VM_OK_TIME)62 def _clean_up(self):63 clean_up(self.dom_name, self.tmp_path)64 def execute(self):65 self._prepare()66 # Get ip of vm67 addr = get_addr(self.dom_name)68 ssh = paramiko.SSHClient()69 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())70 try:71 ssh.connect(addr, username=DEFAULT_SSH_USER, password=DEFAULT_SSH_PASSWORD)72 print('User root is set OK')73 ssh.close()74 self._clean_up()75 return "PASS"76 except Exception as e:77 print('User root is set FAIL')78 self._clean_up()79 return "FAIL"80class TestCaseValidateDiskExtend(object):81 def __init__(self, image, size):82 self.image = image83 self.size = size84 def _prepare(self):85 # Generate tmp dir86 ran_str = ''.join(random.sample(string.ascii_letters, 8))87 tmp_path = TEST_DIR + ran_str88 self.tmp_path = tmp_path89 os.mkdir(tmp_path)90 shutil.copy(self.image, tmp_path)91 # Create vm92 os.chdir(TEST_DIR + ran_str)93 img_file = os.path.split(sys.argv[1])[-1]94 self.dom_name = img_file95 # Resize96 os.system('qemu-img resize ' + img_file + ' +' + self.size + 'G')97 self.exp_cap_min = DEFAULT_SYSDISK_SIZE + int(self.size) - 598 self.exp_cap_max = DEFAULT_SYSDISK_SIZE + int(self.size) + 599 cmd_create = 'virt-install --name ' + self.dom_name + ' --disk path=' + img_file + \100 ',bus=virtio,cache=none --network network=default,model=virtio' \101 ' --ram 4096 --vcpus 2 --accelerate --boot hd ' \102 '--vnc --vnclisten 0.0.0.0 --noreboot --autostart --import'103 os.system(cmd_create)104 time.sleep(10)105 cmd_start = 'virsh --connect qemu:///system start ' + img_file106 os.system(cmd_start)107 time.sleep(WAIT_VM_OK_TIME)108 def _clean_up(self):109 clean_up(self.dom_name, self.tmp_path)110 def execute(self):111 self._prepare()112 # Get ip of vm113 addr = get_addr(self.dom_name)114 ssh = paramiko.SSHClient()115 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())116 try:117 ssh.connect(addr, username=DEFAULT_SSH_USER, password=DEFAULT_SSH_PASSWORD)118 stdin, stdout, stderr = ssh.exec_command('df -h')119 for line in stdout:120 if 'vda' in line and 'boot' not in line:121 act_cap = int(line.split('G')[0][-2:])122 if self.exp_cap_min < act_cap < self.exp_cap_max:123 print('Root partition grow OK')124 ssh.close()125 self._clean_up()126 return "PASS"127 print('Root partition grow FAIL')128 ssh.close()129 self._clean_up()130 return "FAIL"131 except Exception as e:132 print('Root partition grow FAIL')133 self._clean_up()134 return "FAIL"135class TeseCaseValidateDistro(object):136 def __init__(self, image):137 self.image = image138 def _prepare(self):139 # Generate tmp dir140 ran_str = ''.join(random.sample(string.ascii_letters, 8))141 tmp_path = TEST_DIR + ran_str142 self.tmp_path = tmp_path143 os.mkdir(tmp_path)144 shutil.copy(self.image, tmp_path)145 # Create vm146 os.chdir(TEST_DIR + ran_str)147 img_file = os.path.split(sys.argv[1])[-1]148 self.dom_name = img_file149 cmd_create = 'virt-install --name ' + self.dom_name + ' --disk path=' + img_file + \150 ',bus=virtio,cache=none --network network=default,model=virtio' \151 ' --ram 4096 --vcpus 2 --accelerate --boot hd ' \152 '--vnc --vnclisten 0.0.0.0 --noreboot --autostart --import'153 os.system(cmd_create)154 time.sleep(10)155 cmd_start = 'virsh --connect qemu:///system start ' + img_file156 os.system(cmd_start)157 time.sleep(WAIT_VM_OK_TIME)158 def _clean_up(self):159 clean_up(self.dom_name, self.tmp_path)160 def execute(self):161 self._prepare()162 # Get ip of vm163 addr = get_addr(self.dom_name)164 ssh = paramiko.SSHClient()165 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())166 try:167 ssh.connect(addr, username=DEFAULT_SSH_USER, password=DEFAULT_SSH_PASSWORD)168 stdin, stdout, stderr = ssh.exec_command('cat /etc/centos-release')169 if '6.5' in stdout:170 print('Distro is 6.5 OK')171 ssh.close()172 self._clean_up()173 return 'PASS'174 else:175 print('Distro is 6.5 FAIL')176 ssh.close()177 self._clean_up()178 return "FAIL"179 except Exception as e:180 print('Distro is 6.5 FAIL')181 self._clean_up()182 return "FAIL"183def main():184 if len(sys.argv) < 2 or not os.path.exists(sys.argv[1]):185 print("Please input image to be verified!")186 exit(1)187 print("=====TestCase 1: Validate ssh creds=====")188 test_ssh = TestCaseValidateSshCreds(sys.argv[1])189 if test_ssh.execute() == "FAIL":190 print('FAIL: Validate ssh creds')191 return -1192 else:193 print('OK: Validate ssh creds')194 print("=====TestCase 2: Validate disk extend=====")195 test_diskex = TestCaseValidateDiskExtend(sys.argv[1], '60')...

Full Screen

Full Screen

fasttext_issues.py

Source:fasttext_issues.py Github

copy

Full Screen

1import fasttext2import re3model = fasttext.load_model('fastlangid/models/lid.176.ftz')4def _clean_up(txt):5 txt = re.sub(r"\b\d+\b", "", txt)6 return txt7print("These examples should equal to zh, however example 3,4,5 is equal to ja")8# These examples should equal to zh, however example 3,4,5 is equal to ja9# 1.10print(model.predict(_clean_up("2K 也決定從 NVIDIA GeForce Now 平台撤出")), '== zh')11# 2.12print(model.predict(_clean_up("HTC推出VIVE Sync VR虛擬會議服務,攜中華電信完成三地VR會議")), '== zh')13# 3.14print(model.predict(_clean_up("HUAWEI真無線藍牙降噪耳機、穿戴新品齊發,HUAWEI FreeBuds 3搭配HUAWEI WATCH GT2加碼限定好禮!")), '== zh')15# 4.16print(model.predict(_clean_up("平嘢有冇好嘢?~$500真無線耳機評測 Sabbat E12 Ultra | Edifier TWS 5 | Soul ST-XX | 小米Air 2 【Price.com.hk產品比較】")), '== zh')17# 5.18print(model.predict(_clean_up("沈义人:OPPO Find X2系列缎黑等配色会逐渐补货,开售当日会加货")), '== zh')19# 6.20print(model.predict(_clean_up("iPhone 7成功刷入Android 10 蘋果控告技術擁有公司")), '== zh')21print("Cascade Fasttext model")22from fastlangid.langid import LID23model = LID()24# These examples should equal to zh, however example 3,4,5 is equal to ja25# 1.26print(model.predict(_clean_up("2K 也決定從 NVIDIA GeForce Now 平台撤出")), '== zh-hant')27# 2.28print(model.predict(_clean_up("HTC推出VIVE Sync VR虛擬會議服務,攜中華電信完成三地VR會議")), '== zh-hant')29# 3.30print(model.predict(_clean_up("HUAWEI真無線藍牙降噪耳機、穿戴新品齊發,HUAWEI FreeBuds 3搭配HUAWEI WATCH GT2加碼限定好禮!")), '== zh-hant')31# 4.32print(model.predict(_clean_up("平嘢有冇好嘢?~$500真無線耳機評測 Sabbat E12 Ultra | Edifier TWS 5 | Soul ST-XX | 小米Air 2 【Price.com.hk產品比較】")), '== zh-hant')33# 5.34print(model.predict(_clean_up("沈义人:OPPO Find X2系列缎黑等配色会逐渐补货,开售当日会加货")), '== zh-hans')35# 6....

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

...10 except IndexError:11 post_exist = False12 if post_exist:13 delete_post(post_id=request.param)14 def _clean_up():15 if not post_exist:16 delete_post(post_id=request.param)17 request.addfinalizer(_clean_up)18 return request.param19@pytest.fixture(scope='function')20def create_post(request, post_exist=None):21 response = get_all_post()22 post_id = request.param23 try:24 if response.json()[post_id]:25 post_exist = True26 except IndexError:27 post_exist = False28 if not post_exist:29 gen_create_post(post_id=request.param)30 def _clean_up():31 if post_exist:32 delete_post(post_id=request.param)33 request.addfinalizer(_clean_up)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful