How to use raise_if_not method in Selene

Best Python code snippet using selene_python

utils.py

Source:utils.py Github

copy

Full Screen

...53Regex.address_port = Regex(r'\d+')54Regex.peer_identity = Regex(r'{}@{}:{}'.format(Regex.peer_name.pattern,55 Regex.onion_domain.pattern,56 Regex.address_port.pattern))57def raise_if_not(f, error=ValueError):58 @wraps(f)59 def raising_f(instance=None, attribute=None, value=None):60 if not f(value):61 raise error()62 return raising_f63def is_valid_name(value):64 return (isinstance(value, str) and65 Regex.peer_name.match(value) is not None)66raise_invalid_name = raise_if_not(is_valid_name,67 errors.InvalidNameError)68def is_valid_identity(value):69 return (isinstance(value, str) and70 Regex.peer_identity.match(value) is not None)71raise_invalid_identity = raise_if_not(is_valid_identity,72 errors.InvalidIdentityError)73def is_valid_curve25519_key(value):74 return isinstance(value, bytes) and len(value) == PublicKey.SIZE75def is_valid_priv_key(value):76 return is_valid_curve25519_key(value)77raise_invalid_priv_key = raise_if_not(is_valid_priv_key,78 errors.InvalidPrivateKeyError)79def is_valid_pub_key(value):80 return is_valid_curve25519_key(value)81raise_invalid_pub_key = raise_if_not(is_valid_pub_key,82 errors.InvalidPublicKeyError)83def is_valid_shared_key(value):84 return is_valid_curve25519_key(value)85raise_invalid_shared_key = raise_if_not(is_valid_shared_key,86 errors.InvalidSharedKeyError)87def is_valid_file_name(value):88 # TODO make a real file name validator89 try:90 expath = os.path.expanduser(value)91 assert expath == value92 abspath = os.path.abspath(value)93 assert abspath == os.path.join(os.getcwd(), value)94 head, tail = os.path.split(value)95 assert not len(head) and tail == value96 except:97 return False98 else:99 return True

Full Screen

Full Screen

packets.py

Source:packets.py Github

copy

Full Screen

...50 return LINESEP.join([str(getattr(self, a.name))51 for a in attr.fields(type(self))])52@attr.s53class IdentifiablePacket(Packet):54 iv = attr.ib(validator=raise_if_not(is_valid_iv))55 iv_hash = attr.ib(validator=raise_if_not(is_valid_hash))56@attr.s57class IntroductionPacket(IdentifiablePacket):58 tail = attr.ib(validator=raise_if_not(is_valid_non_empty))59 @classmethod60 @raise_malformed61 def build(cls, data):62 lines = data.splitlines()63 return cls(iv=lines[0],64 iv_hash=lines[1],65 tail=LINESEP.join(lines[2:]))66@attr.s67class RegularPacket(IdentifiablePacket):68 payload_hash = attr.ib(validator=raise_if_not(is_valid_hash))69 handshake_key = attr.ib(validator=raise_if_not(is_valid_empty))70 payload = attr.ib(validator=raise_if_not(is_valid_non_empty))71@attr.s72class ReplyPacket(IdentifiablePacket):73 payload_hash = attr.ib(validator=raise_if_not(is_valid_hash))74 handshake_key = attr.ib(validator=raise_if_not(is_valid_enc_key))75 payload = attr.ib(validator=raise_if_not(is_valid_non_empty))76@attr.s77class RequestPacket(IdentifiablePacket):78 handshake_packet_hash = attr.ib(validator=raise_if_not(is_valid_hash))79 request_key = attr.ib(validator=raise_if_not(is_valid_key))80 handshake_packet = attr.ib(raise_if_not(is_valid_non_empty))81@attr.s82class HandshakePacket(Packet):83 identity = attr.ib(validator=attr.validators.instance_of(str))84 identity_key = attr.ib(validator=raise_if_not(is_valid_key))85 handshake_key = attr.ib(validator=raise_if_not(is_valid_key))86 ratchet_key = attr.ib(validator=raise_if_not(is_valid_key))87@attr.s88class ElementPacket(Packet):89 type_ = attr.ib(validator=attr.validators.instance_of(str))90 id_ = attr.ib(validator=attr.validators.instance_of(str))91 part_num = attr.ib(convert=int)92 part_total = attr.ib(convert=int)93 payload = attr.ib(validator=attr.validators.instance_of(str))94 @classmethod95 @raise_malformed96 def build(cls, data):97 lines = data.splitlines()98 return cls(type_=lines[0],99 id_=lines[1],100 part_num=lines[2],...

Full Screen

Full Screen

validate.py

Source:validate.py Github

copy

Full Screen

...9__TOOLS__ = ["gatk", "muse", "strelka", "freebayes"]10def validate(opts):11 """Raises ValueError if options are invalid/incomplete"""12 # tool, run_type, opts[tool]13 raise_if_not([opts["tool"]], __TOOLS__, "Unsupported toolchain")14 _opts = dict((tool, template_vars(tool)) for tool in __TOOLS__)15 mandatory_somatic = set(deepcopy(_opts["gatk"]))16 consume(17 map(18 mandatory_somatic.intersection_update,19 [_opts[t] for t in ["gatk", "muse", "strelka"]],20 )21 )22 mandatory_germline = set(deepcopy(_opts["gatk"]))23 consume(24 map(25 mandatory_germline.intersection_update,26 [_opts[t] for t in ["gatk", "freebayes", "strelka"]],27 )28 )29 # print(mandatory_germline)30 # print(mandatory_somatic)31 if "somatic" == opts["run_type"]:32 raise_if_not(mandatory_somatic, opts[opts["tool"]], "Missing mandatory option")33 elif "germline" == opts["run_type"]:34 raise_if_not(mandatory_germline, opts[opts["tool"]], "Missing mandatory option")35 else:36 pass...

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