How to use generate_run_function method in avocado

Best Python code snippet using avocado_python

service.py

Source:service.py Github

copy

Full Screen

...367 :type run: function368 """369 for cmd in service_command_generator.commands:370 setattr(self, cmd,371 self.generate_run_function(run,372 getattr(service_result_parser, cmd),373 getattr(service_command_generator, cmd),374 service_name))375 @staticmethod376 def generate_run_function(run_func, parse_func, command, service_name):377 """378 Generate the wrapped call to utils.run for the given service_name.379 :param run_func: function to execute command and return CmdResult object.380 :type run_func: function381 :param parse_func: function to parse the result from run.382 :type parse_func: function383 :param command: partial function that generates the command list384 :type command: function385 :param service_name: init service name or systemd unit name386 :type service_name: str387 :return: wrapped utils.run function.388 :rtype: function389 """390 def run(**kwargs):391 """392 Wrapped utils.run invocation that will start, stop, restart, etc. a service.393 :param kwargs: extra arguments to utils.run, .e.g. timeout. But not for ignore_status.394 We need a CmdResult to parse and raise a error.TestError if command failed.395 We will not let the CmdError out.396 :return: result of parse_func.397 """398 # If run_func is utils.run by default, we need to set399 # ignore_status = True. Otherwise, skip this setting.400 if run_func is utils.run:401 logging.debug("Setting ignore_status to True.")402 kwargs["ignore_status"] = True403 result = run_func(" ".join(command(service_name)), **kwargs)404 return parse_func(result)405 return run406class _GenericServiceManager(object):407 """408 Base class for SysVInitServiceManager and SystemdServiceManager.409 """410 def __init__(self, service_command_generator, service_result_parser, run=utils.run):411 """412 Create staticmethods for each service command, e.g. start, stop, restart.413 These staticmethods take as an argument the service to be started or stopped.414 systemd = SpecificServiceManager(auto_create_specific_service_command_generator())415 systemd.start("lldpad")416 systemd.stop("lldpad")417 :param service_command_generator: a sys_v_init or systemd command generator418 :type service_command_generator: _ServiceCommandGenerator419 :param run: function to call the run the commands, default utils.run420 :type run: function421 """422 # create staticmethods in class attributes (not used)423 # for cmd in service_command_generator.commands:424 # setattr(self.__class__, cmd,425 # staticmethod(self.generate_run_function(run, getattr(service_command_generator, cmd))))426 # create functions in instance attributes427 for cmd in service_command_generator.commands:428 setattr(self, cmd,429 self.generate_run_function(run,430 getattr(service_result_parser, cmd),431 getattr(service_command_generator, cmd)))432 @staticmethod433 def generate_run_function(run_func, parse_func, command):434 """435 Generate the wrapped call to utils.run for the service command, "service" or "systemctl"436 :param run_func: utils.run437 :type run_func: function438 :param command: partial function that generates the command list439 :type command: function440 :return: wrapped utils.run function.441 :rtype: function442 """443 def run(service="", **kwargs):444 """445 Wrapped utils.run invocation that will start, stop, restart, etc. a service.446 :param service: service name, e.g. crond, dbus, etc.447 :param kwargs: extra arguments to utils.run, .e.g. timeout. But not for ignore_status....

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