Best Python code snippet using avocado_python
__init__.py
Source:__init__.py
...45 op = ">="46 class Lte(Op):47 op = "<="48 @classmethod49 def _parse_key_val(cls, k, v):50 if issubclass(v.__class__, cls.Op):51 return '{} {} "{}"'.format(k, v.op, v.v)52 else:53 return '{} {} "{}"'.format(k, cls.Eq.op, v)54 @classmethod55 def sql(cls, data):56 rows = []57 for k, v in data.items():58 if isinstance(v, list) or isinstance(v, tuple) or isinstance(v, set):59 parts = [cls._parse_key_val(k, _v) for _v in v]60 rows.append("( {} )".format(cls.OR.join(parts)))61 else:62 rows.append(cls._parse_key_val(k, v))63 return cls.AND.join(rows)64def validate_with_schema(65 data: Dict, schema: Dict, do_raise: bool = True, reraise_as: Exception = None66):67 """Validate JSON data using a JSON Schema."""68 try:69 jsonschema.validate(data, schema)70 except jsonschema.ValidationError as e:71 if do_raise:72 if reraise_as:73 raise reraise_as(str(e)) from e74 else:75 raise e76 else:...
gnmi_utils.py
Source:gnmi_utils.py
...5from gnmi import gnmi_pb2, gnmi_pb2_grpc6# This file contains utility functions that make it easy to perform gNMI7# requests against the switch under test.8_grpc_addr = testutils.test_param_get("grpcaddr")9def _parse_key_val(key_val_str):10 # [key1=val1,key2=val2,.....]11 key_val_str = key_val_str[1:-1] # remove "[]"12 return [kv.split("=") for kv in key_val_str.split(",")]13# parse path_str string and add elements to path (gNMI Path class)14def _build_path(path_str, path):15 if path_str == "/":16 # the root path should be an empty path17 return18 path_elem_info_list = re.findall(r"/([^/\[]+)(\[([^=]+=[^\]]+)\])?", path_str)19 for path_elem_info in path_elem_info_list:20 # [('interfaces', ''), ('interface', '[name=1/1/1]'), ...]21 pe = path.elem.add()22 pe.name = path_elem_info[0]23 if path_elem_info[1]:24 for kv in _parse_key_val(path_elem_info[1]):25 # [('name', '1/1/1'), ...]26 pe.key[kv[0]] = kv[1]27# Public API starts here.28def build_gnmi_get_req(path: str):29 req = gnmi_pb2.GetRequest()30 req.encoding = gnmi_pb2.PROTO31 p = req.path.add()32 _build_path(path, p)33 if path == "/":34 # Special case35 req.type = gnmi_pb2.GetRequest.CONFIG36 return req37def build_gnmi_set_req(path: str, value, replace=False):38 req = gnmi_pb2.SetRequest()...
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!!