How to use catch_wrapper method in tavern

Best Python code snippet using tavern

_LogError_V3.py

Source:_LogError_V3.py Github

copy

Full Screen

...157 def __call__(_, function):158 catch = Catcher(True)159 160 if inspect.iscoroutinefunction(function):161 async def catch_wrapper(*args, **kwargs):162 with catch:163 return await function(*args, **kwargs)164 165 elif inspect.isgeneratorfunction(function):166 def catch_wrapper(*args, **kwargs):167 with catch:168 return (yield from function(*args, **kwargs))169 170 else:171 def catch_wrapper(*args, **kwargs):172 with catch:173 return function(*args, **kwargs)174 self._core.handlers[str(len(self._core.handlers)-1)] = function175 functools.update_wrapper(catch_wrapper, function)176 return catch_wrapper177 178 return Catcher(False)...

Full Screen

Full Screen

audit_cli.py

Source:audit_cli.py Github

copy

Full Screen

...4from autoaudit.dns import dns_checks5from autoaudit.dns.spf import spf_record6from autoaudit.dns.helpers import reverse_lookup_ipv4, reverse_lookup_ipv67from autoaudit.tcp_ip.helpers import my_ip, is_ipv4, is_ipv68def catch_wrapper(f, *args, **kwargs):9 try:10 return f(*args, **kwargs)11 except Exception as e:12 return f"Error: {e}"13def dns_audit(args: Namespace):14 return (15 {16 n: catch_wrapper(f, args.domain)17 for n, f in dns_checks.items()18 }19 )20def smtp_scan(args: Namespace):21 return {22 n: f(23 args.host,24 args.port,25 args.sender_addr26 ) for n, f in scan_funcs.items()27 }28def send_mails(args):29 return {30 n: f(args.host, args.port, args.recipient, args.sender_addr)31 for n, f in send_funcs.items()32 }33def check_setup(args):34 ip = my_ip()35 if is_ipv4(ip):36 reverse_lookup = catch_wrapper(reverse_lookup_ipv4, ip)37 elif is_ipv6(ip):38 reverse_lookup = catch_wrapper(reverse_lookup_ipv6, ip)39 else:40 raise ValueError(f"{ip} is not an IP")41 return {42 "your_ip": ip,43 "reverse_lookup": reverse_lookup,44 args.sender_addr.split("@").pop(): {45 "spf": catch_wrapper(spf_record, args.sender_addr.split("@").pop())46 } if args.sender_addr else dict()47 }48def main():49 ap = ArgumentParser()50 sub_parsers = ap.add_subparsers(51 help="sub-commands help"52 )53 # configure 'dns' subcommand54 dns_parser = sub_parsers.add_parser(55 "dns", help="check mail-specific DNS config"56 )57 dns_parser.set_defaults(func=dns_audit)58 dns_parser.add_argument("domain")59 # configure 'smtp' subcommand...

Full Screen

Full Screen

get_common_names.py

Source:get_common_names.py Github

copy

Full Screen

...5import json6import functools7import OpenSSL.crypto as crypto8from typing import Iterator, Callable, List, Any, Iterable9def catch_wrapper(g: Callable, exceptions: List[Any]):10 def _catch_wrapper(f):11 @functools.wraps(f)12 def _wrapped(*args, **kwargs):13 try:14 return f(*args, **kwargs)15 except exceptions:16 g()17 return _wrapped18 return _catch_wrapper19def iter_stdin() -> Iterator:20 while True:21 try:22 yield(input())23 except EOFError:24 return25@catch_wrapper(lambda: ..., [ConnectionRefusedError, ConnectionResetError])26def get_cn(ip: str, port: int):27 dst = (ip, 443)28 cert = ssl.get_server_certificate(dst).encode()29 x509 = crypto.load_certificate(crypto.FILETYPE_PEM, cert)30 cert_hostname = x509.get_subject().CN31 for name in cert_hostname.split("\n"):32 yield name33def run_from_iter(iter_: Iterable):34 return [functools.reduce(35 lambda a, b: a + b,36 get_cn(line.strip(), 443)37 ) for line in iter_]38def run_from_stdin():39 return run_from_iter(iter_stdin())...

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