How to use dump_ivariants method in avocado

Best Python code snippet using avocado_python

varianter.py

Source:varianter.py Github

copy

Full Screen

...94 fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env])95 for record in sorted(env):96 out.append(fmt % record)97 return out98def dump_ivariants(ivariants):99 """100 Walks the iterable variants and dumps them into json-serializable object101 """102 def dump_tree_node(node):103 """104 Turns TreeNode-like object into tuple(path, env_representation)105 """106 return (astring.to_text(node.path),107 [(astring.to_text(node.environment.origin[key].path),108 astring.to_text(key), value)109 for key, value in node.environment.items()])110 variants = []111 for variant in ivariants():112 safe_variant = {}113 safe_variant["paths"] = [astring.to_text(pth)114 for pth in variant.get("paths")]115 safe_variant["variant_id"] = variant.get("variant_id")116 safe_variant["variant"] = [dump_tree_node(_)117 for _ in variant.get("variant", [])]118 variants.append(safe_variant)119 return variants120class FakeVariantDispatcher:121 """122 This object can act instead of VarianterDispatcher to report loaded123 variants.124 """125 def __init__(self, state):126 for variant in state:127 variant["variant"] = [tree.TreeNodeEnvOnly(path, env)128 for path, env in variant["variant"]]129 self.variants = state130 def map_method_with_return(self, method, *args, **kwargs):131 """132 Reports list containing one result of map_method on self133 """134 if hasattr(self, method):135 return [getattr(self, method)(*args, **kwargs)]136 else:137 return []138 def to_str(self, summary=0, variants=0, **kwargs): # pylint: disable=W0613139 if not self.variants:140 return ""141 out = []142 for variant in self.variants:143 paths = ', '.join([x.path for x in variant["variant"]])144 out.append('\nVariant %s: %s' % (variant["variant_id"],145 paths))146 env = set()147 for node in variant["variant"]:148 for key, value in node.environment.items():149 origin = node.environment.origin[key].path150 env.add(("%s:%s" % (origin, key), astring.to_text(value)))151 if not env:152 continue153 fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env])154 for record in sorted(env):155 out.append(fmt % record)156 return "\n".join(out)157 def __iter__(self):158 return iter(self.variants)159 def __len__(self):160 return sum(1 for _ in self)161class Varianter:162 """163 This object takes care of producing test variants164 """165 def __init__(self, debug=False, state=None):166 """167 :param debug: Store whether this instance should debug varianter168 :param state: Force-varianter state169 :note: it's necessary to check whether variants debug is enable170 in order to provide the right results.171 """172 if state is None:173 self.debug = debug174 self.node_class = tree.TreeNodeDebug if debug else tree.TreeNode175 self._variant_plugins = dispatcher.VarianterDispatcher()176 self._no_variants = None177 else:178 self.load(state)179 def parse(self, config):180 """181 Apply options defined on the cmdline and initialize the plugins.182 :param config: Configuration received from configuration files, command183 line parser, etc.184 :type config: dict185 """186 self._variant_plugins.map_method_with_return("initialize", config)187 self._no_variants = sum(self._variant_plugins.map_method_with_return("__len__"))188 def is_parsed(self):189 """190 Reports whether the varianter was already parsed191 """192 return self._no_variants is not None193 def to_str(self, summary=0, variants=0, **kwargs):194 """195 Return human readable representation196 The summary/variants accepts verbosity where 0 means do not display197 at all and maximum is up to the plugin.198 :param summary: How verbose summary to output (int)199 :param variants: How verbose list of variants to output (int)200 :param kwargs: Other free-form arguments201 :rtype: str202 """203 if self._no_variants == 0: # No variants204 return ""205 out = [item for item in self._variant_plugins.map_method_with_return("to_str",206 summary,207 variants,208 **kwargs)209 if item]210 return "\n\n".join(out)211 def get_number_of_tests(self, test_suite):212 """213 :return: overall number of tests * number of variants214 """215 # Currently number of tests is symmetrical216 if self._no_variants:217 return len(test_suite) * self._no_variants218 else:219 return len(test_suite)220 def dump(self):221 """222 Dump the variants in loadable-state223 This is lossy representation which takes all yielded variants and224 replaces the list of nodes with TreeNodeEnvOnly representations::225 [{'path': path,226 'variant_id': variant_id,227 'variant': dump_tree_nodes(original_variant)},228 {'path': [str, str, ...],229 'variant_id': str,230 'variant': [(str, [(str, str, object), ...])],231 {'path': ['/run/*'],232 'variant_id': 'cat-26c0'233 'variant': [('/pig/cat',234 [('/pig', 'ant', 'fox'),235 ('/pig/cat', 'dog', 'bee')])]}236 ...]237 where `dump_tree_nodes` looks like::238 [(node.path, environment_representation),239 (node.path, [(path1, key1, value1), (path2, key2, value2), ...]),240 ('/pig/cat', [('/pig', 'ant', 'fox')])241 :return: loadable Varianter representation242 """243 if not self.is_parsed():244 raise NotImplementedError("Dumping Varianter state before "245 "multiplexation is not supported.")246 return dump_ivariants(self.itertests)247 def load(self, state):248 """249 Load the variants state250 Current implementation supports loading from a list of loadable251 variants. It replaces the VariantDispatcher with fake implementation252 which reports the loaded (and initialized) variants.253 :param state: loadable Varianter representation254 """255 self.debug = False256 self.node_class = tree.TreeNode257 self._variant_plugins = FakeVariantDispatcher(state)258 self._no_variants = sum(self._variant_plugins.map_method_with_return("__len__"))259 def itertests(self):260 """...

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