Best Python code snippet using avocado_python
varianter.py
Source:varianter.py  
...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        """261        Yields all variants of all plugins262        The variant is defined as dictionary with at least:263         * variant_id - name of the current variant264         * variant - AvocadoParams-compatible variant (usually a list of265                     TreeNodes but dict or simply None are also possible266                     values)267         * paths - default path(s)268        :yield variant269        """270        if self._no_variants:  # Copy template and modify it's params271            plugins_variants = self._variant_plugins.map_method_with_return("__iter__")272            iter_variants = (variant273                             for plugin_variants in plugins_variants274                             for variant in plugin_variants)275            for variant in iter(iter_variants):276                yield variant277        else:   # No real variants, but currently *something* needs to be returned278            yield {"variant": self.node_class('').get_leaves(),279                   "variant_id": None,280                   "paths": ["/run/*"]}281    @classmethod282    def from_resultsdir(cls, resultsdir):283        """284        Retrieves the job variants objects from the results directory.285        This will return a list of variants since a Job can have multiple...dispatcher.py
Source:dispatcher.py  
...67        TODO: Replace this with per-plugin-refresh-mechanism68        """69        self.__init__()70        self.extensions = state.get("extensions")71    def map_method_with_return(self, method_name, *args, **kwargs):72        return super(VarianterDispatcher, self).map_method_with_return(73            method_name, deepcopy=False, *args, **kwargs)74    def map_method_with_return_copy(self, method_name, *args, **kwargs):75        """76        The same as map_method_with_return, but use copy.deepcopy on each passed arg77        """78        return super(VarianterDispatcher, self).map_method_with_return(79            method_name, deepcopy=True, *args, **kwargs)80class RunnerDispatcher(EnabledExtensionManager):81    def __init__(self):82        super(RunnerDispatcher, self).__init__('avocado.plugins.runner')83class InitDispatcher(EnabledExtensionManager):84    def __init__(self):85        super(InitDispatcher, self).__init__('avocado.plugins.init')86class SpawnerDispatcher(EnabledExtensionManager):87    def __init__(self, config=None):88        super(SpawnerDispatcher, self).__init__('avocado.plugins.spawner',...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!!
