How to use test_fin method in pytest-django

Best Python code snippet using pytest-django_python

test_db.py

Source:test_db.py Github

copy

Full Screen

1import unittest2import xtract3from xtract import db4import xtract.model.stockdatamodel5import os6import tempfile7import pytest8# import date from datetime9TEST_TICKER = "GLUMANDA"10TEST_PERIOD = "2055-12-31"11TEST_FCF = 9.9312TEST_FD = 999.9913@pytest.fixture14def client():15 db_fd, app.config['DATABASE'] = tempfile.mkstemp()16 app.config['TESTING'] = True17 18 19 with app.test_client() as client:20 with app.app_context():21 app.init_db()22 yield client23 os.close(db_fd)24 os.unlink(app.config['DATABASE'])25class DatabaseConnectionTestCase(unittest.TestCase):26 def setUp(self):27 print("Setting up the DB")28 29 self.app, self.app_connex, self.port = xtract.create_app(os.getenv('BOILERPLATE_ENV') or 'dev')30 31 self.app.app_context().push()32 33 #self.db = db.init_db()34 self.delete_test_financial()35 def test_1_write_and_read_back_StockData(self):36 print(37 "Writing some stuff {tick} {period} {FCF}".format(38 tick=TEST_TICKER, period=TEST_PERIOD, FCF=TEST_FCF39 )40 )41 financial = xtract.model.stockdatamodel.Financial(42 ticker=TEST_TICKER, beta=TEST_FD, dividend_yield=TEST_FD,43 )44 db.session.add(financial)45 db.session.commit()46 f = xtract.model.stockdatamodel.Ratio(47 ticker=TEST_TICKER,48 period=TEST_PERIOD,49 gross_margin=34,50 operating_income=2.0,51 net_income=2000.33,52 eps=3.3,53 dividends=2.0,54 payout_ratio=9.2,55 shares=400000,56 bps=20.2,57 operating_cash_flow=4.0,58 cap_spending=3.2,59 fcf=TEST_FCF,60 working_capital=2.3,61 current_ratio=10.0,62 debt_equity=10.0,63 )64 print("Adding {0}".format(f))65 db.session.add(f)66 db.session.commit()67 # check it's there68 print("Reading it back")69 read_q = self.read_test_ratios()70 assert read_q.count() == 171 # check it is what it should be72 print("Checking Ratio it's correct")73 test_fin = read_q.first()74 assert test_fin.fcf == TEST_FCF75 read_q = self.read_test_financial()76 assert read_q.count() == 177 print("Checking Financial is correct")78 test_fin = read_q.first()79 assert test_fin.beta == TEST_FD80 # Clean up81 print("Nuking it")82 self.delete_test_financial()83 # Check it's gone84 print("Checking it's gone")85 read_q = self.read_test_financial()86 assert read_q.count() == 087 def read_test_financial(self):88 query = xtract.model.stockdatamodel.Financial.query.filter(89 xtract.model.stockdatamodel.Financial.ticker == TEST_TICKER90 )91 return query92 def read_test_ratios(self):93 query = xtract.model.stockdatamodel.Ratio.query.filter(94 xtract.model.stockdatamodel.Ratio.ticker == TEST_TICKER95 ).filter(xtract.model.stockdatamodel.Ratio.period == TEST_PERIOD)96 return query97 def delete_test_financial(self):98 print("Checking if we need to delete our test financial")99 test_ratios = self.read_test_ratios()100 test_financial = self.read_test_financial()101 # print(test_fin)102 if test_ratios.count() == 1:103 db.session.delete(test_ratios.first())104 db.session.commit()105 if test_financial.count() == 1:106 print("Deleting our test financials")107 db.session.delete(test_financial.first())108 db.session.commit()109if __name__ == "__main__":110 print("Here we go ")...

Full Screen

Full Screen

Spo2Calulation.py

Source:Spo2Calulation.py Github

copy

Full Screen

1import cv22import imutils3import numpy as np4import time5# from face_detection import FaceDetection6# from scipy import signal7import sys8from numpy.linalg import inv9# import dlib10import imutils11import time12import skin_detector13def face_detect_and_thresh(frame):14 skinM = skin_detector.process(frame)15 skin = cv2.bitwise_and(frame, frame, mask = skinM)16 # cv2.imshow("skin2",skin)17 # cv2.waitKey(1)18 return skin,skinM19def spartialAverage(thresh,frame):20 a=list(np.argwhere(thresh>0))21 # x=[i[0] for i in a]22 # y=[i[1] for i in a]23 # p=[x,y]24 if a:25 ind_img=(np.vstack((a)))26 else:27 return 0,0,028 sig_fin=np.zeros([np.shape(ind_img)[0],3])29 test_fin=[]30 for i in range(np.shape(ind_img)[0]):31 sig_temp=frame[ind_img[i,0],ind_img[i,1],:]32 sig_temp = sig_temp.reshape((1, 3))33 if sig_temp.any()!=0:34 sig_fin=np.concatenate((sig_fin,sig_temp))35 # print(sig_fin)36 for _ in sig_fin:37 if sum(_)>0:38 # test_fin=np.concatenate((test_fin,_))39 test_fin.append(_)40 # print("min=>")41 a= [item for item in sig_fin if sum(item)>0]42 # print(min(a, key=sum))43 min_value=sum(min(a, key=sum))44 max_value=sum(max(a, key=sum))45 # print(sum1)46 img_rgb_mean=np.nanmean(test_fin,axis=0)47 # print(img_rgb_mean)48 return img_rgb_mean,min_value,max_value49def MeanRGB(thresh,frame,last_stage,min_value,max_value):50 # cv2.imshow("threshh",thresh)51 # print(thresh)52 # print("==<>>")53 # print(img_rgb)54 # cv2.waitKey(1)55 # print(img_rgb[0])56 # thresh=thresh.reshape((1,3))57 # img_rgb_mean=np.nanmean(thresh,axis=0)58 a= [item for item in frame[0] if (sum(item)>min_value and sum(item)<max_value)]59 # print(a)60 # a = filter(lambda (x,y,z) : i+j+k>764 ,frame[0])61 # print(a[1:10])62 # img_temp = [item for item in img_rgb if sum(item)>764]63 # print(frame[0])64 # print(img_temp)65 # print(np.mean(a, axis=(0)))66 if a:67 # print("==>")68 # print(a)69 # print("==>")70 img_mean=np.mean(a, axis=(0))71 # print(img_mean)72 return img_mean[::-1]73 else:74 return last_stage75def preprocess(z1,z2,detrended_RGB,window_size,size_video,duration,frame):76 temp=(int(size_video/duration))77 f=frame-278 main_R=[]79 main_B=[]80 out=[]81 for i in range(len(detrended_RGB)-f+1):82 temp_R=z1[i:i+f-1]83 temp_B=z2[i:i+f-1]84 p=[list(a) for a in zip(temp_R, temp_B)]85 out.append(p)86 # if not main_R:87 # main_R.append(temp_R)88 # else:89 # main_R=[main_R,temp_R]90 #91 # if not main_B:92 # main_B.append(temp_B)93 # else:94 # main_B=[main_B,temp_B]95 # out=[main_R,main_B]96 # print(out[0])97 return out[0]98def SPooEsitmate(final_sig,video_size,frames,seconds):99 A = 100.6100 B = 4.834101 ten=10102 z1=[item[0] for item in final_sig]103 z3=[item[2] for item in final_sig]104 SPO_pre=[]105 for _ in range(len(z1)):106 SPO_pre.append([z1[_],z3[_]])107 Spo2 = preprocess(z1,z3,SPO_pre,ten,video_size,seconds,frames)108 R_temp = [item[0] for item in Spo2]109 DC_R_comp=np.mean(R_temp)110 AC_R_comp=np.std(R_temp)111 # print(DC_R_comp)112 # print(R_temp)113 # print(AC_R_comp)114 I_r=AC_R_comp/DC_R_comp115 B_temp = [item[1] for item in Spo2]116 DC_B_comp=np.mean(B_temp)117 AC_B_comp=np.std(B_temp)118 # print(I_r)119 I_b=AC_B_comp/DC_B_comp120 SpO2_value=(A-B*((I_b*650)/(I_r*950)))...

Full Screen

Full Screen

exercice5.py

Source:exercice5.py Github

copy

Full Screen

1""" @auteur : johanna2date : 10/09/20203description : atelier3 exercice 24version 15"""67#exercice 589def present(L,e):10 if e in L:11 return(True)12 else:13 return(False)1415def test_present(present:callable):16 liste_vide=[]17 liste=[2,5,8,4,6,9,456,1,3]18 test_debut=219 test_fin=320 test_milieu=621 test_pas_present=99922 msg_succes = " succès"23 msg_echec = " echec"24 e=52526 if not(present(liste_vide,e)):27 msg= msg_succes28 else:29 msg =msg_echec3031 if present(liste, test_fin):32 msg += msg_succes +" test_fin "33 else:34 msg += msg_echec + " test_fin "3536 if present(liste, test_debut):37 msg += msg_succes + " test_debut "38 else:39 msg += msg_echec + " test_debut"4041 if present(liste, test_milieu ):42 msg += msg_succes + " test_milieu "43 else:44 msg += msg_echec + " test_milieu "4546 if not present(liste,test_pas_present):47 msg += msg_succes + " test_pas_present "48 else:49 msg += msg_echec + " test_pas_present "50 return msg515253def present1 (L,e):54 for i in range(0,len(L)):55 if(L[i]==e):56 return(True)57 else:58 return(False)5960def present2(L,e):61 b= False62 for i in range(0,len(L)):63 if(L[i]==e):64 b=True65 return(b)6667def present3(L,e):68 b=False69 for i in range(0,len(L)):70 if (L[i] == e):71 b = True72 return (b)737475def present4(L,e):76 b= False77 i=078 while(i<len(L)):79 if(L[i]==e):80 b=True81 i+=182 return(b)83print(test_present(present))84print(test_present(present1))85print(test_present(present2))86print(test_present(present3))87print(test_present(present4))888990def test_pos(pos:callable):91 liste=[2,3,1,2,2,3]92 test_1 = pos(liste,1)93 test_2 = pos(liste,2)94 test_3 = pos(liste,3)95 msg_succes = "succès"96 msg_echec = " echec"97 msg=""9899 liste_1=[0,3,4]100 liste_2=[1,5]101102 print(test_1)103 print(test_2)104 print(test_3)105 if len(test_1)==1 :106 if test_1[0]==2:107 msg+=msg_succes + "test 1"108 else:109 msg+= msg_echec + "bon_numéro test 1"110 else:111 msg += msg_echec + "mauvaise taille test 1"112113 if len(test_2)==3 :114 estOk = True115 for i in range(0,len(test_2)):116 for j in range(0,len(liste_1)):117 if test_2[i]!=liste_1[i] :118 estOk = False119 if (estOk):120 msg += msg_succes + "test 2"121 else:122 msg+= msg_echec + "bon_numéro test 2"123 else:124 msg += msg_echec + "mauvaise taille test 2"125126127128129 return(msg)130131132def pos1(L,e):133 Lres= []134 for i in range(0,len(L)):135 if L[i]==e:136 Lres.append(i)137 return Lres138139def pos3(L,e):140 Lres= []141 for i in range(0,len(L),1):142 if L[i]==e:143 Lres.append(i)144 return Lres145146def pos2(L,e):147 Lres= []148 for i in range(0,len(L)):149 if(L[i]==e):150 Lres.append(i)151 return Lres152153def pos4(L,e):154 nb= L.count(e)155 Lres = [0]*nb156 j=0157 for i in range(0,len(L)):158 if(L[i]==e):159 Lres[j]=i160 j+=1161 return Lres162163print(test_pos(pos1))164print(test_pos(pos2))165print(test_pos(pos3)) ...

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 pytest-django 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