Best Python code snippet using autotest_python
__init__.py
Source: __init__.py
...22 def delete(call):23 data = call.data24 entity_id = data[CONF_ENTITY_ID]25 saver_entity.delete(entity_id)26 def delete_variable(call):27 data = call.data28 variable = data[CONF_NAME]29 saver_entity.delete_variable(variable)30 def execute(call):31 data = call.data32 script = data[CONF_SCRIPT]33 saver_entity.execute(script)34 def restore_state(call):35 data = call.data36 entity_id = data[CONF_ENTITY_ID]37 restore_script = data[CONF_RESTORE_SCRIPT]38 should_delete = data[CONF_DELETE_AFTER_RUN]39 saver_entity.restore(entity_id, restore_script, should_delete)40 def save_state(call):41 data = call.data42 entity_id = data[CONF_ENTITY_ID]43 saver_entity.save(entity_id)44 def set_variable(call):45 data = call.data46 name = data[CONF_NAME]47 value = data[CONF_VALUE]48 saver_entity.set_variable(name, value)49 hass.services.register(DOMAIN, SERVICE_CLEAR, clear, SERVICE_CLEAR_SCHEMA)50 hass.services.register(DOMAIN, SERVICE_DELETE, delete, SERVICE_DELETE_SCHEMA)51 hass.services.register(DOMAIN, SERVICE_DELETE_VARIABLE, delete_variable, SERVICE_DELETE_VARIABLE_SCHEMA)52 hass.services.register(DOMAIN, SERVICE_EXECUTE, execute, SERVICE_EXECUTE_SCHEMA)53 hass.services.register(DOMAIN, SERVICE_RESTORE_STATE, restore_state, SERVICE_RESTORE_STATE_SCHEMA)54 hass.services.register(DOMAIN, SERVICE_SAVE_STATE, save_state, SERVICE_SAVE_STATE_SCHEMA)55 hass.services.register(DOMAIN, SERVICE_SET_VARIABLE, set_variable, SERVICE_SET_VARIABLE_SCHEMA)56 return True57class SaverEntity(RestoreEntity):58 def __init__(self):59 self._entities_db = {}60 self._variables_db = {}61 @property62 def name(self):63 return DOMAIN64 def clear(self):65 self._entities_db.clear()66 self._variables_db.clear()67 self.schedule_update_ha_state()68 def delete(self, entity_id):69 self._entities_db.pop(entity_id)70 self.schedule_update_ha_state()71 def delete_variable(self, variable):72 self._variables_db.pop(variable)73 self.schedule_update_ha_state()74 def execute(self, script):75 script = Script(self.hass, script, self.name, DOMAIN, script_mode=SCRIPT_MODE_PARALLEL)76 variables = {}77 variables.update(self._variables_db)78 for entity_id in self._entities_db:79 variables.update(SaverEntity.convert_to_variables(self._entities_db[entity_id], entity_id))80 script.run(variables=variables, context=Context())81 self.schedule_update_ha_state()82 def restore(self, entity_id, restore_script, delete):83 if entity_id not in self._entities_db:84 return85 old = self._entities_db[entity_id]...
variables.py
Source: variables.py
...18 fraudDetector.create_variable(name = 'order_price',variableType = 'PRICE',dataSource = 'EVENT',dataType = 'FLOAT',defaultValue = '0.0')19 fraudDetector.create_variable(name = 'payment_currency',variableType = 'CURRENCY_CODE',dataSource = 'EVENT',dataType = 'STRING',defaultValue = 'null')20 fraudDetector.create_variable(name = 'merchant',variableType = 'CATEGORICAL',dataSource = 'EVENT',dataType = 'STRING',defaultValue = 'null')21def delete_variables():22 fraudDetector.delete_variable(name = 'card_bin')23 fraudDetector.delete_variable(name = 'customer_name')24 fraudDetector.delete_variable(name = 'billing_street')25 fraudDetector.delete_variable(name = 'billing_city')26 fraudDetector.delete_variable(name = 'billing_state')27 fraudDetector.delete_variable(name = 'billing_zip')28 fraudDetector.delete_variable(name = 'billing_latitude')29 fraudDetector.delete_variable(name = 'billing_longitude')30 fraudDetector.delete_variable(name = 'customer_job')31 fraudDetector.delete_variable(name = 'ip_address')32 fraudDetector.delete_variable(name = 'customer_email')33 fraudDetector.delete_variable(name = 'phone')34 fraudDetector.delete_variable(name = 'user_agent')35 fraudDetector.delete_variable(name = 'product_category')36 fraudDetector.delete_variable(name = 'order_price')37 fraudDetector.delete_variable(name = 'payment_currency')...
test_utility.py
Source: test_utility.py
...26 in_fnames = read_fnames("test_data/filenames.txt")27 true_fnames = ["test1", "test2", "filename3.txt", "ncfile.nc"]28 for in_fname, true_fname in zip(in_fnames, true_fnames):29 assert in_fname == true_fname30def test_delete_variable():31 fname = "./test_data/contains_extra_var.nc"32 ds = xr.load_dataset(fname)33 # Ensure ds initially contains the variable34 assert "crs" in ds35 # Ensure deleting works36 delete_variable(ds, "crs")37 assert "crs" not in ds38 # Ensure deleting a missing variable throws39 with pytest.raises(ValueError, match=f"Could not find crs in dataset"):...
Check out the latest blogs from LambdaTest on this topic:
In an ideal world, you can test your web application in the same test environment and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
If you pay close attention, you’ll notice that toggle switches are all around us because lots of things have two simple states: either ON or OFF (in binary 1 or 0).
With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
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!!