Best Python code snippet using molecule_python
test_git.py
Source:test_git.py
...93 git.clone(name, repo, clone_dir)94 git.overlay(clone_dir, files, branch)95 assert 2 == len(glob.glob("{}/*".format(os.path.join(dst_dir, "tests"))))96@pytest.fixture()97def patched_run_command(mocker):98 return mocker.patch("gilt.util.run_command")99def test_get_version_has_branch(mocker, patched_run_command):100 mocker.patch("gilt.git._has_branch").return_value = True101 mocker.patch("gilt.git._has_tag").return_value = False102 mocker.patch("gilt.git._has_commit").return_value = False103 git._get_version("branch")104 expected = [105 mocker.call(sh.git.bake("checkout", "branch"), debug=False),106 mocker.call(sh.git.bake("clean", "-d", "-x", "-f"), debug=False),107 mocker.call(108 sh.git.bake("pull", rebase=True, ff_only=True), debug=False109 ),110 ]111 assert expected == patched_run_command.mock_calls...
test_gilt.py
Source:test_gilt.py
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 pytest22import sh23from molecule import config24from molecule.dependency import gilt25@pytest.fixture26def _patched_gilt_has_requirements_file(mocker):27 m = mocker.patch("molecule.dependency.gilt.Gilt._has_requirements_file")28 m.return_value = True29 return m30@pytest.fixture31def _dependency_section_data():32 return {33 "dependency": {"name": "gilt", "options": {"foo": "bar"}, "env": {"FOO": "bar"}}34 }35# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables36# config.Config._validate from executing. Thus preventing odd side-effects37# throughout patched.assert_called unit tests.38@pytest.fixture39def _instance(_dependency_section_data, patched_config_validate, config_instance):40 return gilt.Gilt(config_instance)41@pytest.fixture42def gilt_config(_instance):43 return os.path.join(_instance._config.scenario.directory, "gilt.yml")44def test_config_private_member(_instance):45 assert isinstance(_instance._config, config.Config)46def test_default_options_property(gilt_config, _instance):47 x = {"config": gilt_config}48 assert x == _instance.default_options49def test_default_env_property(_instance):50 assert "MOLECULE_FILE" in _instance.default_env51 assert "MOLECULE_INVENTORY_FILE" in _instance.default_env52 assert "MOLECULE_SCENARIO_DIRECTORY" in _instance.default_env53 assert "MOLECULE_INSTANCE_CONFIG" in _instance.default_env54@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)55def test_name_property(_instance):56 assert "gilt" == _instance.name57def test_enabled_property(_instance):58 assert _instance.enabled59@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)60def test_options_property(gilt_config, _instance):61 x = {"config": gilt_config, "foo": "bar"}62 assert x == _instance.options63@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)64def test_options_property_handles_cli_args(gilt_config, _instance):65 _instance._config.args = {"debug": True}66 x = {"config": gilt_config, "foo": "bar", "debug": True}67 assert x == _instance.options68@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)69def test_env_property(_instance):70 assert "bar" == _instance.env["FOO"]71@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)72def test_bake(gilt_config, _instance):73 _instance.bake()74 x = [str(sh.gilt), "--foo=bar", "--config={}".format(gilt_config), "overlay"]75 result = str(_instance._sh_command).split()76 assert sorted(x) == sorted(result)77def test_execute(78 patched_run_command,79 _patched_gilt_has_requirements_file,80 patched_logger_success,81 _instance,82):83 _instance._sh_command = "patched-command"84 _instance.execute()85 patched_run_command.assert_called_once_with("patched-command", debug=False)86 msg = "Dependency completed successfully."87 patched_logger_success.assert_called_once_with(msg)88def test_execute_does_not_execute_when_disabled(89 patched_run_command, patched_logger_warning, _instance90):91 _instance._config.config["dependency"]["enabled"] = False92 _instance.execute()93 assert not patched_run_command.called94 msg = "Skipping, dependency is disabled."95 patched_logger_warning.assert_called_once_with(msg)96def test_execute_does_not_execute_when_no_requirements_file(97 patched_run_command,98 _patched_gilt_has_requirements_file,99 patched_logger_warning,100 _instance,101):102 _patched_gilt_has_requirements_file.return_value = False103 _instance.execute()104 assert not patched_run_command.called105 msg = "Skipping, missing the requirements file."106 patched_logger_warning.assert_called_once_with(msg)107def test_execute_bakes(108 patched_run_command, gilt_config, _patched_gilt_has_requirements_file, _instance109):110 _instance.execute()111 assert _instance._sh_command is not None112 assert 1 == patched_run_command.call_count113def test_executes_catches_and_exits_return_code(114 patched_run_command, _patched_gilt_has_requirements_file, _instance115):116 patched_run_command.side_effect = sh.ErrorReturnCode_1(sh.gilt, b"", b"")117 with pytest.raises(SystemExit) as e:118 _instance.execute()119 assert 1 == e.value.code120def test_config_file(_instance, gilt_config):121 assert gilt_config == _instance._config_file()122def test_has_requirements_file(_instance):...
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!!