Best Python code snippet using pypom_form_python
stream_interface.py
Source:stream_interface.py
...40 }41 getter_factory, setter_factory = self._get_getter_and_setter_factories()42 for command_name, emulator_name in six.iteritems(numeric_get_and_set_commands):43 self.commands.update({44 CmdBuilder(setter_factory(emulator_name)).escape(command_name).int().escape(",").float().eos().build(),45 CmdBuilder(getter_factory(emulator_name)).escape("?{}".format(command_name)).int().eos().build(),46 })47 def _get_getter_and_setter_factories(self):48 """49 Returns a pair of functions (getter_factory, setter_factory) which can generate appropriate attribute getters50 and setters for a given property name.51 For example:52 >>> getter_factory("foo")53 will generate the getter accessing54 >>> self.device.channels[chan].foo55 where56 >>> chan57 is one of the captured arguments to the getter.58 Factory methods are used to force the functions to bind correctly.59 """60 def getter_factory(name):61 def getter(chan):62 if not self.device.connected:63 return None64 return "{:.2f}".format(getattr(self.device.channels[chan], name))65 return getter66 def setter_factory(name):67 def setter(chan, value):68 if not self.device.connected:69 return None70 setattr(self.device.channels[chan], name, value)71 return ""72 return setter73 return getter_factory, setter_factory74 in_terminator = "\r"75 out_terminator = "\r"76 def handle_error(self, request, error):77 err_string = "command was: {}, error was: {}: {}\n".format(request, error.__class__.__name__, error)78 print(err_string)79 self.log.error(err_string)80 return err_string...
test_models_setter.py
Source:test_models_setter.py
...37 self.__dict__["payload"] = self.name, attr, value38class TestModelsSetter(common.TestCase):39 @defer.inlineCallbacks40 def check_attr(self, ref, context, setter_factory, exp_name):41 setter = setter_factory("tata")42 yield setter(None, context)43 self.assertEqual(ref.payload, (exp_name, "tata", None))44 setter = setter_factory("toto")45 yield setter("spam", context)46 self.assertEqual(ref.payload, (exp_name, "toto", "spam"))47 setter = setter_factory("tutu")48 yield setter("spam", context, param="foo")49 self.assertEqual(ref.payload, (exp_name, "tutu", "spam"))50 @defer.inlineCallbacks51 def check_set(self, ref, context, setter_factory, exp_key, exp_name):52 setter = setter_factory("titi")53 yield setter(None, context)54 self.assertEqual(ref.payload, (exp_name, "titi",55 (exp_key, None), {}))56 setter = setter_factory("titi")57 yield setter("spam", context)58 self.assertEqual(ref.payload, (exp_name, "titi",59 (exp_key, "spam"), {}))60 setter = setter_factory("titi")61 yield setter("spam", context, foo="bar")62 self.assertEqual(ref.payload, (exp_name, "titi",63 (exp_key, "spam"), {}))64 @defer.inlineCallbacks65 def check_setattr(self, ref, context, setter_factory, exp_key, exp_name):66 setter = setter_factory()67 yield setter(None, context)68 self.assertEqual(ref.payload, (exp_name, exp_key, None))69 setter = setter_factory()70 yield setter("spam", context)71 self.assertEqual(ref.payload, (exp_name, exp_key, "spam"))72 setter = setter_factory()73 yield setter("spam", context, param="foo")74 self.assertEqual(ref.payload, (exp_name, exp_key, "spam"))75 @defer.inlineCallbacks76 def testAttr(self):77 source = DummyAttr("source")78 action = DummyAttr("action")79 model = DummyAttr("model", source)80 view = DummyAttr("view")81 context = {"model": model, "view": view, "action": action}82 yield self.check_attr(model, context, setter.model_attr, "model")83 yield self.check_attr(source, context, setter.source_attr, "source")84 yield self.check_attr(action, context, setter.action_attr, "action")85 yield self.check_attr(view, context, setter.view_attr, "view")86 @defer.inlineCallbacks...
__init__.py
Source:__init__.py
...18 raise plugin_api.InitializationError("missing auth key in config!")19 self.client = Client(f'http://{self.ip}:{self.port}', self.auth_key)20 self.printing = 021 # ---- Data ----22 self.set_tool_temp = core.storage.setter_factory("octo.tool.temp")23 self.set_tool_target = core.storage.setter_factory("octo.tool.target")24 self.set_bed_temp = core.storage.setter_factory("octo.bed.temp")25 self.set_bed_temp_target = core.storage.setter_factory("octo.bed.target")26 self.set_progress = core.storage.setter_factory("octo.progress")27 self.set_file = core.storage.setter_factory("octo.file")28 self.set_printing = core.storage.setter_factory("octo.printing")29 self.set_connection_state = core.storage.setter_factory("octo.serial.state")30 @plugin_api.output_service("octo.set_tool")31 async def set_tool(self, target: int, context: Context):32 await self.client.tool.set_temp(target)33 @plugin_api.output_service("octo.set_bed")34 async def set_tool(self, target: int, context: Context):35 await self.client.bed.set_temp(target)36 @plugin_api.output_service("octo.reconnect_serial")37 async def set_tool(self, _: None, context: Context):38 await self.client.connect()39 @plugin_api.poll_job(2)40 async def update(self):41 try:42 await self.client.refresh()43 self.set_tool_temp(self.client.tool.actual)...
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!!