How to use lint_sequence method in molecule

Best Python code snippet using molecule_python

test_scenario.py

Source:test_scenario.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.20import os21import shutil22import pytest23from molecule import config24from molecule import scenario25from molecule import util26# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables27# config.Config._validate from executing. Thus preventing odd side-effects28# throughout patched.assert_called unit tests.29@pytest.fixture30def _instance(patched_config_validate, config_instance):31 return scenario.Scenario(config_instance)32def test_prune(_instance):33 e_dir = _instance.ephemeral_directory34 # prune data also includes files in the scenario inventory dir,35 # which is "<e_dir>/inventory" by default.36 # items are created in listed order, directories first, safe before pruned37 prune_data = {38 # these files should not be pruned39 "safe_files": ["state.yml", "ansible.cfg", "inventory/ansible_inventory.yml"],40 # these directories should not be pruned41 "safe_dirs": ["inventory"],42 # these files should be pruned43 "pruned_files": ["foo", "bar", "inventory/foo", "inventory/bar"],44 # these directories should be pruned, including empty subdirectories45 "pruned_dirs": ["baz", "roles", "inventory/baz", "roles/foo"],46 }47 for directory in prune_data["safe_dirs"] + prune_data["pruned_dirs"]:48 # inventory dir should already exist, and its existence is49 # required by the assertions below.50 if directory == "inventory":51 continue52 os.mkdir(os.path.join(e_dir, directory))53 for file in prune_data["safe_files"] + prune_data["pruned_files"]:54 util.write_file(os.path.join(e_dir, file), "")55 _instance.prune()56 for safe_file in prune_data["safe_files"]:57 assert os.path.isfile(os.path.join(e_dir, safe_file))58 for safe_dir in prune_data["safe_dirs"]:59 assert os.path.isdir(os.path.join(e_dir, safe_dir))60 for pruned_file in prune_data["pruned_files"]:61 assert not os.path.isfile(os.path.join(e_dir, pruned_file))62 for pruned_dir in prune_data["pruned_dirs"]:63 assert not os.path.isdir(os.path.join(e_dir, pruned_dir))64def test_config_member(_instance):65 assert isinstance(_instance.config, config.Config)66def test_init_calls_setup(patched_scenario_setup, _instance):67 patched_scenario_setup.assert_called_once_with()68def test_name_property(_instance):69 assert "default" == _instance.name70def test_directory_property(molecule_scenario_directory_fixture, _instance):71 assert molecule_scenario_directory_fixture == _instance.directory72def test_ephemeral_directory_property(_instance):73 assert os.access(_instance.ephemeral_directory, os.W_OK)74def test_inventory_directory_property(_instance):75 ephemeral_directory = _instance.config.scenario.ephemeral_directory76 e_dir = os.path.join(ephemeral_directory, "inventory")77 assert e_dir == _instance.inventory_directory78def test_check_sequence_property(_instance):79 sequence = [80 "dependency",81 "cleanup",82 "destroy",83 "create",84 "prepare",85 "converge",86 "check",87 "cleanup",88 "destroy",89 ]90 assert sequence == _instance.check_sequence91def test_converge_sequence_property(_instance):92 sequence = ["dependency", "create", "prepare", "converge"]93 assert sequence == _instance.converge_sequence94def test_create_sequence_property(_instance):95 sequence = ["dependency", "create", "prepare"]96 assert sequence == _instance.create_sequence97def test_dependency_sequence_property(_instance):98 assert ["dependency"] == _instance.dependency_sequence99def test_destroy_sequence_property(_instance):100 assert ["dependency", "cleanup", "destroy"] == _instance.destroy_sequence101def test_idempotence_sequence_property(_instance):102 assert ["idempotence"] == _instance.idempotence_sequence103def test_lint_sequence_property(_instance):104 assert "lint" in _instance.lint_sequence105 assert "dependency" in _instance.lint_sequence106def test_prepare_sequence_property(_instance):107 assert ["prepare"] == _instance.prepare_sequence108def test_side_effect_sequence_property(_instance):109 assert ["side_effect"] == _instance.side_effect_sequence110def test_syntax_sequence_property(_instance):111 assert ["syntax"] == _instance.syntax_sequence112def test_test_sequence_property(_instance):113 sequence = [114 "dependency",115 "lint",116 "cleanup",117 "destroy",118 "syntax",119 "create",120 "prepare",121 "converge",122 "idempotence",123 "side_effect",124 "verify",125 "cleanup",126 "destroy",127 ]128 assert sequence == _instance.test_sequence129def test_verify_sequence_property(_instance):130 assert ["verify"] == _instance.verify_sequence131def test_sequence_property(_instance):132 assert "lint" in _instance.sequence133def test_sequence_property_with_invalid_subcommand(_instance):134 _instance.config.command_args = {"subcommand": "invalid"}135 assert [] == _instance.sequence136def test_setup_creates_ephemeral_and_inventory_directories(_instance):137 ephemeral_dir = _instance.config.scenario.ephemeral_directory138 inventory_dir = _instance.config.scenario.inventory_directory139 shutil.rmtree(ephemeral_dir)140 _instance._setup()141 assert os.path.isdir(ephemeral_dir)142 assert os.path.isdir(inventory_dir)143def test_ephemeral_directory():144 # assure we can write to ephemeral directory145 assert os.access(scenario.ephemeral_directory("foo/bar"), os.W_OK)146def test_ephemeral_directory_OVERRIDDEN_via_env_var(monkeypatch):147 monkeypatch.setenv("MOLECULE_EPHEMERAL_DIRECTORY", "foo/bar")148 assert os.access(scenario.ephemeral_directory("foo/bar"), os.W_OK)149def test_ephemeral_directory_OVERRIDDEN_via_env_var_uses_absolute_path(monkeypatch):150 monkeypatch.setenv("MOLECULE_EPHEMERAL_DIRECTORY", "foo/bar")...

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