How to use get_or_die method in avocado

Best Python code snippet using avocado_python

beef.py

Source:beef.py Github

copy

Full Screen

...60 raise ValueError("Unknown beef version '%s'" % version)61 getattr(beef, decoder)(data)62 return beef63 @staticmethod64 def get_or_die(d, k):65 if k not in d:66 raise ValueError("Missed '%s' key" % k)67 return d[k]68 def decode_v1(self, data):69 self.version = self.get_or_die(data, "version")70 self.uuid = self.get_or_die(data, "uuid")71 self.spec = self.get_or_die(data, "spec")72 box = self.get_or_die(data, "box")73 self.box = Box(74 profile=self.get_or_die(box, "profile"),75 vendor=self.get_or_die(box, "vendor"),76 platform=self.get_or_die(box, "platform"),77 version=self.get_or_die(box, "version"),78 )79 self.changed = self.get_or_die(data, "changed")80 self.description = data.get("description") or ""81 self.cli_fsm = [82 CLIFSM(83 state=self.get_or_die(d, "state"),84 reply=[smart_bytes(n) for n in self.get_or_die(d, "reply")],85 )86 for d in self.get_or_die(data, "cli_fsm")87 ]88 self.cli = [89 CLI(90 names=[n for n in self.get_or_die(d, "names")],91 request=smart_bytes(self.get_or_die(d, "request")),92 reply=[smart_bytes(n) for n in self.get_or_die(d, "reply")],93 )94 for d in self.get_or_die(data, "cli")95 ]96 self.mib_encoding = self.get_or_die(data, "mib_encoding")97 self.mib = [98 MIB(oid=self.get_or_die(d, "oid"), value=smart_bytes(self.get_or_die(d, "value")))99 for d in self.get_or_die(data, "mib")100 ]101 self._mib_decoder = getattr(self, "mib_decode_%s" % self.mib_encoding)102 self.cli_encoding = self.get_or_die(data, "cli_encoding")103 self._cli_decoder = getattr(self, "cli_decode_%s" % self.cli_encoding)104 def get_data(self, decode=False):105 return {106 "version": "1",107 "uuid": self.uuid,108 "spec": self.spec,109 "box": {110 "profile": self.box.profile,111 "vendor": self.box.vendor,112 "platform": self.box.platform,113 "version": self.box.version,114 },115 "changed": self.changed,116 "description": self.description,...

Full Screen

Full Screen

handler.py

Source:handler.py Github

copy

Full Screen

...3import json4import boto35import os6sts = boto3.client('sts')7def get_or_die(e):8 var = os.getenv(e)9 if not var:10 print("Could get get necessary environment variable: " + e)11 exit(1)12 return var13# https://gist.github.com/gene1wood/938ff578fbe57cf894a105b4107702de14def role_arn_to_session(**args):15 """16 Usage :17 session = role_arn_to_session(18 RoleArn='arn:aws:iam::012345678901:role/example-role',19 RoleSessionName='ExampleSessionName')20 client = session.client('sqs')21 """22 response = sts.assume_role(**args)23 return boto3.Session(24 aws_access_key_id=response['Credentials']['AccessKeyId'],25 aws_secret_access_key=response['Credentials']['SecretAccessKey'],26 aws_session_token=response['Credentials']['SessionToken'])27role_to_assume = get_or_die('RoleToAssume')28forwarding_stream_name = get_or_die('ForwardingStreamName')29ca_session = role_arn_to_session(30 # FIXME:31 # - get role from ssm32 # - figure out role expiry and cycle as-necessary33 RoleArn = role_to_assume,34 RoleSessionName = 'cross-accountlambda-event-forwarder'35)36# the cross-accout kinesis client37ca_kinesis = ca_session.client('kinesis')38def main(event, context):39 for record in event['Records']:40 # Kinesis data is base64 encoded so decode here41 payload = base64.b64decode(record['kinesis']['data'])42 print("Decoded payload: " + payload)...

Full Screen

Full Screen

server.py

Source:server.py Github

copy

Full Screen

1from flask import Flask, render_template2import json, parser, os3app = Flask(__name__)4laws = json.loads(open('laws.json', 'r').read())5def get_or_die(file_urn, laws):6 tmp_laws = []7 for index, l in enumerate(laws):8 if l:9 filename = l['urn'].split(';')[0][:-6]+'::'+l['urn'].split(';')[1] + '.json'10 if file_urn == filename:11 l = parser.getCamaraUrl(l)12 l = parser.getCamaraText(l)13 tmp_laws.append(l)14 else:15 tmp_laws.append(l)16 if os.path.isfile('data/'+file_urn):17 update = open('laws.json', 'w')18 update.write(json.dumps(laws, indent=4))19 update.close()20 law = json.loads(open('data/'+file_urn).read())21 return law22 else:23 return {'raw' : 'Not Found!'}24 25@app.route('/<tipo>/<numero>/<ano>')26def index(tipo, numero, ano, laws=laws):27 file_urn = 'urn:lex:br:federal:'+tipo+':'+ano+'::'+numero+'.json'28 if os.path.isfile('data/'+file_urn):29 law = json.loads(open('data/'+file_urn).read())30 return render_template('law.html', law=law)31 else:32 law = get_or_die(file_urn, laws)33 return render_template('law.html', law=law)34if __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 avocado 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