Best Python code snippet using pytest-benchmark
tester.py
Source:tester.py
...140 msg.append('\n{}/{} test cases successful'141 .format(successful, len(outcomes)))142 msg.append('***************')143 return '\n'.join(msg)144def make_arguments(format, output,145 pointers=None, pointer_type='glob', mode='document',146 **kwargs):147 """Generates argument string to call the pipeline with"""148 args = dict(149 pointer_type=pointer_type,150 mode=mode,151 format=format,152 output=output,153 input=join(TESTFILES, format),154 termlist=TERMLIST,155 cache=CACHE.name,156 miscellaneous='',157 )158 args.update(kwargs)159 arguments = """160 -t {pointer_type}161 -m {mode}162 -f {format}163 -i {input}164 -o {output}165 -c termlist1_path {termlist}166 -c termlist_cache {cache}167 -c termlist_skip_header true168 -e {export}169 {miscellaneous}170 """.format(**args)171 if pointers is None and pointer_type == 'glob':172 pointers = '*'173 if pointers:174 arguments += '-- ' + pointers175 return arguments176def run_with_arguments(arguments_string):177 argument_list = shlex.split(arguments_string.strip())178 arguments = parameters.parse_cmdline(argument_list)179 run(**arguments)180def outdir(outputdir, *args):181 'Create an output directory name with datetime and test-case name.'182 # Get the name of the calling function.183 testcase = sys._getframe(1).f_code.co_name184 subcase = '_'.join((testcase,) + args)185 return join(outputdir, subcase)186##########################187# ACTUAL TESTING FUNCTIONS188##########################189def txt_directory(outputdir):190 for output_format in OUTPUT_FORMATS:191 testlogger.info('-> %s', output_format)192 output = join(outdir(outputdir), output_format)193 arguments = make_arguments(format='txt',194 output=output,195 export=output_format,196 pointers='*.txt')197 run_with_arguments(arguments)198 # It doesn't crash when there's an empty file,199 # or a file in a different format200 # but it crashes if the encoding is messed up201 # (this is why I added *.txt for testing)202def txt_id(outputdir):203 pointers = join(IDFILES, 'txt_ids.txt')204 for output_format in OUTPUT_FORMATS:205 testlogger.info('-> %s', output_format)206 output = join(outdir(outputdir), output_format)207 arguments = make_arguments(pointer_type='id',208 format='txt',209 output=output,210 export=output_format,211 pointers=pointers,212 miscellaneous='-b pubmed')213 run_with_arguments(arguments)214def txt_collection(outputdir):215 for output_format in OUTPUT_FORMATS:216 testlogger.info('-> %s', output_format)217 output = join(outdir(outputdir), output_format)218 arguments = make_arguments(format='txt',219 output=output,220 mode='collection',221 export=output_format,222 pointers='*.txt')223 run_with_arguments(arguments)224 # TODO output is just called 'None'225 # Is there a way to make that nicer?226def txt_json(outputdir):227 _multiple_outfmts(outdir(outputdir), 'txt_json')228def pubtator(outputdir):229 _multiple_outfmts(outdir(outputdir), 'pubtator')230def pubtator_fbk(outputdir):231 _multiple_outfmts(outdir(outputdir), 'pubtator_fbk')232def pxmlgz(outputdir):233 _multiple_outfmts(outdir(outputdir), 'pxml.gz')234def pxml_directory(outputdir):235 _multiple_outfmts(outdir(outputdir), 'pxml')236def _multiple_outfmts(outputdir, fmt):237 for mode in ['collection', 'document']:238 export = ' '.join(OUTPUT_FORMATS)239 testlogger.info('-> %s (%s mode)', export, mode)240 output = '_'.join((outputdir, mode))241 misc = '-c fn-format-out {fmt}/{id}.{ext}'242 arguments = make_arguments(format=fmt,243 output=output,244 mode=mode,245 export=export,246 miscellaneous=misc)247 run_with_arguments(arguments)248def pxml_id(outputdir):249 testlogger.info('-> tsv (ID pointers)')250 pointers = join(IDFILES, 'pxml_pmids.txt')251 arguments = make_arguments(format='pxml',252 output=outdir(outputdir, 'pmid'),253 pointers=pointers,254 pointer_type='id',255 export='tsv')256 run_with_arguments(arguments)257 # missing ids are downloaded258 testlogger.info('-> tsv (ID pointers, pubmed fallback)')259 pointers = join(IDFILES, 'pxml_pmids_dl.txt')260 arguments = make_arguments(format='pxml',261 output=outdir(outputdir, 'pmid', 'dl'),262 pointers=pointers,263 pointer_type='id',264 export='tsv',265 miscellaneous='-b pubmed')266 run_with_arguments(arguments)267def bioc_xml(outputdir):268 output = join(outputdir, 'bioc_xml')269 arguments = make_arguments(format='bioc_xml',270 output=output,271 export='xml')272 run_with_arguments(arguments)273def bioc_json(outputdir):274 output = join(outputdir, 'bioc_json')275 arguments = make_arguments(format='bioc_json',276 output=output,277 export='pubtator')278 run_with_arguments(arguments)279def download_pubmed(outputdir):280 pointers = join(IDFILES, 'pubmed_pmids.txt')281 output = join(outputdir, 'pubmed')282 arguments = make_arguments(format='pubmed',283 output=output,284 pointers=pointers,285 pointer_type='id',286 export='odin')287 run_with_arguments(arguments)288def download_pmc(outputdir):289 # running with a PMCID we know works290 good_pmcids = join(IDFILES, 'good_pmcids.txt')291 output = join(outputdir, 'pmc')292 arguments = make_arguments(format='pmc',293 output=output,294 pointers=good_pmcids,295 pointer_type='id',296 export='xml')297 run_with_arguments(arguments)298def download_bad_pmc(outputdir):299 # some PMC articles do not allow DLing the whole article300 bad_pmcids = join(IDFILES, 'bad_pmcids.txt')301 output = join(outputdir, 'pmc')302 arguments = make_arguments(format='pmc',303 output=output,304 pointers=bad_pmcids,305 pointer_type='id',306 export='xml')307 run_with_arguments(arguments)308def download_fictious_pmc(outputdir):309 # running with PMCIDs that don't exist310 # raises a ValueError with a list of missed IDs.311 fictious_pmcids = join(IDFILES, 'fictious_pmcids.txt')312 output = join(outputdir, 'pmc')313 arguments = make_arguments(format='pmc',314 output=output,315 pointers=fictious_pmcids,316 pointer_type='id',317 export='xml')318 with open(fictious_pmcids) as f:319 ids = [i.strip() for i in f]320 try:321 run_with_arguments(arguments)322 except ValueError as e:323 if getattr(e, 'ids', None) != ids:324 raise325def download_random_pmc(outputdir):326 # generate random list of pmcids to be dowloaded327 # to make testing deterministic, this is commented328 # import random329 random_pmcids = join(IDFILES, 'random_pmcids.txt')330 # with open(random_pmcids, 'w+') as f:331 # for r in random.sample(range(1, 5000000), 100):332 # f.write(str(r) + "\n")333 output = join(outputdir, 'pmc')334 misc = '-c ignore-load-errors true'335 arguments = make_arguments(format='pmc',336 output=output,337 pointers=random_pmcids,338 pointer_type='id',339 export='xml',340 miscellaneous=misc)...
make.py
Source:make.py
1"""Extension providing the :ref:`command-zebra_make` command."""2import logging3from zaf.commands.command import CommandId4from zaf.component.decorator import requires5from zaf.config.options import ConfigOption, ConfigOptionId6from zaf.extensions.extension import AbstractExtension, FrameworkExtension7from zaf.messages.message import EndpointId, MessageId8from zebra.docker import docker9logger = logging.getLogger(__name__)10logger.addHandler(logging.NullHandler())11@requires(docker_run='DockerRun')12def make(application, docker_run):13 """14 Run make inside the container.15 The MAKE_ARGUMENTS variable will be forwarded to the make command.16 Example::17 \b18 zebra make -j8 <target>19 MAKE_ARGUMENTS='-j8' make <target>20 """21 make_arguments = application.config.get(MAKE_ARGUMENTS)22 make_command = docker.IMAGES[docker_run.docker_config.image].config.make_command23 application.messagebus.trigger_event(PRE_MAKE, MAKE_ENDPOINT, data=make_arguments)24 command_with_arguments = [make_command]25 command_with_arguments.extend(make_arguments)26 return docker_run.run_in_docker(command_with_arguments, forward_signals=False)27MAKE_ARGUMENTS = ConfigOptionId(28 'arguments',29 'The arguments to make.',30 multiple=True,31 namespace='make',32 argument=True,33)34MAKE_COMMAND = CommandId(35 'make',36 make.__doc__,37 make,38 config_options=[39 ConfigOption(MAKE_ARGUMENTS, required=True),40 ],41 allow_unknown_options=True,42)43MAKE_ENDPOINT = EndpointId('MAKE_ENDPOINT', 'Endpoint for the make command')44PRE_MAKE = MessageId('PRE_MAKE', 'Event triggered before make is executed.')45@FrameworkExtension(46 'makecommand', commands=[MAKE_COMMAND], endpoints_and_messages={47 MAKE_ENDPOINT: [PRE_MAKE]48 })49class MakeExtension(AbstractExtension):...
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!!