How to use pedantic method in pytest-benchmark

Best Python code snippet using pytest-benchmark

recipe.py

Source:recipe.py Github

copy

Full Screen

1import os2import re3from os.path import (4 basename,5 getsize,6 isfile,7 join,8)9import yaml10from planemo.conda_verify.const import (11 FIELDS,12 LICENSE_FAMILIES,13)14from planemo.conda_verify.utils import (15 all_ascii,16 get_bad_seq,17 memoized,18)19PEDANTIC = True20sel_pat = re.compile(r"(.+?)\s*\[(.+)\]$")21name_pat = re.compile(r"[a-z0-9_][a-z0-9_\-\.]*$")22version_pat = re.compile(r"[\w\.]+$")23url_pat = re.compile(r"(ftp|http(s)?)://")24class RecipeError(Exception):25 pass26def ns_cfg(cfg):27 plat = cfg["plat"]28 py = cfg["PY"]29 np = cfg["NPY"]30 for x in py, np:31 assert isinstance(x, int), x32 return dict(33 nomkl=False,34 debug=False,35 linux=plat.startswith("linux-"),36 linux32=bool(plat == "linux-32"),37 linux64=bool(plat == "linux-64"),38 armv7l=False,39 arm=False,40 ppc64le=False,41 osx=plat.startswith("osx-"),42 unix=plat.startswith(("linux-", "osx-")),43 win=plat.startswith("win-"),44 win32=bool(plat == "win-32"),45 win64=bool(plat == "win-64"),46 x86=plat.endswith(("-32", "-64")),47 x86_64=plat.endswith("-64"),48 py=py,49 py3k=bool(30 <= py < 40),50 py2k=bool(20 <= py < 30),51 py26=bool(py == 26),52 py27=bool(py == 27),53 py33=bool(py == 33),54 py34=bool(py == 34),55 py35=bool(py == 35),56 np=np,57 )58def select_lines(data, namespace):59 lines = []60 for line in data.splitlines():61 line = line.rstrip()62 m = sel_pat.match(line)63 if m:64 if PEDANTIC:65 x = m.group(1).strip()66 # error on comment, unless the whole line is a comment67 if "#" in x and not x.startswith("#"):68 raise RecipeError("found commented selector: %s" % line)69 cond = m.group(2)70 if eval(cond, namespace, {}):71 lines.append(m.group(1))72 continue73 lines.append(line)74 return "\n".join(lines) + "\n"75@memoized76def yamlize(data):77 res = yaml.safe_load(data)78 # ensure the result is a dict79 if res is None:80 res = {}81 return res82def parse(data, cfg):83 if cfg is not None:84 data = select_lines(data, ns_cfg(cfg))85 # ensure we create new object, because yamlize is memoized86 return dict(yamlize(data))87def get_field(meta, field, default=None):88 section, key = field.split("/")89 submeta = meta.get(section)90 if submeta is None:91 submeta = {}92 res = submeta.get(key)93 if res is None:94 res = default95 return res96def check_name(name):97 if name:98 name = str(name)99 else:100 raise RecipeError("package name missing")101 if not name_pat.match(name) or name.endswith((".", "-", "_")):102 raise RecipeError("invalid package name '%s'" % name)103 seq = get_bad_seq(name)104 if seq:105 raise RecipeError("'%s' is not allowed in " "package name: '%s'" % (seq, name))106def check_version(ver):107 if ver:108 ver = str(ver)109 else:110 raise RecipeError("package version missing")111 if not version_pat.match(ver):112 raise RecipeError("invalid version '%s'" % ver)113 if ver.startswith(("_", ".")) or ver.endswith(("_", ".")):114 raise RecipeError("version cannot start or end with '_' or '.': %s" % ver)115 seq = get_bad_seq(ver)116 if seq:117 raise RecipeError(f"'{seq}' not allowed in version '{ver}'")118def check_build_number(bn):119 if not (isinstance(bn, int) and bn >= 0):120 raise RecipeError("build/number '%s' (not a positive interger)" % bn)121def check_requirements(meta):122 for req in get_field(meta, "requirements/run", []):123 name = req.split()[0]124 if not name_pat.match(name):125 raise RecipeError("invalid run requirement name '%s'" % name)126def check_license_family(meta):127 if not PEDANTIC:128 return129 lf = get_field(meta, "about/license_family", get_field(meta, "about/license"))130 if lf not in LICENSE_FAMILIES:131 print(132 """\133Error: license_family is invalid: %s134Note that about/license_family falls back to about/license.135Allowed license families are:"""136 % lf137 )138 for x in LICENSE_FAMILIES:139 print(" - %s" % x)140 raise RecipeError("wrong license family")141def check_url(url):142 if not url_pat.match(url):143 raise RecipeError("not a valid URL: %s" % url)144def check_about(meta):145 summary = get_field(meta, "about/summary")146 if summary and len(summary) > 80:147 msg = "summary exceeds 80 characters"148 if PEDANTIC:149 raise RecipeError(msg)150 else:151 print("Warning: %s" % msg)152 for field in ("about/home", "about/dev_url", "about/doc_url", "about/license_url"):153 url = get_field(meta, field)154 if url:155 check_url(url)156 check_license_family(meta)157hash_pat = {158 "md5": re.compile(r"[a-f0-9]{32}$"),159 "sha1": re.compile(r"[a-f0-9]{40}$"),160 "sha256": re.compile(r"[a-f0-9]{64}$"),161}162def check_source(meta):163 src = meta.get("source")164 if not src:165 return166 fn = src.get("fn")167 if fn:168 for ht in "md5", "sha1", "sha256":169 hexgigest = src.get(ht)170 if hexgigest and not hash_pat[ht].match(hexgigest):171 raise RecipeError("invalid hash: %s" % hexgigest)172 url = src.get("url")173 if url:174 check_url(url)175 git_url = src.get("git_url")176 if git_url and (src.get("git_tag") and src.get("git_branch")):177 raise RecipeError("cannot specify both git_branch and git_tag")178def validate_meta(meta):179 for section in meta:180 if PEDANTIC and section not in FIELDS:181 raise RecipeError("Unknown section: %s" % section)182 submeta = meta.get(section)183 if submeta is None:184 submeta = {}185 for key in submeta:186 if PEDANTIC and key not in FIELDS[section]:187 raise RecipeError("in section %r: unknown key %r" % (section, key))188 check_name(get_field(meta, "package/name"))189 check_version(get_field(meta, "package/version"))190 check_build_number(get_field(meta, "build/number", 0))191 check_requirements(meta)192 check_about(meta)193 check_source(meta)194def validate_files(recipe_dir, meta):195 for field in "test/files", "source/patches":196 flst = get_field(meta, field)197 if not flst:198 continue199 for fn in flst:200 if PEDANTIC and fn.startswith(".."):201 raise RecipeError("path outsite recipe: %s" % fn)202 path = join(recipe_dir, fn)203 if isfile(path):204 continue205 raise RecipeError("no such file '%s'" % path)206def iter_cfgs():207 for py in 27, 34, 35:208 for plat in "linux-64", "linux-32", "osx-64", "win-32", "win-64":209 yield dict(plat=plat, PY=py, NPY=111)210def dir_size(dir_path):211 return sum(sum(getsize(join(root, fn)) for fn in files) for root, unused_dirs, files in os.walk(dir_path))212def check_dir_content(recipe_dir):213 disallowed_extensions = (214 ".tar",215 ".tar.gz",216 ".tar.bz2",217 ".tar.xz",218 ".so",219 ".dylib",220 ".la",221 ".a",222 ".dll",223 ".pyd",224 )225 for root, unused_dirs, files in os.walk(recipe_dir):226 for fn in files:227 fn_lower = fn.lower()228 if fn_lower.endswith(disallowed_extensions):229 if PEDANTIC:230 raise RecipeError("found: %s" % fn)231 else:232 print("Warning: found: %s" % fn)233 path = join(root, fn)234 # only allow small archives for testing235 if PEDANTIC and fn_lower.endswith((".bz2", ".gz")) and getsize(path) > 512:236 raise RecipeError("found: %s (too large)" % fn)237 if basename(recipe_dir) == "icu":238 return239 # check total size od recipe directory (recursively)240 kb_size = dir_size(recipe_dir) / 1024241 kb_limit = 512242 if PEDANTIC and kb_size > kb_limit:243 raise RecipeError("recipe too large: %d KB (limit %d KB)" % (kb_size, kb_limit))244 if PEDANTIC:245 try:246 with open(join(recipe_dir, "build.sh"), "rb") as fi:247 data = fi.read()248 if data and not data.decode("utf-8").startswith(("#!/bin/bash\n", "#!/bin/sh\n")):249 raise RecipeError("not a bash script: build.sh")250 except OSError:251 pass252def render_jinja2(recipe_dir):253 import jinja2254 loaders = [jinja2.FileSystemLoader(recipe_dir)]255 env = jinja2.Environment(loader=jinja2.ChoiceLoader(loaders))256 template = env.get_or_select_template("meta.yaml")257 return template.render(environment=env)258def validate_recipe(recipe_dir, pedantic=True):259 global PEDANTIC260 PEDANTIC = bool(pedantic)261 meta_path = join(recipe_dir, "meta.yaml")262 with open(meta_path, "rb") as fi:263 data = fi.read()264 if PEDANTIC and not all_ascii(data):265 raise RecipeError("non-ASCII in: %s" % meta_path)266 if b"{{" in data:267 if PEDANTIC:268 raise RecipeError("found {{ in %s (Jinja templating not allowed)" % meta_path)269 else:270 data = render_jinja2(recipe_dir)271 else:272 data = data.decode("utf-8")273 check_dir_content(recipe_dir)274 for cfg in iter_cfgs():275 meta = parse(data, cfg)276 validate_meta(meta)...

Full Screen

Full Screen

__cc__.py

Source:__cc__.py Github

copy

Full Screen

1from .cli import CLI2from .__cxx__ import CxxRunner3class CcCLI(CLI):4 def __init__(self, compiler=None):5 super(CcCLI, self).__init__('C', compiler)6 self.cxx_setup('C', compiler)7 def cxx_setup(self, lang, compiler):8 self.parser.add_argument(9 '--std',10 metavar='VERSION',11 help='set --std options'12 )13 self.parser.add_argument(14 '--no-warning',15 action='store_true',16 help='disable warning option'17 )18 self.parser.add_argument(19 '--optimize',20 action='store_true',21 help='use optimization'22 )23 self.parser.add_argument(24 '--cpp-pedantic',25 metavar='PEDANTIC',26 help='use cpp-pedantic'27 )28 self.parser.add_argument(29 '--cpp-verbose',30 action='store_true',31 help='use cpp-verbose'32 )33 def get_runner(self, args, options):34 return CxxRunner(args.language, args.compiler, args.save, args.encoding, args.retry, args.retry_wait)35 def setup_runner(self, args, enable_options, disable_options, runner):36 def filterout_cppver(opt):37 tmp = list(filter(lambda s: s.find('c') == -1, opt))38 tmp = list(filter(lambda s: s.find('gnu') == -1, tmp))39 return tmp40 self.check_bool_option(args, 'no-warning' , enable_options, disable_options)41 self.check_bool_option(args, 'cpp-verbose' , enable_options, disable_options)42 self.check_bool_option(args, 'optimize' , enable_options, disable_options)43 if args.cpp_pedantic:44 pedantic_opt = args.cpp_pedantic45 if args.cpp_pedantic == 'no':46 pedantic_opt = 'cpp-no-pedantic'47 elif args.cpp_pedantic == 'yes':48 pedantic_opt = 'cpp-pedantic'49 elif args.cpp_pedantic == 'error':50 pedantic_opt = 'cpp-pedantic-errors'51 elif args.cpp_pedantic == 'errors':52 pedantic_opt = 'cpp-pedantic-errors'53 enable_options = list(filter(lambda s: s.find('pedantic') == -1, enable_options))54 enable_options.append(pedantic_opt)55 if args.std:56 enable_options = filterout_cppver(enable_options)57 enable_options.append(args.std)58 super(CcCLI, self).setup_runner(args, list(set(enable_options)), disable_options, runner)59def cc(compiler=None):60 cli = CcCLI(compiler)61 cli.execute()62def main():63 cc()64def gcc():65 cc('gcc-*-c')66def clang():67 cc('clang-*-c')68if __name__ == '__main__':...

Full Screen

Full Screen

test_rdrand.py

Source:test_rdrand.py Github

copy

Full Screen

...52 r = rd.seed16()53 assert type(r) == int54 assert 0 < r < 2**1655def test_rand16b(benchmark):56 benchmark.pedantic(rd.rand16, args=(), rounds=RDS, iterations=ITR)57def test_rand32b(benchmark):58 benchmark.pedantic(rd.rand32, args=(), rounds=RDS, iterations=ITR)59def test_rand64b(benchmark):60 benchmark.pedantic(rd.rand64, args=(), rounds=RDS, iterations=ITR)61def test_seed16b(benchmark):62 benchmark.pedantic(rd.seed16, args=(), rounds=RDS, iterations=ITR)63def test_seed32b(benchmark):64 benchmark.pedantic(rd.seed32, args=(), rounds=RDS, iterations=ITR)65def test_seed64b(benchmark):66 benchmark.pedantic(rd.seed64, args=(), rounds=RDS, iterations=ITR)67def test_rand_bytes8b(benchmark):68 benchmark.pedantic(rd.rand_bytes, args=(8,), rounds=RDS, iterations=ITR)69def test_rand_bytes16b(benchmark):...

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