How to use from_multiple method in yandex-tank

Best Python code snippet using yandex-tank

decorators_classmethod_staticmethod_examples.py

Source:decorators_classmethod_staticmethod_examples.py Github

copy

Full Screen

...11 FixedFloat.12 """13 return FixedFloat(value1 + value2)14 @staticmethod15 def from_multiple(value1, value2):16 return FixedFloat(value1 * value2) # FixedFloat formata o resultado17 @classmethod18 def from_div(cls, value1, value2):19 return cls(value1 / value2) # Substituimos FixedFloat pelo 'cls' que é20 # a classe que foi passada como argumento.21number = FixedFloat(18.5746) # Instanciamos um novo objeto do tipo FixedFloat22print(number) # mostra o retorno do método de instância '__repr__'23# Aqui criamos um objeto FixedFloat a partir do retorno do método Fixedfloat24""" Porém não é interessante fazer isso, pois precisamos criar uma instancia da25 classe(que nunca iremos utilizar, que no caso é 'number') para podermos 26 invocar o método 'from_sum'.27"""28new_number = number.from_sum(19.575, 0.789)29print(new_number)30# Para podermos utilizar o método 'from_sum' sem precisar instanciar 31# a classe, utilizamos @staticmethod como no método 'from_multiple'32# Então:33new_number2 = FixedFloat.from_multiple(2, 4)34print(new_number2)35# OUTRO EXEMPLO:36# digamos que temos uma classe Euro, que herda de FixedFloat37class Euro(FixedFloat):38 def __init__(self, amount):39 super().__init__(amount)40 self.symbol = '$'41 42 def __repr__(self):43 return f'<Euro {self.symbol}{self.amount:.2f}>'44# Agora vamos chamar o método 'from_multiple' a partir da classe 'Euro'45money = Euro.from_multiple(16.758, 9.999)46print(money) 47""" Vamos ter a seguinte mensagem: <fixedFloat 167.56> 48 é um objeto do tipo FixedFloat, isso esta errado! Queremos um objeto do 49 tipo Euro.50 Podemos resolver esse 'bug' com o decorador @classmethod(que tem a classe51 como parametro.52 Fiz isso como exemplo no método 'from_div()53"""54dinheiro = Euro.from_div(16, 2)55print(dinheiro) # <Euro $8.00>56# CONSIDERAÇÕES IMPORTANTES:57############################58""" Muitos na comunidade Python são contra os @staticmethods59 eles dizem: "@staticmethod é um @classmethod com menos funcionalidades...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1from flask import Flask,render_template,request,jsonify2import requests as req3import json4app = Flask(__name__)5def getdata():6 link = 'https://api.nbp.pl/api/exchangerates/tables/a/?format=json'7 datadict = req.get(link).json()[0]8 datanbp = datadict['rates']9 data_date = datadict['effectiveDate']10 return [datanbp,data_date]11@app.route('/')12def formdata(value="output",from_curr="",to_curr="",from_multi=""):13 data_to_form=getdata()14 data_values = data_to_form[0]15 data_date = data_to_form[1]16 return render_template('currencyexchange.html',data_to_form=data_values,data_date=data_date,value=value,17 from_curr=from_curr,to_curr=to_curr,from_multi=from_multi)18@app.route('/',methods=['POST'])19def formdatapost():20 from_currency = float(request.form.get('from_currency'))21 print(from_currency)22 to_currency = float(request.form.get('to_currency'))23 from_multiple = float(request.form.get('from_multiple'))24 datanbp=getdata()[0]25 if from_currency == 1:26 from_code=['PLN']27 else:28 from_code = [i['code'] for i in datanbp if i['mid'] == from_currency]29 if to_currency == 1:30 to_code = ['PLN']31 else:32 to_code = [i['code'] for i in datanbp if i['mid'] == to_currency]33 return formdata((from_multiple*float(from_currency))/float(to_currency),from_code[0],to_code[0],from_multiple)34if __name__ == '__main__':...

Full Screen

Full Screen

answer.py

Source:answer.py Github

copy

Full Screen

1PREFIXES = {2 "": 1,3 "K": 10 ** 3,4 "M": 10 ** 6,5 "G": 10 ** 96}7BLOBS = {8 "b": 1,9 "B": 810}11UNITS_TO_DECIMAL = {}12for prefix, decimal in PREFIXES.items():13 for blob, byte_count in BLOBS.items():14 UNITS_TO_DECIMAL[f"{prefix}{blob}/s"] = decimal * byte_count15def bitrate_convert(value: float, from_units: str, to_units: str) -> float:16 from_multiple = UNITS_TO_DECIMAL.get(from_units, 1)17 to_multiple = UNITS_TO_DECIMAL.get(to_units, 1)18 return value * from_multiple / to_multiple19def get_si_prefix(unit: str) -> int:20 if unit.startswith("G"):21 return 10 ** 922 elif unit.startswith("M"):23 return 10 ** 624 elif unit.startswith("K"):25 return 10 ** 326 return 127def get_bits_in_unit(unit: str) -> int:28 """29 Returns the number of bits (8 or 1) based upon wether the unit is expressed in b/s or B/s.30 """31 if unit.endswith("B/s"):32 return 833 return 134def bitrate_convert(value: float, from_units: str, to_units: str) -> float:35 from_multiple = get_si_prefix(from_units) * get_bits_in_unit(from_units)36 to_multiple = get_si_prefix(to_units) * get_bits_in_unit(to_units)...

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 yandex-tank 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