How to use patched_logger_debug method in molecule

Best Python code snippet using molecule_python

test_config.py

Source:test_config.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 pytest22from molecule import config23from molecule import platforms24from molecule import scenario25from molecule import state26from molecule import util27from molecule.dependency import ansible_galaxy28from molecule.dependency import gilt29from molecule.dependency import shell30from molecule.provisioner import ansible31from molecule.verifier.ansible import Ansible as AnsibleVerifier32def test_molecule_file_private_member(molecule_file_fixture, config_instance):33 assert molecule_file_fixture == config_instance.molecule_file34def test_args_member(config_instance):35 assert {} == config_instance.args36def test_command_args_member(config_instance):37 x = {"subcommand": "test"}38 assert x == config_instance.command_args39def test_debug_property(config_instance):40 assert not config_instance.debug41def test_env_file_property(config_instance):42 config_instance.args = {"env_file": ".env"}43 result = config_instance.env_file44 assert util.abs_path(config_instance.args.get("env_file")) == result45def test_subcommand_property(config_instance):46 assert "test" == config_instance.subcommand47def test_action_property(config_instance):48 assert config_instance.action is None49def test_action_setter(config_instance):50 config_instance.action = "foo"51 assert "foo" == config_instance.action52def test_init_calls_validate(patched_config_validate, config_instance):53 patched_config_validate.assert_called_once_with()54def test_project_directory_property(config_instance):55 assert os.getcwd() == config_instance.project_directory56def test_molecule_directory_property(config_instance):57 x = os.path.join(os.getcwd(), "molecule")58 assert x == config_instance.molecule_directory59def test_dependency_property(config_instance):60 assert isinstance(config_instance.dependency, ansible_galaxy.AnsibleGalaxy)61@pytest.fixture62def _config_dependency_gilt_section_data():63 return {"dependency": {"name": "gilt"}}64@pytest.mark.parametrize(65 "config_instance", ["_config_dependency_gilt_section_data"], indirect=True66)67def test_dependency_property_is_gilt(config_instance):68 assert isinstance(config_instance.dependency, gilt.Gilt)69@pytest.fixture70def _config_dependency_shell_section_data():71 return {"dependency": {"name": "shell", "command": "bin/command"}}72@pytest.mark.parametrize(73 "config_instance", ["_config_dependency_shell_section_data"], indirect=True74)75def test_dependency_property_is_shell(config_instance):76 assert isinstance(config_instance.dependency, shell.Shell)77@pytest.fixture78def _config_driver_delegated_section_data():79 return {"driver": {"name": "delegated", "options": {"managed": False}}}80def test_env(config_instance):81 config_instance.args = {"env_file": ".env"}82 x = {83 "MOLECULE_DEBUG": "False",84 "MOLECULE_FILE": config_instance.config_file,85 "MOLECULE_ENV_FILE": util.abs_path(config_instance.args.get("env_file")),86 "MOLECULE_INVENTORY_FILE": config_instance.provisioner.inventory_file,87 "MOLECULE_EPHEMERAL_DIRECTORY": config_instance.scenario.ephemeral_directory,88 "MOLECULE_SCENARIO_DIRECTORY": config_instance.scenario.directory,89 "MOLECULE_PROJECT_DIRECTORY": config_instance.project_directory,90 "MOLECULE_INSTANCE_CONFIG": config_instance.driver.instance_config,91 "MOLECULE_DEPENDENCY_NAME": "galaxy",92 "MOLECULE_DRIVER_NAME": "docker",93 "MOLECULE_PROVISIONER_NAME": "ansible",94 "MOLECULE_SCENARIO_NAME": "default",95 "MOLECULE_STATE_FILE": config_instance.state.state_file,96 "MOLECULE_VERIFIER_NAME": "ansible",97 "MOLECULE_VERIFIER_TEST_DIRECTORY": config_instance.verifier.directory,98 }99 assert x == config_instance.env100def test_lint_property(config_instance):101 assert isinstance(config_instance.lint, (str, bool, type(None)))102def test_platforms_property(config_instance):103 assert isinstance(config_instance.platforms, platforms.Platforms)104def test_provisioner_property(config_instance):105 assert isinstance(config_instance.provisioner, ansible.Ansible)106def test_scenario_property(config_instance):107 assert isinstance(config_instance.scenario, scenario.Scenario)108def test_state_property(config_instance):109 assert isinstance(config_instance.state, state.State)110def test_verifier_property_is_ansible(config_instance):111 assert isinstance(config_instance.verifier, AnsibleVerifier)112def test_get_driver_name_from_state_file(config_instance):113 config_instance.state.change_state("driver", "state-driver")114 assert "state-driver" == config_instance._get_driver_name()115def test_get_driver_name_from_cli(config_instance):116 config_instance.command_args = {"driver_name": "cli-driver"}117 assert "cli-driver" == config_instance._get_driver_name()118def test_get_driver_name(config_instance):119 assert "docker" == config_instance._get_driver_name()120def test_get_driver_name_raises_when_different_driver_used(121 patched_logger_critical, config_instance122):123 config_instance.state.change_state("driver", "foo")124 config_instance.command_args = {"driver_name": "bar"}125 with pytest.raises(SystemExit) as e:126 config_instance._get_driver_name()127 assert 1 == e.value.code128 msg = (129 "Instance(s) were created with the 'foo' driver, "130 "but the subcommand is using 'bar' driver."131 )132 patched_logger_critical.assert_called_once_with(msg)133def test_get_config(config_instance):134 assert isinstance(config_instance._get_config(), dict)135def test_get_config_with_base_config(config_instance):136 config_instance.args = {"base_config": "./foo.yml"}137 contents = {"foo": "bar"}138 util.write_file(config_instance.args["base_config"], util.safe_dump(contents))139 result = config_instance._get_config()140 assert result["foo"] == "bar"141def test_reget_config(config_instance):142 assert isinstance(config_instance._reget_config(), dict)143def test_interpolate(patched_logger_critical, config_instance):144 string = "foo: $HOME"145 x = "foo: {}".format(os.environ["HOME"])146 assert x == config_instance._interpolate(string, os.environ, None)147def test_interpolate_curly(patched_logger_critical, config_instance):148 string = "foo: ${HOME}"149 x = "foo: {}".format(os.environ["HOME"])150 assert x == config_instance._interpolate(string, os.environ, None)151def test_interpolate_default(patched_logger_critical, config_instance):152 string = "foo: ${NONE-default}"153 x = "foo: default"154 assert x == config_instance._interpolate(string, os.environ, None)155def test_interpolate_default_colon(patched_logger_critical, config_instance):156 string = "foo: ${NONE:-default}"157 x = "foo: default"158 assert x == config_instance._interpolate(string, os.environ, None)159def test_interpolate_default_variable(patched_logger_critical, config_instance):160 string = "foo: ${NONE:-$HOME}"161 x = "foo: {}".format(os.environ["HOME"])162 assert x == config_instance._interpolate(string, os.environ, None)163def test_interpolate_curly_default_variable(patched_logger_critical, config_instance):164 string = "foo: ${NONE-$HOME}"165 x = "foo: {}".format(os.environ["HOME"])166 assert x == config_instance._interpolate(string, os.environ, None)167def test_interpolate_raises_on_failed_interpolation(168 patched_logger_critical, config_instance169):170 string = "$6$8I5Cfmpr$kGZB"171 with pytest.raises(SystemExit) as e:172 config_instance._interpolate(string, os.environ, None)173 assert 1 == e.value.code174 msg = (175 "parsing config file '{}'.\n\n"176 "Invalid placeholder in string: line 1, col 1\n"177 "$6$8I5Cfmpr$kGZB"178 ).format(config_instance.molecule_file)179 patched_logger_critical.assert_called_once_with(msg)180def test_get_defaults(config_instance, mocker):181 mocker.patch.object(182 config_instance, "molecule_file", "/path/to/test_scenario_name/molecule.yml"183 )184 defaults = config_instance._get_defaults()185 assert defaults["scenario"]["name"] == "test_scenario_name"186def test_preflight(mocker, config_instance, patched_logger_info):187 m = mocker.patch("molecule.model.schema_v3.pre_validate")188 m.return_value = (None, None)189 config_instance._preflight("foo")190 m.assert_called_once_with("foo", os.environ, config.MOLECULE_KEEP_STRING)191def test_preflight_exists_when_validation_fails(192 mocker, patched_logger_critical, config_instance193):194 m = mocker.patch("molecule.model.schema_v3.pre_validate")195 m.return_value = ("validation errors", None)196 with pytest.raises(SystemExit) as e:197 config_instance._preflight("invalid stream")198 assert 1 == e.value.code199 msg = "Failed to pre-validate.\n\nvalidation errors"200 patched_logger_critical.assert_called_once_with(msg)201def test_validate(202 mocker, config_instance, patched_logger_debug, patched_logger_success203):204 m = mocker.patch("molecule.model.schema_v3.validate")205 m.return_value = None206 config_instance._validate()207 assert patched_logger_debug.call_count == 2208 m.assert_called_with(config_instance.config)209def test_validate_exists_when_validation_fails(210 mocker, patched_logger_critical, config_instance211):212 m = mocker.patch("molecule.model.schema_v3.validate")213 m.return_value = "validation errors"214 with pytest.raises(SystemExit) as e:215 config_instance._validate()216 assert 1 == e.value.code217 msg = "Failed to validate.\n\nvalidation errors"218 patched_logger_critical.assert_called_once_with(msg)219def test_molecule_directory():220 assert "/foo/bar/molecule" == config.molecule_directory("/foo/bar")221def test_molecule_file():222 assert "/foo/bar/molecule.yml" == config.molecule_file("/foo/bar")223def test_set_env_from_file(config_instance):224 config_instance.args = {"env_file": ".env"}225 contents = {"foo": "bar", "BAZ": "zzyzx"}226 env_file = config_instance.args.get("env_file")227 util.write_file(env_file, util.safe_dump(contents))228 env = config.set_env_from_file({}, env_file)229 assert contents == env230def test_set_env_from_file_returns_original_env_when_env_file_not_found(231 config_instance,232):233 env = config.set_env_from_file({}, "file-not-found")234 assert {} == env235def test_write_config(config_instance):236 config_instance.write()...

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