How to use parse_string_output method in locust

Best Python code snippet using locust

DG4000.py

Source:DG4000.py Github

copy

Full Screen

...16 if (s[0] == s[-1]) and s.startswith(("'", '"')):17 s = s[1:-1]18 s = s.lower()19 return s20def parse_string_output(s):21 """ Parse an output of the VISA instrument into either text of a number """22 s = clean_string(s)23 # prevent float() from parsing 'infinity' into a float24 if s == 'infinity':25 return s26 # If it is a number; parse it27 if is_number(s):28 return float(s)29 return s30def parse_single_output(i, s):31 """ Used as a partial function to parse output i in string s """32 parts = clean_string(s).split(',')33 return parse_string_output(parts[i])34def parse_multiple_outputs(s):35 """ Parse an output such as 'sin,1.5,0,2' and return a parsed array """36 parts = clean_string(s).split(',')37 return [parse_string_output(part) for part in parts]38class Rigol_DG4000(VisaInstrument):39 """40 Driver for the Rigol DG4000 series arbitrary waveform generator.41 This driver works for all four models (DG4202, DG4162, DG4102, DG4062).42 """43 def __init__(self, name, address, reset=False, **kwargs):44 super().__init__(name, address, terminator='\n', **kwargs)45 model = self.get_idn()['model']46 models = ['DG4202', 'DG4162', 'DG4102', 'DG4062']47 if model in models:48 i = models.index(model)49 sine_freq = [200e6, 160e6, 100e6, 60e6][i]50 square_freq = [60e6, 50e6, 40e6, 25e6][i]51 ramp_freq = [5e6, 4e6, 3e6, 1e6][i]...

Full Screen

Full Screen

run.py

Source:run.py Github

copy

Full Screen

1#!/usr/bin/env python32import argparse3import os4import subprocess5import json6import glob7import shlex8import shutil9import contextlib10import sys11LITYC = './lityc'12EVM = './evm'13GENERATE_STRING_INPUT = 'scripts/generate_string_input.py'14PARSE_STRING_OUTPUT = 'scripts/parse_string_output.py'15ENI_LIBRARY_PATH = os.path.abspath('libeni/build/examples/eni')16ENI_LD_LIBRARY_PATH = os.path.abspath('libeni/build')17LD_LIBRARY_PATH = '{}:{}'.format(18 os.environ['LD_LIBRARY_PATH'], ENI_LD_LIBRARY_PATH19) if 'LD_LIBRARY_PATH' in os.environ else ENI_LD_LIBRARY_PATH20def check_call(cmd, **kw):21 print(end='\033[4m', file=sys.stderr)22 print(*map(shlex.quote, cmd), end='\033[0m\n', file=sys.stderr)23 return subprocess.check_call(cmd, **kw)24def run(litysource, inputfile):25 environ = {26 **os.environ,27 'ENI_LIBRARY_PATH': ENI_LIBRARY_PATH,28 'LD_LIBRARY_PATH': LD_LIBRARY_PATH,29 }30 with contextlib.suppress(FileNotFoundError):31 shutil.rmtree('tempdir')32 os.mkdir('tempdir')33 check_call([LITYC, '--bin-runtime', litysource, '--abi', '-o', 'tempdir'])34 with open('tempdir/inputfile', 'wb') as f:35 check_call([GENERATE_STRING_INPUT, inputfile], stdout=f)36 valid_contracts = []37 for contractfile in glob.iglob('tempdir/*.abi'):38 with open(contractfile) as f:39 contract = json.load(f)40 if contract:41 valid_contracts.append(42 os.path.splitext(contractfile)[0] + '.bin-runtime')43 assert len(44 valid_contracts45 ) == 1, 'require exact 1 valid contracts, instead, got {valid_contracts}'.format(valid_contracts=valid_contracts)46 with open('tempdir/outputfile', 'wb') as f:47 check_call([48 EVM, '--codefile', valid_contracts[0], '--inputfile',49 'tempdir/inputfile', '--statdump', '--gas', '1152921504606846975',50 'run'51 ],52 stdout=f,53 env=environ)54 check_call([PARSE_STRING_OUTPUT])55def main():56 parser = argparse.ArgumentParser()57 parser.add_argument('litysource')58 parser.add_argument('inputfile')59 args = parser.parse_args()60 run(**vars(args))61if __name__ == '__main__':...

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