How to use filter_runnable_config method in avocado

Best Python code snippet using avocado_python

runnable.py

Source:runnable.py Github

copy

Full Screen

...51 execute a runnable.52 """53 def __init__(self, kind, uri, *args, config=None, **kwargs):54 if config is None:55 config = self.filter_runnable_config(kind, {})56 self.kind = kind57 #: The main reference to what needs to be run. This is free58 #: form, but commonly set to the path to a file containing the59 #: test or being the test, or an actual URI with multiple60 #: parts61 self.uri = uri62 #: This attributes holds configuration from Avocado proper63 #: that is passed to runners, as long as a runner declares64 #: its interest in using them with65 #: attr:`avocado.core.nrunner.runner.BaseRunner.CONFIGURATION_USED`66 self._config = {}67 self.config = config or {}68 self.args = args69 self.tags = kwargs.pop("tags", None)70 self.dependencies = kwargs.pop("dependencies", None)71 self.variant = kwargs.pop("variant", None)72 self.output_dir = kwargs.pop("output_dir", None)73 self.kwargs = kwargs74 self._identifier_format = config.get("runner.identifier_format", "{uri}")75 def __repr__(self):76 fmt = (77 '<Runnable kind="{}" uri="{}" config="{}" args="{}" '78 'kwargs="{}" tags="{}" dependencies="{}"> variant="{}"'79 )80 return fmt.format(81 self.kind,82 self.uri,83 self.config,84 self.args,85 self.kwargs,86 self.tags,87 self.dependencies,88 self.variant,89 )90 @property91 def identifier(self):92 """Runnable identifier respecting user's format string.93 This is still experimental and we have room for improvements.94 This property it will return an unique identifier for this runnable.95 Please use this property in order to respect user's customization.96 By default runnables has its '{uri}' as identifier.97 Custom formatter can be configured and currently we accept the98 following values as normal f-strings replacements: {uri}, {args},99 and {kwargs}. "args" and "kwargs" are special cases.100 For args, since it is a list, you can use in two different ways:101 "{args}" for the entire list, or "{args[n]}" for a specific element102 inside this list. The same is valid when using "{kwargs}". With103 kwargs, since it is a dictionary, you have to specify a key as index104 and then the values are used. For instance if you have a kwargs value105 named 'DEBUG', a valid usage could be: "{kwargs[DEBUG]}" and this will106 print the current value to this variable (i.e: True or False).107 Since this is formatter, combined values can be used. Example:108 "{uri}-{args}".109 """110 fmt = self._identifier_format111 # For the cases where there is no config (when calling the Runnable112 # directly113 if not fmt:114 return self.uri115 # For args we can use the entire list of arguments or with a specific116 # index.117 args = "-".join(self.args)118 if "args" in fmt and "[" in fmt:119 args = self.args120 # For kwargs we can use the entire list of values or with a specific121 # index.122 kwargs = "-".join(self.kwargs.values())123 if "kwargs" in fmt and "[" in fmt:124 kwargs = self.kwargs125 options = {"uri": self.uri, "args": args, "kwargs": kwargs}126 return fmt.format(**options)127 @property128 def config(self):129 return self._config130 @config.setter131 def config(self, config):132 """Sets the config values based on the runnable kind.133 This is not avocado config, it is a runnable config which is a subset134 of avocado config based on `STANDALONE_EXECUTABLE_CONFIG_USED` which135 describes essential configuration values for each runner kind.136 :param config: A config dict with new values for Runnable.137 :type config: dict138 """139 command = self.pick_runner_command(self.kind)140 if command is not None:141 command = " ".join(command)142 configuration_used = STANDALONE_EXECUTABLE_CONFIG_USED.get(command)143 if not set(configuration_used).issubset(set(config.keys())):144 LOG.warning(145 "The runnable config should have only values "146 "essential for its runner. In the next version of "147 "avocado, this will raise a Value Error. Please "148 "use avocado.core.nrunner.runnable.Runnable.filter_runnable_config "149 "or avocado.core.nrunner.runnable.Runnable.from_avocado_config"150 )151 self._config = config152 @classmethod153 def from_args(cls, args):154 """Returns a runnable from arguments"""155 decoded_args = [_arg_decode_base64(arg) for arg in args.get("arg", ())]156 return cls.from_avocado_config(157 args.get("kind"),158 args.get("uri"),159 *decoded_args,160 config=json.loads(args.get("config", "{}"), cls=ConfigDecoder),161 **_key_val_args_to_kwargs(args.get("kwargs", [])),162 )163 @classmethod164 def from_recipe(cls, recipe_path):165 """166 Returns a runnable from a runnable recipe file167 :param recipe_path: Path to a recipe file168 :rtype: instance of :class:`Runnable`169 """170 with open(recipe_path, encoding="utf-8") as recipe_file:171 recipe = json.load(recipe_file)172 config = ConfigDecoder.decode_set(recipe.get("config", {}))173 return cls.from_avocado_config(174 recipe.get("kind"),175 recipe.get("uri"),176 *recipe.get("args", ()),177 config=config,178 **recipe.get("kwargs", {}),179 )180 @classmethod181 def from_avocado_config(cls, kind, uri, *args, config=None, **kwargs):182 """Creates runnable with only essential config for runner of specific kind."""183 if not config:184 config = {}185 config = cls.filter_runnable_config(kind, config)186 return cls(kind, uri, *args, config=config, **kwargs)187 @staticmethod188 def filter_runnable_config(kind, config):189 """190 Returns only essential values for specific runner.191 It will use configuration from argument completed by values from192 config file and avocado default configuration.193 :param kind: Kind of runner which should use the configuration.194 :type kind: str195 :param config: Configuration values for runner. If some values will be196 missing the default ones and from config file will be197 used.198 :type config: dict199 :returns: Config dict, which has only values essential for runner200 based on STANDALONE_EXECUTABLE_CONFIG_USED201 :rtype: dict202 """...

Full Screen

Full Screen

runner_nrunner.py

Source:runner_nrunner.py Github

copy

Full Screen

...258 :param config: A config dict to be used on the desired test suite.259 :type config: dict260 """261 for runnable in runnables:262 runnable.config = Runnable.filter_runnable_config(runnable.kind, config)263 def _determine_status_server(self, test_suite, config_key):264 if test_suite.config.get("nrunner.status_server_auto"):265 # no UNIX domain sockets on Windows266 if platform.system() != "Windows":267 if self.status_server_dir is None:268 self.status_server_dir = tempfile.TemporaryDirectory(269 prefix="avocado_"270 )271 return os.path.join(self.status_server_dir.name, ".status_server.sock")272 return test_suite.config.get(config_key)273 def _create_status_server(self, test_suite, job):274 listen = self._determine_status_server(275 test_suite, "nrunner.status_server_listen"276 )...

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