Best Python code snippet using autotest_python
control.py
Source: control.py
...19from .runable_instance import RunableInstance20from time import time21_runable_instance: RunableInstance = None22_active_instances: Dict[Instance, List] = {}23def _set_instance(instance: Instance, max_instances: int = 1):24 global _runable_instance25 global _active_instances26 if _runable_instance is not None and _runable_instance.instance == instance:27 # instance is already avaiable as runable_instance - return28 return29 if max_instances > 0 and len(_active_instances) > max_instances:30 # we have too many instances...31 sorted_instances = sorted(_active_instances.items(), key=lambda x: x[1][1], reverse=True)32 sorted_instances = sorted_instances[-(len(sorted_instances)-max_instances):]33 # remove the unused instances34 for elem in sorted_instances:35 elem[1][0].terminate()36 del _active_instances[elem[0]]37 if instance in _active_instances and _active_instances[instance][0].is_alive():38 _runable_instance = _active_instances[instance][0]39 _active_instances[instance][1] = time()40 return41 else:42 # replace the oldest instance if the number is exhausted43 if max_instances > 0 and len(_active_instances) == max_instances:44 elem = sorted(_active_instances.items(), key=lambda x: x[1][1], reverse=True)[-1]45 elem[1][0].terminate()46 del _active_instances[elem[0]]47 # create a new runable instance and add it to the dictionary48 _runable_instance = RunableInstance(instance)49 _active_instances[instance] = [_runable_instance, time()]50def train(instance: Instance, batch_iterable=None, dev=False, max_instances=1):51 if dev:52 temp_dir = TemporaryDirectory()53 model = instance.load_code(temp_dir.name)54 actions.train(model, instance, batch_iterable)55 temp_dir.cleanup()56 else:57 _set_instance(instance, max_instances)58 _runable_instance.train(batch_iterable)59def infer(instance: Instance, data, dev=False, model=None, max_instances=1) -> List[Any]:60 if dev:61 temp_dir = None62 if model is None:63 temp_dir = TemporaryDirectory()64 model = instance.load_code(temp_dir.name)65 ret = actions.infer(model, instance, data)66 if temp_dir:67 temp_dir.cleanup()68 return ret69 else:70 _set_instance(instance, max_instances)71 return _runable_instance.infer(data)72def terminate():73 for elem in _active_instances.values():...
woo_product_image_ept.py
Source: woo_product_image_ept.py
...34 product_image.url_image_id=base64.b64encode(img.content)35 except Exception:36 pass37 @api.depends('woo_product_tmpl_id')38 def _set_instance(self):39 for woo_gallery_img in self:40 woo_gallery_img.woo_instance_id = woo_gallery_img.woo_product_tmpl_id.woo_instance_id.id41 42 sequence = fields.Integer("Sequence",defaule=None)43 woo_instance_id=fields.Many2one("woo.instance.ept","Instance",readonly=True,compute="_set_instance",store=True)44 is_image_url=fields.Boolean("Is Image Url?",related="woo_instance_id.is_image_url")45 image=fields.Binary("Image") 46 woo_product_tmpl_id = fields.Many2one('woo.product.template.ept', string='WooCommerce Product') 47 url = fields.Char(size=600, string='Image URL')48 response_url = fields.Char(size=600, string='Response URL',help="URL from WooCommerce")49 url_image_id=fields.Binary("Image URL ID",compute=set_image,store=False)...
__init__.py
Source: __init__.py
...7 def __init__( self ):8 gedit.Plugin.__init__( self )9 def _get_instance( self, window ):10 return window.get_data( self.DATA_TAG )11 def _set_instance( self, window, instance ):12 window.set_data( self.DATA_TAG, instance )13 def is_configurable( self ):14 return True15 def create_configure_dialog( self ):16 return FuzzyOpenConfigWindow()._window17 def activate( self, window ):18 self._set_instance( window, FuzzyOpenPluginInstance( self, window ) )19 def deactivate( self, window ):20 self._get_instance( window ).deactivate()21 self._set_instance( window, None )22 def update_ui( self, window ):...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!