How to use generate_random method in localstack

Best Python code snippet using localstack_python

randomizedmodel.py

Source:randomizedmodel.py Github

copy

Full Screen

...11 print explanationstring, "size", len(inlist)12 for x in range(len(inlist)) :13 print x, inlist[x]1415def generate_random(numitems, numhits, numrounds) :1617 assert numhits <= numitems 18 accum_precat20 = []19 accum_rhr = []20 hitlist = [1 for x in range(numhits)]21 nonhitslist = [0 for x in range(numitems-numhits)]2223 totallsit= hitlist + nonhitslist2425 for i in range(numrounds):26 random.shuffle(totallsit)27 precat20 = 028 rhr = 0.029 for y in range(numitems):30 if totallsit[y]== 1 :31 if y < 20 :32 precat20 += 133 rhr += 1.0/float(y+1)34 accum_precat20.append(precat20)35 accum_rhr.append(rhr)3637# printlist(accum_precat20, 'prec@20')38# printlist(accum_rhr, 'rhr')39 precat20_parameters = (statistics.mean(accum_precat20), statistics.stdev(accum_precat20))40 rhr_parameters = (statistics.mean(accum_rhr), statistics.stdev(accum_rhr))41 42 print 'prec@20: ', precat20_parameters, 'rhr: ', rhr_parameters 4344 return (precat20_parameters, rhr_parameters)4546########################################################47# testing4849#numitems = 10050#numhits = 2051##generate_random(numitems, numhits, 10)52##generate_random(numitems, numhits, 100)53##generate_random(numitems, numhits, 1000)54##generate_random(numitems, numhits, 10000)55##generate_random(numitems, numhits, 100000)56##prec@20 3.8 1.5491933384857##rhr 1.1567029922 0.55610807203958##prec@20 3.77 1.5364592642559##rhr 0.996366478522 0.45407668868560##prec@20 3.964 1.6003953465561##rhr 1.03744185854 0.47237904987462##prec@20 4.0033 1.6010451100963##rhr 1.04068589783 0.46734950464664##prec@20 4.00532 1.6102911624865##rhr 1.03903958702 0.4703193141236667# covid19 (trials data)6869##############################################################70# case DM fda only on trial hits..7172##numitems = 34273##numhits = 6174##generate_random(numitems, numhits, 10)75##generate_random(numitems, numhits, 100)76##generate_random(numitems, numhits, 1000)77##generate_random(numitems, numhits, 10000)78##generate_random(numitems, numhits, 100000)79##prec@20 3.3 1.3374935098580##rhr 1.00187548487 0.25035312912681##prec@20 3.34 1.4989558655582##rhr 1.07260588909 0.42239871039483##prec@20 3.525 1.6852938067984##rhr 1.12785544564 0.47664438029385##prec@20 3.559 1.6667323719486##rhr 1.14043660017 0.47225682495187##prec@20 3.57018 1.6573358848588##rhr 1.14528688654 0.47245910071789 909192############################################################93# case GEO fda only on trial hits. 9495##numitems = 9396##numhits = 3497##generate_random(numitems, numhits, 10)98##generate_random(numitems, numhits, 100)99##generate_random(numitems, numhits, 1000)100##generate_random(numitems, numhits, 10000)101##generate_random(numitems, numhits, 100000)102##prec@20 7.0 2.05480466766103##rhr 1.79192706601 0.64511092716104##prec@20 7.36 2.11067512776105##rhr 1.80169872725 0.614814438733106##prec@20 7.242 1.9227930552107##rhr 1.86860297075 0.555623178387108##prec@20 7.3304 1.92992442879109##rhr 1.87730335108 0.564996944796110##prec@20 7.3137 1.91783969379111##rhr 1.87087800565 0.564257362883112 113114##############################################################115# case DM on trial hits.. (no fda filter)116117##numitems = 656118##numhits = 69119##generate_random(numitems, numhits, 10)120##generate_random(numitems, numhits, 100)121##generate_random(numitems, numhits, 1000)122##generate_random(numitems, numhits, 10000)123##generate_random(numitems, numhits, 100000)124##prec@20 2.1 0.994428926012125##rhr 0.706517567467 0.313608736532126##prec@20 2.11 1.27044889863127##rhr 0.691005548692 0.3022607442128##prec@20 2.035 1.31358307712129##rhr 0.724635286223 0.357933994271130##prec@20 2.0925 1.33226170182131##rhr 0.742925556625 0.382723943814132##prec@20 2.10819 1.35072690376133##rhr 0.743608442853 0.384046274893134135136############################################################137# case GEO on trial hits. (no fda filter)138139##numitems = 132140##numhits = 37141##generate_random(numitems, numhits, 10)142##generate_random(numitems, numhits, 100)143##generate_random(numitems, numhits, 1000)144##generate_random(numitems, numhits, 10000)145##generate_random(numitems, numhits, 100000)146##prec@20 5.5 1.26929551764147##rhr 1.61511906679 0.45519217353148##prec@20 5.58 1.93416909835149##rhr 1.57391686805 0.633793678691150##prec@20 5.651 1.87902361074151##rhr 1.53937895087 0.534620787204152##prec@20 5.5994 1.8691894037153##rhr 1.53530581548 0.540766870266154##prec@20 5.6023 1.85910980657155##rhr 1.53101455976 0.536447067514156157# asthma 158159##############################################################160# case DM fda only on asthma hits..161162##numitems = 342163##numhits = 9164##generate_random(numitems, numhits, 10)165##generate_random(numitems, numhits, 100)166##generate_random(numitems, numhits, 1000)167##generate_random(numitems, numhits, 10000)168##generate_random(numitems, numhits, 100000)169##prec@20 0.3 0.48304589154170##rhr 0.11806226457 0.0794367762824171##prec@20 0.46 0.657820091459172##rhr 0.154034408115 0.171687045576173##prec@20 0.545 0.715882313993174##rhr 0.173670473466 0.205219772099175##prec@20 0.5298 0.699257360409176##rhr 0.169643649548 0.199459070663177##prec@20 0.52482 0.694657320618178##rhr 0.168725060714 0.197802656772179180##############################################################181# case GEO fda only on asthma hits..182183##numitems = 93184##numhits = 2185##generate_random(numitems, numhits, 10)186##generate_random(numitems, numhits, 100)187##generate_random(numitems, numhits, 1000)188##generate_random(numitems, numhits, 10000)189##generate_random(numitems, numhits, 100000)190##prec@20 0.6 0.516397779494191##rhr 0.0790095028624 0.037479291557192##prec@20 0.36 0.522619663935193##rhr 0.0845312666096 0.12162022832194##prec@20 0.414 0.557597448806195##rhr 0.114346616367 0.183056507602196##prec@20 0.428 0.579525310024197##rhr 0.112523990784 0.175579793498198##prec@20 0.42998 0.57770281028199##rhr 0.110351057967 0.170627142831200201202##############################################################203# case DM on asthma hits.. (no fda filter)204205##numitems = 656206##numhits = 10207##generate_random(numitems, numhits, 10)208##generate_random(numitems, numhits, 100)209##generate_random(numitems, numhits, 1000)210##generate_random(numitems, numhits, 10000)211##generate_random(numitems, numhits, 100000)212##prec@20 0.5 0.707106781187213##rhr 0.0922745327348 0.0688734756748214##prec@20 0.37 0.562372319965215##rhr 0.119496482548 0.165175291779216##prec@20 0.309 0.534607149975217##rhr 0.111392097911 0.170934647783218##prec@20 0.3102 0.545715805685219##rhr 0.109629441286 0.158338364563220##prec@20 0.30184 0.535290089349221##rhr 0.106954456732 0.151417897917222223224############################################################225# case GEO on asthma hits. (no fda filter)226227##numitems = 132228##numhits = 3229##generate_random(numitems, numhits, 10)230##generate_random(numitems, numhits, 100)231##generate_random(numitems, numhits, 1000)232##generate_random(numitems, numhits, 10000)233##generate_random(numitems, numhits, 100000)234##prec@20 0.4 0.69920589878235##rhr 0.17763354454 0.30437725775236##prec@20 0.59 0.604611904907237##rhr 0.150901642688 0.175209112145238##prec@20 0.436 0.623131039423239##rhr 0.112823909304 0.151751524472240##prec@20 0.4631 0.622155203876241##rhr 0.127512769846 0.182180222948242##prec@20 0.45519 0.614911249741243##rhr 0.124012302504 0.177268442271244245# arthritis246247#####################################################################248# case DM fda only arthritis249250##numitems = 342251##numhits = 23252##generate_random(numitems, numhits, 10)253##generate_random(numitems, numhits, 100)254##generate_random(numitems, numhits, 1000)255##generate_random(numitems, numhits, 10000)256##generate_random(numitems, numhits, 100000)257##prec@20 1.6 0.69920589878258##rhr 0.485224255835 0.314086846202259##prec@20 1.2 1.03474976236260##rhr 0.402065262786 0.279967080262261##prec@20 1.293 1.05558763978262##rhr 0.41470740302 0.295246064028263##prec@20 1.3318 1.07713730902264##rhr 0.430376301354 0.308133860634265##prec@20 1.33843 1.08454916789266##rhr 0.429644950915 0.309432954012267268#####################################################################269# case GEO fda only arthritis270271##numitems = 93272##numhits = 8273##generate_random(numitems, numhits, 10)274##generate_random(numitems, numhits, 100)275##generate_random(numitems, numhits, 1000)276##generate_random(numitems, numhits, 10000)277##generate_random(numitems, numhits, 100000)278##prec@20 1.6 0.516397779494279##rhr 0.42610509242 0.284794186757280##prec@20 1.87 1.0115993937281##rhr 0.454620640257 0.330577224107282##prec@20 1.774 1.1181118791283##rhr 0.447502965639 0.33944231556284##prec@20 1.7133 1.11500109092285##rhr 0.435826078821 0.328317812284286##prec@20 1.71593 1.11549391678287##rhr 0.438688268274 0.327282810166288289290#####################################################################291# case DM arthritis (no fda filter)292293##numitems = 656294##numhits = 25295##generate_random(numitems, numhits, 10)296##generate_random(numitems, numhits, 100)297##generate_random(numitems, numhits, 1000)298##generate_random(numitems, numhits, 10000)299##generate_random(numitems, numhits, 100000)300##prec@20 0.7 0.948683298051301##rhr 0.237353601876 0.22105525522302##prec@20 0.77 0.827006284099303##rhr 0.275375738483 0.254319570076304##prec@20 0.774 0.805961272999305##rhr 0.265240624397 0.226567540442306##prec@20 0.7676 0.843481704685307##rhr 0.27255902649 0.244569591144308##prec@20 0.76206 0.844435721128309##rhr 0.269374266876 0.240117293991310311#####################################################################312# case GEO arthritis (no fda filter)313314##numitems = 132315##numhits = 11316##generate_random(numitems, numhits, 10)317##generate_random(numitems, numhits, 100)318##generate_random(numitems, numhits, 1000)319##generate_random(numitems, numhits, 10000)320##generate_random(numitems, numhits, 100000)321##prec@20 1.6 1.17378779078322##rhr 0.404174860214 0.220273679881323##prec@20 1.66 1.19949484317324##rhr 0.481294007073 0.352708913333325##prec@20 1.686 1.14136177731326##rhr 0.463752322259 0.342853500635327##prec@20 1.6816 1.15401673101328##rhr 0.45918399323 0.333994964242329##prec@20 1.6722 1.14696133989330##rhr 0.458240846649 0.332427923241331332###############################################333# crc 334335#####################################################################336# case DM fda only crc337338##numitems = 342339##numhits = 9340##generate_random(numitems, numhits, 10)341##generate_random(numitems, numhits, 100)342##generate_random(numitems, numhits, 1000)343##generate_random(numitems, numhits, 10000)344##generate_random(numitems, numhits, 100000)345##prec@20 0.6 0.843274042712346##rhr 0.140679782145 0.112610555519347##prec@20 0.49 0.717670192394348##rhr 0.182247126585 0.227071448567349##prec@20 0.561 0.711888885842350##rhr 0.17184947717 0.206225775059351##prec@20 0.5226 0.698095963172352##rhr 0.167088534796 0.196050754021353##prec@20 0.52502 0.693670535188354##rhr 0.169110445712 0.199603661942355356357#####################################################################358# case GEO fda only crc359360##numitems = 93361##numhits = 8362##generate_random(numitems, numhits, 10)363##generate_random(numitems, numhits, 100)364##generate_random(numitems, numhits, 1000)365##generate_random(numitems, numhits, 10000)366##generate_random(numitems, numhits, 100000)367##prec@20 1.2 0.918936583473368##rhr 0.356858824307 0.320774000312369##prec@20 1.67 1.05461946797370##rhr 0.441767838998 0.319029871337371##prec@20 1.708 1.11623563013372##rhr 0.451550411606 0.3343683795373##prec@20 1.7346 1.1190567764374##rhr 0.444057613519 0.331956184116375##prec@20 1.72191 1.11899440275376##rhr 0.439699967869 0.327125966597377378#####################################################################379# case DM crc (no fda filter)380381##numitems = 656382##numhits = 11383##generate_random(numitems, numhits, 10)384##generate_random(numitems, numhits, 100)385##generate_random(numitems, numhits, 1000)386##generate_random(numitems, numhits, 10000)387##generate_random(numitems, numhits, 100000)388##prec@20 0.2 0.421637021356389##rhr 0.0711351970602 0.0326635969053390##prec@20 0.45 0.672324476737391##rhr 0.148002722625 0.197879104019392##prec@20 0.321 0.544293354043393##rhr 0.118119106469 0.166552635579394##prec@20 0.3373 0.56529697157395##rhr 0.117078690637 0.15460654274396##prec@20 0.33447 0.565970867033397##rhr 0.11854994899 0.161313115955398399#####################################################################400# case GEO crc (no fda filter)401402##numitems = 132403##numhits = 12404##generate_random(numitems, numhits, 10)405##generate_random(numitems, numhits, 100)406##generate_random(numitems, numhits, 1000)407##generate_random(numitems, numhits, 10000)408##generate_random(numitems, numhits, 100000)409##prec@20 1.9 0.994428926012410##rhr 0.443392186929 0.145277471728411##prec@20 1.83 1.20650593271412##rhr 0.502406062424 0.348561679095413##prec@20 1.824 1.18085495232414##rhr 0.48207117677 0.319371002086415##prec@20 1.8319 1.20224245836416##rhr 0.500373122108 0.346726349304417##prec@20 1.81455 1.18442911406418##rhr 0.495042925474 0.34140177612419##420421422#####################################################################423#prc424425#####################################################################426# case DM fda only prc427428##numitems = 342429##numhits = 10430##generate_random(numitems, numhits, 10)431##generate_random(numitems, numhits, 100)432##generate_random(numitems, numhits, 1000)433##generate_random(numitems, numhits, 10000)434##generate_random(numitems, numhits, 100000)435##prec@20 0.5 0.971825315808436##rhr 0.164113510796 0.183304147806437##prec@20 0.6 0.724743075339438##rhr 0.155991010603 0.134185743856439##prec@20 0.602 0.739014304423440##rhr 0.186090234777 0.20247038507441##prec@20 0.5887 0.736197329967442##rhr 0.187440853418 0.20594940048443##prec@20 0.58572 0.732255039979444##rhr 0.186890171482 0.206456885716445446#####################################################################447# case GEO fda only prc448449450##numitems = 93451##numhits = 8452##generate_random(numitems, numhits, 10)453##generate_random(numitems, numhits, 100)454##generate_random(numitems, numhits, 1000)455##generate_random(numitems, numhits, 10000)456##generate_random(numitems, numhits, 100000)457##prec@20 2.0 1.05409255339458##rhr 0.35954660121 0.177622437623459##prec@20 1.71 1.10366698242460##rhr 0.440976540855 0.324429648593461##prec@20 1.747 1.10100100055462##rhr 0.442730095489 0.32060759937463##prec@20 1.7249 1.11074000753464##rhr 0.436884682992 0.322837320927465##prec@20 1.70977 1.11533357646466##rhr 0.438704176274 0.327820488953467468469470471#####################################################################472# case DM prc (no fda filter)473474##numitems = 656475##numhits = 15476##generate_random(numitems, numhits, 10)477##generate_random(numitems, numhits, 100)478##generate_random(numitems, numhits, 1000)479##generate_random(numitems, numhits, 10000)480##generate_random(numitems, numhits, 100000)481##prec@20 0.5 0.527046276695482##rhr 0.169632037374 0.166618320561483##prec@20 0.47 0.658357306813484##rhr 0.179111511745 0.21790514358485##prec@20 0.472 0.644694991164486##rhr 0.17503578274 0.212836275406487##prec@20 0.4561 0.655069234181488##rhr 0.159512269555 0.182828937832489##prec@20 0.45579 0.657852417794490##rhr 0.16072074913 0.186156188972491492#####################################################################493# case GEO prc (no fda filter)494495##numitems = 132496##numhits = 12497##generate_random(numitems, numhits, 10)498##generate_random(numitems, numhits, 100)499##generate_random(numitems, numhits, 1000)500##generate_random(numitems, numhits, 10000)501##generate_random(numitems, numhits, 100000)502##prec@20 2.2 1.39841179756503##rhr 0.580363372361 0.38682928086504##prec@20 1.77 1.1534314199505##rhr 0.51963710874 0.345550643595506##prec@20 1.721 1.19941552333507##rhr 0.491687795277 0.350101917053508##prec@20 1.8162 1.19019293223509##rhr 0.494996613778 0.340998378515510##prec@20 1.82026 1.18898598363511##rhr 0.4962109877 0.342314627115512513514515###############################################################516# cmap runs517518# covid19 no fda filter519520##numitems = 1290521##numhits = 77522##generate_random(numitems, numhits, 10)523##generate_random(numitems, numhits, 100)524##generate_random(numitems, numhits, 1000)525##generate_random(numitems, numhits, 10000)526##generate_random(numitems, numhits, 100000)527##prec@20 1.5 0.971825315808528##rhr 0.448930605319 0.278954555121529##prec@20 1.06 1.10846148724530##rhr 0.418528418175 0.249269040627531##prec@20 1.221 1.08042876967532##rhr 0.479800480111 0.320610091092533##prec@20 1.1912 1.04821392628534##rhr 0.459846975817 0.300371832386535##prec@20 1.18894 1.04938681549536##rhr 0.462224311689 0.299978171515537##538539540# asthma no fda filter541542##numitems = 1290543##numhits = 19544##generate_random(numitems, numhits, 10)545##generate_random(numitems, numhits, 100)546##generate_random(numitems, numhits, 1000)547##generate_random(numitems, numhits, 10000)548##generate_random(numitems, numhits, 100000)549##prec@20 0.3 0.48304589154550##rhr 0.0845230315895 0.0350920862742551##prec@20 0.27 0.54781475893552##rhr 0.123674759481 0.183241917768553##prec@20 0.295 0.527497159474554##rhr 0.114581531191 0.153456465072555##prec@20 0.2945 0.538886620616556##rhr 0.115083579574 0.156052766574557##prec@20 0.29303 0.532114884741558##rhr 0.113896651501 0.151632856172559##560561# arthritis no fda filter562563##numitems = 1290564##numhits = 30565##generate_random(numitems, numhits, 10)566##generate_random(numitems, numhits, 100)567##generate_random(numitems, numhits, 1000)568##generate_random(numitems, numhits, 10000)569##generate_random(numitems, numhits, 100000)570##prec@20 0.3 0.48304589154571##rhr 0.127779102647 0.0948710476908572##prec@20 0.56 0.715202874376573##rhr 0.190841822465 0.204995926267574##prec@20 0.472 0.698357862205575##rhr 0.178752070557 0.186791201669576##prec@20 0.4777 0.685090975685577##rhr 0.18257380026 0.195226016646578##prec@20 0.46466 0.667229747805579##rhr 0.180111122099 0.190827428537580581# crc no fda filter582583##numitems = 1290584##numhits = 10585##generate_random(numitems, numhits, 10)586##generate_random(numitems, numhits, 100)587##generate_random(numitems, numhits, 1000)588##generate_random(numitems, numhits, 10000)589##generate_random(numitems, numhits, 100000)590##prec@20 0.1 0.316227766017591##rhr 0.128858529761 0.323258633695592##prec@20 0.11 0.314466037735593##rhr 0.0601627605322 0.118935834851594##prec@20 0.156 0.397267947136595##rhr 0.0566991400944 0.0861991537087596##prec@20 0.1595 0.396075040294597##rhr 0.0613305666875 0.114821934549598##prec@20 0.15494 0.388014306374599##rhr 0.0601391313419 0.11145779052600601# prc no fda filter602603##numitems = 1290604##numhits = 21605##generate_random(numitems, numhits, 10)606##generate_random(numitems, numhits, 100)607##generate_random(numitems, numhits, 1000)608##generate_random(numitems, numhits, 10000)609##generate_random(numitems, numhits, 100000)610##prec@20 0.8 0.918936583473611##rhr 0.171197244519 0.12839309911612##prec@20 0.35 0.57515917867613##rhr 0.109810334209 0.0825510833334614##prec@20 0.327 0.5571188216615##rhr 0.128456361866 0.168489784494616##prec@20 0.3305 0.566128784094617##rhr 0.128837205732 0.167193659123618##prec@20 0.32731 0.564908271415619##rhr 0.126152459045 0.160190347449620621622####################################################623# cmp runs with filter624# covid19625626##print "*********************************"627##628##numitems = 429629##numhits = 64630##generate_random(numitems, numhits, 10)631##generate_random(numitems, numhits, 100)632##generate_random(numitems, numhits, 1000)633##generate_random(numitems, numhits, 10000)634##generate_random(numitems, numhits, 100000)635##636###asthma637##print "*********************************"638##numitems = 429639##numhits = 9640##generate_random(numitems, numhits, 10)641##generate_random(numitems, numhits, 100)642##generate_random(numitems, numhits, 1000)643##generate_random(numitems, numhits, 10000)644##generate_random(numitems, numhits, 100000)645##646###arthritis647##print "*********************************"648##numitems = 429649##numhits = 26650##generate_random(numitems, numhits, 10)651##generate_random(numitems, numhits, 100)652##generate_random(numitems, numhits, 1000)653##generate_random(numitems, numhits, 10000)654##generate_random(numitems, numhits, 100000)655##656##657###crc658##print "*********************************"659##numitems = 429660##numhits = 7661##generate_random(numitems, numhits, 10)662##generate_random(numitems, numhits, 100)663##generate_random(numitems, numhits, 1000)664##generate_random(numitems, numhits, 10000)665##generate_random(numitems, numhits, 100000)666##667##668###prc669##print "*********************************"670##numitems = 429671##numhits = 16672##generate_random(numitems, numhits, 10)673##generate_random(numitems, numhits, 100)674##generate_random(numitems, numhits, 1000)675##generate_random(numitems, numhits, 10000)676##generate_random(numitems, numhits, 100000) ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...4from fastapi import FastAPI, HTTPException5from pydantic import BaseSettings6class Settings(BaseSettings):7 GENERATOR_TABLES_LOC = os.path.join(os.getcwd(), "lazy_dm_api", "data", "tables.json")8def generate_random(base: str, subtype: str):9 return GENERATORS[base][subtype][randint(0, len(GENERATORS[base][subtype]) - 1)]10__version__ = "1.3"11app = FastAPI()12s = Settings()13with open(s.GENERATOR_TABLES_LOC, "r") as f:14 GENERATORS = loads(f.read())15@app.get("/")16async def root():17 return {"message": f"Please see /docs for valid endpoints to use. Lazy DM API {__version__}"}18@app.get("/v1/names")19async def get_names():20 return {21 "given": generate_random("names", "given"),22 "surname": generate_random("names", "surname"),23 }24@app.get("/v1/names/{kind}")25async def get_name(kind: str):26 types = ("given", "surname")27 if kind in types:28 return {kind: generate_random("names", kind)}29 else:30 raise HTTPException(status_code=404, detail=f"Name type not found. Valid types are {', '.join(types)}.")31@app.get("/v1/traps")32async def get_traps():33 return {34 "type": generate_random("traps", "type"),35 "flavor": generate_random("traps", "flavor"),36 "trigger": generate_random("traps", "trigger"),37 }38@app.get("/v1/traps/{kind}")39async def get_trap(kind: str):40 types = ("type", "flavor", "trigger")41 if kind in types:42 return {kind: generate_random("traps", kind)}43 else:44 raise HTTPException(status_code=404, detail=f"Trap type not found. Valid types are {', '.join(types)}.")45@app.get("/v1/monuments")46async def get_monuments():47 return {48 "condition": generate_random("monuments", "condition"),49 "origin": generate_random("monuments", "origin"),50 "type": generate_random("monuments", "type"),51 "effect": generate_random("monuments", "effect"),52 }53@app.get("/v1/monuments/{kind}")54async def get_monument(kind: str):55 types = ("condition", "origin", "type", "effect")56 if kind in types:57 return {kind: generate_random("monuments", kind)}58 else:59 raise HTTPException(status_code=404, detail=f"Monument type not found. Valid types are {', '.join(types)}.")60@app.get("/v1/events")61async def get_events():62 return {63 "mundane": generate_random("events", "mundane"),64 "weather": generate_random("events", "weather"),65 "sentiment": generate_random("events", "sentiment"),66 "fantastic": generate_random("events", "fantastic"),67 }68@app.get("/v1/events/{kind}")69async def get_event(kind: str):70 types = ("mundane", "weather", "sentiment", "fantastic")71 if kind in types:72 return {kind: generate_random("events", kind)}73 else:74 raise HTTPException(status_code=404, detail=f"Event type not found. Valid types are {', '.join(types)}.")75@app.get("/v1/items")76async def get_items():77 return {78 "origin": generate_random("items", "origin"),79 "condition": generate_random("items", "condition"),80 "weapon": generate_random("items", "weapon"),81 "armor": generate_random("items", "armor"),82 "healing": generate_random("items", "healing"),83 "mundane": generate_random("items", "mundane"),84 "spellEffect": generate_random("items", "spellEffect"),85 }86@app.get("/v1/items/{kind}")87async def get_item(kind: str):88 types = ("origin", "condition", "weapon", "armor", "healing", "mundane", "spellEffect")89 if kind in types:90 return {kind: generate_random("items", kind)}91 else:...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...8 raise ImportError("The function 'generate_random' should exist on app.py")9@pytest.mark.it("The function 'generate_random' should return random number between 0 and 9")10def test_for_return():11 from app import generate_random12 result = generate_random()13 assert result is not None14 for x in range(0,100):15 result = generate_random()16 assert result <= 9 and result >= 0 17@pytest.mark.it("The function should also print the random number between 0 and 9")18def test_for_file_output(capsys):19 from app import generate_random20 result = generate_random()21 captured = capsys.readouterr()...

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 localstack 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