def test_promote_command_yes(mocker, legacy_run): mocker.patch.object( sys, "argv", [ "cmd", "promote", "name", "--from-channel", "edge", "--to-channel", "edge/foo", "--yes", ], ) cli.run() assert legacy_run.mock_calls == [ call( argparse.Namespace(snap_name="name", from_channel="edge", to_channel="edge/foo", yes=True)) ]
def test_lifecycle_command_arguments(cmd, run_method, mocker): mocker.patch.object( sys, "argv", [ "cmd", cmd, "part1", "part2", ], ) mock_lifecycle_cmd = mocker.patch(run_method) cli.run() assert mock_lifecycle_cmd.mock_calls == [ call( argparse.Namespace( parts=["part1", "part2"], debug=False, destructive_mode=False, shell=False, shell_after=False, use_lxd=False, enable_manifest=False, manifest_image_information=None, bind_ssh=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, )) ]
def test_lifecycle_command_pack_debug(mocker): mocker.patch.object( sys, "argv", ["cmd", "pack", "--debug"], ) mock_pack_cmd = mocker.patch( "snapcraft.commands.lifecycle.PackCommand.run") cli.run() assert mock_pack_cmd.mock_calls == [ call( argparse.Namespace( directory=None, output=None, debug=True, destructive_mode=False, use_lxd=False, enable_manifest=False, manifest_image_information=None, bind_ssh=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, )) ]
def test_lifecycle_command_pack_env_manifest_image_information(mocker): mocker.patch.dict(os.environ, {"SNAPCRAFT_IMAGE_INFO": "{'some-info': true}"}) mocker.patch.object( sys, "argv", ["cmd", "pack"], ) mock_pack_cmd = mocker.patch( "snapcraft.commands.lifecycle.PackCommand.run") cli.run() assert mock_pack_cmd.mock_calls == [ call( argparse.Namespace( directory=None, output=None, debug=False, destructive_mode=False, use_lxd=False, enable_manifest=False, manifest_image_information="{'some-info': true}", bind_ssh=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, )) ]
def test_no_keyring_error(capsys, mocker): mocker.patch.object(sys, "argv", ["cmd", "whoami"]) mock_version_cmd = mocker.patch( "snapcraft.commands.account.StoreWhoAmICommand.run", side_effect=craft_store.errors.NoKeyringError, ) cli.run() assert mock_version_cmd.mock_calls == [call(argparse.Namespace())] stderr = capsys.readouterr().err.splitlines() # Simple verification that our expected message is being printed assert stderr[0].startswith( "craft-store error: No keyring found to store or retrieve credentials") assert stderr[1].startswith( "Recommended resolution: Ensure the keyring is working or SNAPCRAFT_STORE_CREDENTIALS " ) assert stderr[2].startswith( "For more information, check out: https://snapcraft.io/docs/snapcraft-authentication" )
def test_version_argument_with_command(mocker, emitter): mocker.patch.object(sys, "argv", ["cmd", "--version", "version"]) cli.run() emitter.assert_message(f"snapcraft {__version__}")
def test_version_command(mocker): mocker.patch.object(sys, "argv", ["cmd", "version"]) mock_version_cmd = mocker.patch("snapcraft.commands.version.VersionCommand.run") cli.run() assert mock_version_cmd.mock_calls == [call(argparse.Namespace())]
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- # # Copyright 2022 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """Main entry point.""" import sys from snapcraft import cli sys.exit(cli.run())