Best Python code snippet using assertpy_python
engine.py
Source:engine.py
...16 self.action_name = action_name17 self.function = function18 self.has_command = has_command19 def __call__(self, targets, sources, property_set_):20 assert is_iterable(targets)21 assert is_iterable(sources)22 assert isinstance(property_set_, property_set.PropertySet)23 if self.has_command:24 # Bjam actions defined from Python have only the command25 # to execute, and no associated jam procedural code. So26 # passing 'property_set' to it is not necessary.27 bjam_interface.call("set-update-action", self.action_name,28 targets, sources, [])29 if self.function:30 self.function(targets, sources, property_set_)31class BjamNativeAction(BjamAction):32 """Class representing bjam action defined by Jam code.33 We still allow to associate a Python callable that will34 be called when this action is installed on any target.35 """36 def __call__(self, targets, sources, property_set_):37 assert is_iterable(targets)38 assert is_iterable(sources)39 assert isinstance(property_set_, property_set.PropertySet)40 if self.function:41 self.function(targets, sources, property_set_)42 p = []43 if property_set:44 p = property_set_.raw()45 set_jam_action(self.action_name, targets, sources, p)46action_modifiers = {"updated": 0x01,47 "together": 0x02,48 "ignore": 0x04,49 "quietly": 0x08,50 "piecemeal": 0x10,51 "existing": 0x20}52class Engine:53 """ The abstract interface to a build engine.54 For now, the naming of targets, and special handling of some55 target variables like SEARCH and LOCATE make this class coupled56 to bjam engine.57 """58 def __init__ (self):59 self.actions = {}60 def add_dependency (self, targets, sources):61 """Adds a dependency from 'targets' to 'sources'62 Both 'targets' and 'sources' can be either list63 of target names, or a single target name.64 """65 if isinstance (targets, str):66 targets = [targets]67 if isinstance (sources, str):68 sources = [sources]69 assert is_iterable(targets)70 assert is_iterable(sources)71 for target in targets:72 for source in sources:73 self.do_add_dependency (target, source)74 def get_target_variable(self, targets, variable):75 """Gets the value of `variable` on set on the first target in `targets`.76 Args:77 targets (str or list): one or more targets to get the variable from.78 variable (str): the name of the variable79 Returns:80 the value of `variable` set on `targets` (list)81 Example:82 >>> ENGINE = get_manager().engine()83 >>> ENGINE.set_target_variable(targets, 'MY-VAR', 'Hello World')84 >>> ENGINE.get_target_variable(targets, 'MY-VAR')85 ['Hello World']86 Equivalent Jam code:87 MY-VAR on $(targets) = "Hello World" ;88 echo [ on $(targets) return $(MY-VAR) ] ;89 "Hello World"90 """91 if isinstance(targets, str):92 targets = [targets]93 assert is_iterable(targets)94 assert isinstance(variable, basestring)95 return bjam_interface.call('get-target-variable', targets, variable)96 def set_target_variable (self, targets, variable, value, append=0):97 """ Sets a target variable.98 The 'variable' will be available to bjam when it decides99 where to generate targets, and will also be available to100 updating rule for that 'taret'.101 """102 if isinstance (targets, str):103 targets = [targets]104 if isinstance(value, str):105 value = [value]106 assert is_iterable(targets)107 assert isinstance(variable, basestring)108 assert is_iterable(value)109 if targets:110 if append:111 bjam_interface.call("set-target-variable", targets, variable, value, "true")112 else:113 bjam_interface.call("set-target-variable", targets, variable, value)114 def set_update_action (self, action_name, targets, sources, properties=None):115 """ Binds a target to the corresponding update action.116 If target needs to be updated, the action registered117 with action_name will be used.118 The 'action_name' must be previously registered by119 either 'register_action' or 'register_bjam_action'120 method.121 """122 if isinstance(targets, str):123 targets = [targets]124 if isinstance(sources, str):125 sources = [sources]126 if properties is None:127 properties = property_set.empty()128 assert isinstance(action_name, basestring)129 assert is_iterable(targets)130 assert is_iterable(sources)131 assert(isinstance(properties, property_set.PropertySet))132 self.do_set_update_action (action_name, targets, sources, properties)133 def register_action (self, action_name, command='', bound_list = [], flags = [],134 function = None):135 """Creates a new build engine action.136 Creates on bjam side an action named 'action_name', with137 'command' as the command to be executed, 'bound_variables'138 naming the list of variables bound when the command is executed139 and specified flag.140 If 'function' is not None, it should be a callable taking three141 parameters:142 - targets143 - sources144 - instance of the property_set class145 This function will be called by set_update_action, and can146 set additional target variables.147 """148 assert isinstance(action_name, basestring)149 assert isinstance(command, basestring)150 assert is_iterable(bound_list)151 assert is_iterable(flags)152 assert function is None or callable(function)153 bjam_flags = reduce(operator.or_,154 (action_modifiers[flag] for flag in flags), 0)155 # We allow command to be empty so that we can define 'action' as pure156 # python function that would do some conditional logic and then relay157 # to other actions.158 assert command or function159 if command:160 bjam_interface.define_action(action_name, command, bound_list, bjam_flags)161 self.actions[action_name] = BjamAction(162 action_name, function, has_command=bool(command))163 def register_bjam_action (self, action_name, function=None):164 """Informs self that 'action_name' is declared in bjam.165 From this point, 'action_name' is a valid argument to the166 set_update_action method. The action_name should be callable167 in the global module of bjam.168 """169 # We allow duplicate calls to this rule for the same170 # action name. This way, jamfile rules that take action names171 # can just register them without specially checking if172 # action is already registered.173 assert isinstance(action_name, basestring)174 assert function is None or callable(function)175 if action_name not in self.actions:176 self.actions[action_name] = BjamNativeAction(action_name, function)177 # Overridables178 def do_set_update_action (self, action_name, targets, sources, property_set_):179 assert isinstance(action_name, basestring)180 assert is_iterable(targets)181 assert is_iterable(sources)182 assert isinstance(property_set_, property_set.PropertySet)183 action = self.actions.get(action_name)184 if not action:185 raise Exception("No action %s was registered" % action_name)186 action(targets, sources, property_set_)187 def do_set_target_variable (self, target, variable, value, append):188 assert isinstance(target, basestring)189 assert isinstance(variable, basestring)190 assert is_iterable(value)191 assert isinstance(append, int) # matches bools192 if append:193 bjam_interface.call("set-target-variable", target, variable, value, "true")194 else:195 bjam_interface.call("set-target-variable", target, variable, value)196 def do_add_dependency (self, target, source):197 assert isinstance(target, basestring)198 assert isinstance(source, basestring)...
functiontype_stubt0.7000000000000001_pp2.0_fp0_1.py
Source:functiontype_stubt0.7000000000000001_pp2.0_fp0_1.py
...4b = (x for x in [1])5print(type(b))6print(a == b)7print(a is b)8def is_iterable(param):9 return isinstance(param, Iterator)10def is_iterable(param):11 return isinstance(param, Iterator)12def is_iterable(param):13 return isinstance(param, Iterator)14print(is_iterable([]))15print(is_iterable({}))16print(is_iterable(100))17def is_iterable(param):18 return hasattr(param, '__iter__')19print(is_iterable([]))20print(is_iterable({}))21print(is_iterable(100))22print(is_iterable(iter([])))23print(is_iterable(iter({})))24print(is_iterable(iter(100)))25# å¤ææ¯å¦å¯ä»¥è¿ä»£26from collections import Iterator...
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!!