How to use _set_all_class method in fMBT

Best Python code snippet using fMBT_python

aalmodel.py

Source:aalmodel.py Github

copy

Full Screen

...42 while 1:43 try: plist.append(getattr(self, itemtype + str(i) + property_name))44 except: return plist45 i += 146 def _set_all_class(self, property_name, itemtype, value_array):47 i = 148 cls = self.__class__49 while 1:50 itemname = itemtype + str(i) + property_name51 if hasattr(cls, itemname):52 setattr(cls, itemname, value_array[i-1])53 else:54 return55 i += 156 def call(self, func, call_arguments = ()):57 guard_list = None58 try:59 func_name = func.__name__60 if func_name.endswith("guard"):61 guard_list = self._variables['guard_list']62 guard_list.append(63 getattr(self, func_name.replace("guard", "name"), ""))64 fmbt._g_simulated_actions = self._stack_executed_actions65 if hasattr(func,"requires"):66 for prerequire in func.requires:67 if not self.call(getattr(self,prerequire)):68 return False69 args = []70 for arg in call_arguments:71 if arg == '':72 args.append('')73 else:74 args.append(eval(arg, self._variables))75 self._variables['args'] = args76 return eval(func.func_code, self._variables)77 except Exception, e:78 self._log("Exception %s in %s: %s" % (e.__class__, func.func_name, e))79 self._log(traceback.format_exc())80 raise81 finally:82 if guard_list != None:83 guard_list.pop()84 def call_exception_handler(self, handler_name, action_name, exc, pass_through_rv=[]):85 rv = self._variables[handler_name](action_name, exc)86 if rv in pass_through_rv:87 return rv88 elif type(rv) == int:89 return rv90 elif rv == None or rv == True:91 return self._variables['action'](action_name)92 else:93 raise Exception('''Exception handler "%s('%s', %s)" returned unexpected value: %s''' %94 (handler_name, action_name, exc, rv))95 def call_tagexception_handler(self, handler_name, tag_name, exc):96 rv = self._variables[handler_name](tag_name, exc)97 if type(rv) in [bool, types.NoneType]:98 return rv99 else:100 raise Exception('''Exception handler "%s('%s', %s)" returned unexpected value: %s''' %101 (handler_name, tag_name, exc, rv))102 def reset(self):103 # initialize model104 fmbt._g_actionName = "AAL: initial_state"105 rv = self.call(self.initial_state)106 self._push_variables = [107 v for v in self.__class__.push_variables_set108 if (v in self._variables and109 type(eval(v, self._variables)) not in [types.ModuleType, types.ClassType])110 ]111 return rv112 def adapter_init():113 return True114 def init(self):115 # initialize adapter116 fmbt._g_actionName = "AAL: adapter_init"117 rv = self.call(self.adapter_init)118 return rv119 def adapter_exit(verdict, reason):120 return121 def aexit(self, verdict, reason):122 if not self._adapter_exit_executed:123 self._adapter_exit_executed = True124 fmbt._g_actionName = "AAL: adapter_exit"125 self.adapter_exit.im_func(verdict, reason)126 def adapter_execute(self, i, adapter_call_arguments = ()):127 if not 0 < i <= len(self._all_names):128 raise IndexError('Cannot execute action %s adapter code' % (i,))129 if self._all_types[i-1] == "input":130 try:131 fmbt._g_actionName = self._all_names[i-1]132 fmbt._g_testStep += 1133 rv = self.call(self._all_adapters[i-1], adapter_call_arguments)134 fmbt._g_testStep -= 1135 if rv == None: return i136 else: return rv137 except Exception, exc:138 if 'adapter_exception_handler' in self._variables:139 return self.call_exception_handler('adapter_exception_handler', self._all_names[i-1], exc)140 else:141 raise142 else:143 self._log("AAL model: adapter_execute for an output action in AAL." +144 "This should take place in observe().\n")145 return 0146 def tag_execute(self, i):147 if not 0 < i <= len(self._all_tagnames):148 raise IndexError('Cannot execute tag %s adapter code' % (i,))149 fmbt._g_actionName = "tag: " + self._all_tagnames[i-1]150 try:151 rv = self.call(self._all_tagadapters[i-1])152 except Exception, exc:153 if 'adapter_exception_handler' in self._variables:154 return self.call_tagexception_handler('adapter_exception_handler', self._all_tagnames[i-1], exc)155 else:156 raise157 return rv158 def model_execute(self, i):159 if not 0 < i <= len(self._all_names):160 # If adapter execute returns 0, that is reports unidentified action,161 # test engine checks if executing an unidentified action is ok by162 # calling model_execute(0). In AAL/Python it is never ok.163 return 0164 fmbt._g_actionName = self._all_names[i-1]165 if i in self._enabled_actions_stack[-1] or self.call(self._all_guards[i-1]):166 self.call(self._all_bodies[i-1])167 if self._has_serial:168 for postfunc in getattr(self, self._all_bodies[i-1].__name__ + "_postcall", []):169 getattr(self, postfunc)(fmbt._g_actionName)170 if len(self._stack) == 0:171 fmbt._g_testStep += 1172 if len(self._stack_executed_actions) > 0:173 self._stack_executed_actions[-1].append(fmbt._g_actionName)174 self._enabled_actions_stack[-1] = set()175 return i176 else:177 self._enabled_actions_stack[-1] = set()178 return 0179 def getActions(self):180 enabled_actions = []181 for index, guard in enumerate(self._all_guards):182 fmbt._g_actionName = self._all_names[index]183 if self.call(guard): enabled_actions.append(index + 1)184 self._enabled_actions_stack[-1] = set(enabled_actions)185 return enabled_actions186 def getIActions(self):187 enabled_iactions = []188 try:189 for index, guard in enumerate(self._all_guards):190 fmbt._g_actionName = self._all_names[index]191 if self._all_types[index] == "input" and self.call(guard):192 enabled_iactions.append(index + 1)193 except Exception, e:194 raise Exception('Error at guard() of "%s": %s: %s' % (195 self._all_names[index], type(e).__name__, e))196 self._enabled_actions_stack[-1].update(enabled_iactions)197 return enabled_iactions198 def getprops(self):199 enabled_tags = []200 for index, guard in enumerate(self._all_tagguards):201 fmbt._g_actionName = "tag: " + self._all_tagnames[index]202 if self.call(guard): enabled_tags.append(index + 1)203 return enabled_tags204 def getActionNames(self):205 return self._all_names206 def getSPNames(self):207 return self._all_tagnames208 def push(self):209 # initial state must reset all variables.210 # automatic push saves only their states211 stack_element = {}212 for varname in self._push_variables:213 stack_element[varname] = copy.deepcopy(self._variables[varname])214 if self._has_serial:215 stack_element["!serial_abn"] = copy.deepcopy(self._get_all("guard_next_block", "serial"))216 self._stack.append(stack_element)217 self._stack_executed_actions.append([])218 self._enabled_actions_stack.append(set(self._enabled_actions_stack[-1]))219 def pop(self):220 stack_element = self._stack.pop()221 self._stack_executed_actions.pop()222 for varname in stack_element:223 if varname.startswith("!"): continue224 self._variables[varname] = stack_element[varname]225 if self._has_serial:226 self._set_all_class("guard_next_block", "serial", stack_element["!serial_abn"])227 self._enabled_actions_stack.pop()228 def state(self, discard_variables = set([]), include_variables=None):229 """230 Return the current state of the model as a string.231 By comparing strings one can check if the state is already seen.232 """233 rv_list = []234 for varname in self._push_variables:235 if ((include_variables and not varname in include_variables) or236 (varname in discard_variables)):237 continue238 rv_list.append("%s = %s" % (varname, repr(self._variables[varname])))239 if self._has_serial:240 rv_list.append("!serial = %s" % (self._get_all("guard_next_block", "serial"),))...

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