Best Python code snippet using avocado_python
fasttext_classify.py
Source:fasttext_classify.py
1# -*- coding: utf-8 -*-2"""3å¤çåå§æ°æ®ï¼çæè®ç»æ°æ®é4@author: bruce5"""6import os,re7import time8import fastText.FastText as ff9from read_write_tool import read_file10 11#è®ç»å类模å12def fastText_classifier(train_data,test_data,model_save_path,result_save_path):13 files = []14 results = []15 if not os.path.exists(train_data):16 os.makedirs(train_data)17 if not os.path.exists(model_save_path):18 os.makedirs(model_save_path)19 if not os.path.exists(result_save_path):20 os.makedirs(result_save_path)2122 for level_one,test_l1 in zip(os.listdir(train_data),os.listdir(test_data)):23 print(level_one+'-->'+test_l1)2425 if '.txt' in level_one and '.txt' in test_l1:26 classifier=ff.train_supervised(train_data+level_one,ãlr=0.1,loss='hs',wordNgrams=2,epoch=100)27 #classifier = load_model.load_model(model_save_path+'train_level_1_classifier.model','nt')28 model = classifier.save_model(model_save_path+level_one+'_classifier.model') # ä¿å模å29 classifier.get_labels() # è¾åºæ ç¾30 result = classifier.test(test_data+test_l1)31 files.append(level_one)32 results.append(result)33 print(result)34 else:35 data_list = os.listdir(train_data+level_one+'/')36 test_list = os.listdir(test_data+test_l1+'/')37 if not len(data_list) or not len(test_data):38 continue39 classifier=ff.train_supervised(train_data+level_one+'/'+data_list[0],lr=0.1,loss='hs',wordNgrams=2,epoch=50)40 #classifier = load_model.load_model(model_save_path+'train_level_1_classifier.model','nt')41 model = classifier.save_model(model_save_path+level_one+'_classifier.model') # ä¿å模å42 classifier.get_labels() # è¾åºæ ç¾43 result = classifier.test(test_data+test_l1+'/'+test_list[0])44 files.append(data_list[0])45 results.append(result)46 print(result)47 print(files)48 print(results)4950 with open(result_save_path+'train_results.txt','w') as fp:51 for i,j in zip(files,results):52 fp.write(str(i)+'-->'+str(j))53 fp.write('\n')54 '''55 #linuxç³»ç»56 classifier=fasttext.supervised(train_data+'level_3_train.txt',lr=0.1,loss='hs',wordNgrams=2,epoch=100,lable_prefix='__lable__')57 model = classifier.save_model(model_save_path+'fastText_classifier.model') # ä¿å模å58 classifier.get_labels() # è¾åºæ ç¾59 result = classifier.test(train_data+'level_3_train.txt')60 print(result) 61 # print("P@1:",result.precision) #åç¡®ç62 # print("R@2:",result.recall) #å¬åç63 # print("Number of examples:",result.nexamples) #é¢æµéçä¾å64 '''65if __name__ == '__main__':66 train_path = '../datas/data_set/train/'67 test_path = '../datas/data_set/test/'68 model_save_path = '../datas/model/paper_train/'69 result_save_path = '../datas/results/paper_train/'
...
test_multipler.py
Source:test_multipler.py
1import pytest2from sandpit_package.mathers.multiplier import Multiplier3expected_op = "*"4test_l1 = 55test_r1 = 76expected_result1 = test_l1 * test_r17expected_msg1 = "%s %s %s = %s" % (test_l1, expected_op, test_r1, expected_result1)8test_l2 = "abc"9test_r2 = 510expected_result2 = test_l2 * test_r211expected_msg2 = "%s %s %s = %s" % (test_l2, expected_op, test_r2, expected_result2)12def test_init():13 with pytest.raises(Exception):14 x1 = Multiplier()15 with pytest.raises(Exception):16 x2 = Multiplier(test_l1)17 x3 = Multiplier(test_l1, test_r1)18 assert (x3.l, x3.r) == (test_l1, test_r1)19 x4 = Multiplier(test_l2, test_r2)20 assert (x4.l, x4.r) == (test_l2, test_r2)21def test_op_str():22 x = Multiplier(test_l1, test_r1)23 assert x._op_str() == expected_op24def test_result():25 x1 = Multiplier(test_l1, test_r1)26 assert x1.result() == expected_result127 x1 = Multiplier(test_r1, test_l1)28 assert x1.result() == expected_result129 x2 = Multiplier(test_l2, test_r2)30 assert x2.result() == expected_result231 x2 = Multiplier(test_r2, test_l2)32 assert x2.result() == expected_result233def test_msg():34 x1 = Multiplier(test_l1, test_r1)35 assert x1._msg() == expected_msg136 x2 = Multiplier(test_l2, test_r2)37 assert x2._msg() == expected_msg238def test_print(capsys):39 x1 = Multiplier(test_l1, test_r1)40 x1.print()...
test_adder.py
Source:test_adder.py
1import pytest2from sandpit_package.mathers.adder import Adder3expected_op = "+"4test_l1 = 55test_r1 = 76expected_result1 = test_l1 + test_r17expected_msg1 = "%s %s %s = %s" % (test_l1, expected_op, test_r1, expected_result1)8test_l2 = "abc"9test_r2 = "def"10expected_result2 = test_l2 + test_r211expected_msg2 = "%s %s %s = %s" % (test_l2, expected_op, test_r2, expected_result2)12def test_init():13 with pytest.raises(Exception):14 x1 = Adder()15 with pytest.raises(Exception):16 x2 = Adder(test_l1)17 x3 = Adder(test_l1, test_r1)18 assert (x3.l, x3.r) == (test_l1, test_r1)19 x4 = Adder(test_l2, test_r2)20 assert (x4.l, x4.r) == (test_l2, test_r2)21def test_op_str():22 x = Adder(test_l1, test_r1)23 assert x._op_str() == expected_op24def test_result():25 x1 = Adder(test_l1, test_r1)26 assert x1.result() == expected_result127 x1 = Adder(test_r1, test_l1)28 assert x1.result() == expected_result129 x2 = Adder(test_l2, test_r2)30 assert x2.result() == expected_result231 x2 = Adder(test_r2, test_l2)32 assert x2.result() != expected_result233def test_msg():34 x1 = Adder(test_l1, test_r1)35 assert x1._msg() == expected_msg136 x2 = Adder(test_l2, test_r2)37 assert x2._msg() == expected_msg238def test_print(capsys):39 x1 = Adder(test_l1, test_r1)40 x1.print()...
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!!