Best Python code snippet using rester_python
exc.py
Source:exc.py
...118 value = eval(json_types[value])119 json_eval_expr = type(json_eval_expr)120 # Check for logical operators121 logic_ops = {'-gt':'>', '-ge':'>=', '-lt':'<', '-le':'<=', '-ne':'!=', '-eq':'==', 'exec': 'exec'}122 lg_op_expr = check_for_logical_op(value)123 if lg_op_expr:124 self.logger.debug("---> Found lg_op_expr : " + lg_op_expr)125 if lg_op_expr in logic_ops:126 final_lg_op = logic_ops[lg_op_expr]127 value = value[len(lg_op_expr):]128 self.logger.debug(" -----> Rest of the expression : " + value)129 else:130 # - If no operators found then assume '=='131 final_lg_op = logic_ops['-eq']132 self.logger.debug("---> Final final_lg_op : " + final_lg_op)133 # do variable expansion...134 value = self.case.variables.expand(value)135 self.logger.debug(' ---> final evaluated expression : %s and type %s ', value, type(value))136 if isinstance(json_eval_expr, basestring):137 value = str(value)138 # construct the logical assert expression139 if final_lg_op != 'exec':140 assert_expr = 'json_eval_expr {0} value'.format(final_lg_op)141 assert_literal_expr = "{}:{{{}}} {} {}".format(key, json_eval_expr, final_lg_op, value)142 self.logger.debug(' ---> Assert_expr : ' + assert_expr)143 assert_result = eval(assert_expr)144 else:145 assert_expr = 'exec_result = {0}'.format(value)146 assert_literal_expr = '"f({0}) <- {1}"'.format(json_eval_expr, value)147 exec(assert_expr)148 assert_result = _evaluate(value, json_eval_expr)149 self.logger.debug('assert evaluation result : %s', assert_result)150 if not assert_result:151 assert_message = '{} Assert Statement : {} ---> Fail!'.format(section, assert_literal_expr)152 self.logger.error('%s', assert_message)153 failures.errors.append(assert_message)154 else:155 assert_message = '{} Assert Statement : {} ----> Pass!'.format(section, assert_literal_expr)156 self.logger.info('%s', assert_message)157 def _process_post_asserts(self, response, key, value):158 self.logger.debug("evaled value: {}".format(getattr(response, value, '')))159 self.case.variables.add_variable(key, getattr(response, value, ''))160def _evaluate(clause, value):161 assert_expr = 'result = {0}'.format(clause)162 #self.logger.debug(' ---> Assert_exec : ' + assert_expr)163 exec(assert_expr)164 return result #@UndefinedVariable165def check_for_logical_op(expression):166 if expression and isinstance(expression, basestring):167 #self.logger.debug("_check_for_logical_op : expression %s", expression)168 oprtr_regex = re.compile("-lt|-le|-gt|-ge|-eq|-ne|exec")169 match = re.match(oprtr_regex, expression)170 if match:...
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!!