How to use syntax_sequence method in molecule

Best Python code snippet using molecule_python

scenarios.py

Source:scenarios.py Github

copy

Full Screen

1# Copyright (c) 2015-2018 Cisco Systems, Inc.2#3# Permission is hereby granted, free of charge, to any person obtaining a copy4# of this software and associated documentation files (the "Software"), to5# deal in the Software without restriction, including without limitation the6# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or7# sell copies of the Software, and to permit persons to whom the Software is8# furnished to do so, subject to the following conditions:9#10# The above copyright notice and this permission notice shall be included in11# all copies or substantial portions of the Software.12#13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19# DEALINGS IN THE SOFTWARE.20"""Scenarios Module."""21import operator22import tree_format23from molecule import logger24from molecule import util25LOG = logger.get_logger(__name__)26class Scenarios(object):27 """The Scenarios object consists of one to many scenario objects Molecule will \28 execute."""29 def __init__(self, configs, scenario_name=None):30 """31 Initialize a new scenarios class and returns None.32 :param configs: A list containing Molecule config instances.33 :param scenario_name: A string containing the name of the scenario.34 :return: None35 """36 self._configs = configs37 self._scenario_name = scenario_name38 self._scenarios = self.all39 def next(self):40 if not self._scenarios:41 raise StopIteration42 return self._scenarios.pop(0)43 def __iter__(self):44 """Make object iterable."""45 return self46 __next__ = next # Python 3.X compatibility47 @property48 def all(self):49 """50 Return a list containing all scenario objects.51 :return: list52 """53 if self._scenario_name:54 scenarios = self._filter_for_scenario()55 self._verify()56 return scenarios57 scenarios = [c.scenario for c in self._configs]58 scenarios.sort(key=lambda x: x.directory)59 return scenarios60 def print_matrix(self):61 msg = "Test matrix"62 LOG.info(msg)63 tree = tuple(64 (65 "",66 [67 (scenario.name, [(action, []) for action in scenario.sequence])68 for scenario in self.all69 ],70 )71 )72 tf = tree_format.format_tree(73 tree,74 format_node=operator.itemgetter(0),75 get_children=operator.itemgetter(1),76 )77 LOG.out(tf)78 LOG.out("")79 def _verify(self):80 """81 Verify the specified scenario was found and returns None.82 :return: None83 """84 scenario_names = [c.scenario.name for c in self._configs]85 if self._scenario_name not in scenario_names:86 msg = ("Scenario '{}' not found. " "Exiting.").format(self._scenario_name)87 util.sysexit_with_message(msg)88 def _filter_for_scenario(self):89 """90 Find the scenario matching the provided scenario name and returns a \91 list.92 :return: list93 """94 return [95 c.scenario for c in self._configs if c.scenario.name == self._scenario_name96 ]97 def _get_matrix(self):98 """99 Build a matrix of scenarios with sequence to include and returns a \100 dict.101 {102 scenario_1: {103 'subcommand': [104 'action-1',105 'action-2',106 ],107 },108 scenario_2: {109 'subcommand': [110 'action-1',111 ],112 },113 }114 :returns: dict115 """116 return dict(117 {118 scenario.name: {119 "check": scenario.check_sequence,120 "cleanup": scenario.cleanup_sequence,121 "converge": scenario.converge_sequence,122 "create": scenario.create_sequence,123 "dependency": scenario.dependency_sequence,124 "destroy": scenario.destroy_sequence,125 "idempotence": scenario.idempotence_sequence,126 "lint": scenario.lint_sequence,127 "prepare": scenario.prepare_sequence,128 "side_effect": scenario.side_effect_sequence,129 "syntax": scenario.syntax_sequence,130 "test": scenario.test_sequence,131 "verify": scenario.verify_sequence,132 }133 for scenario in self.all134 }...

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