diff --git a/tests/unit/commands/test_remote.py b/tests/unit/commands/test_remote.py index 269604dbfc8..8fb3e5bd163 100644 --- a/tests/unit/commands/test_remote.py +++ b/tests/unit/commands/test_remote.py @@ -42,8 +42,8 @@ def create_snapcraft_yaml(request, snapcraft_yaml): @pytest.fixture() -def use_new_remote_build(monkeypatch): - """Fixture to force using the new remote-build code.""" +def use_core22_remote_build(monkeypatch): + """Fixture to force using the core22 remote-build code.""" monkeypatch.setenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", "disable-fallback") @@ -61,6 +61,13 @@ def mock_argv(mocker): @pytest.fixture() def mock_confirm(mocker): + return mocker.patch( + "snapcraft.commands.remote.confirm_with_user", return_value=True + ) + + +@pytest.fixture() +def mock_core22_confirm(mocker): return mocker.patch( "snapcraft.commands.core22.remote.confirm_with_user", return_value=True ) @@ -76,14 +83,30 @@ def mock_remote_builder(mocker): @pytest.fixture() -def mock_run_new_or_fallback_remote_build(mocker): +def mock_core22_remote_builder(mocker): + _mock_remote_builder = mocker.patch( + "snapcraft.commands.core22.remote.RemoteBuilder" + ) + _mock_remote_builder.return_value.has_outstanding_build.return_value = False + return _mock_remote_builder + + +@pytest.fixture() +def mock_run_core22_or_fallback_remote_build(mocker): return mocker.patch( "snapcraft.commands.core22.remote.RemoteBuildCommand._run_new_or_fallback_remote_build" ) @pytest.fixture() -def mock_run_new_remote_build(mocker): +def mock_run_remote_build(mocker): + return mocker.patch( + "craft_application.services.remotebuild.RemoteBuildService.start_builds" + ) + + +@pytest.fixture() +def mock_run_core22_remote_build(mocker): return mocker.patch( "snapcraft.commands.core22.remote.RemoteBuildCommand._run_new_remote_build" ) @@ -103,28 +126,28 @@ def mock_run_legacy(mocker): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures("create_snapcraft_yaml", "mock_argv") -def test_command_user_confirms_upload( - mock_confirm, mock_run_new_or_fallback_remote_build +def test_command_user_confirms_upload_core22( + mock_core22_confirm, mock_run_core22_or_fallback_remote_build ): """Run remote-build if the user confirms the upload prompt.""" cli.run() - mock_confirm.assert_called_once_with( + mock_core22_confirm.assert_called_once_with( "All data sent to remote builders will be publicly available. " "Are you sure you want to continue?" ) - mock_run_new_or_fallback_remote_build.assert_called_once() + mock_run_core22_or_fallback_remote_build.assert_called_once() @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures("create_snapcraft_yaml", "mock_argv") -def test_command_user_denies_upload( - capsys, mock_confirm, mock_run_new_or_fallback_remote_build +def test_command_user_denies_upload_core22( + capsys, mock_core22_confirm, mock_run_core22_or_fallback_remote_build ): """Raise an error if the user denies the upload prompt.""" - mock_confirm.return_value = False + mock_core22_confirm.return_value = False cli.run() @@ -140,8 +163,8 @@ def test_command_user_denies_upload( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures("create_snapcraft_yaml") -def test_command_accept_upload( - mock_confirm, mock_run_new_or_fallback_remote_build, mocker +def test_command_accept_upload_core22( + mock_core22_confirm, mock_run_core22_or_fallback_remote_build, mocker ): """Do not prompt user if `--launchpad-accept-public-upload` is provided.""" mocker.patch.object( @@ -150,17 +173,17 @@ def test_command_accept_upload( cli.run() - mock_confirm.assert_not_called() - mock_run_new_or_fallback_remote_build.assert_called_once() + mock_core22_confirm.assert_not_called() + mock_run_core22_or_fallback_remote_build.assert_called_once() @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_command_new_build_arguments_mutually_exclusive(capsys, mocker): +def test_command_new_build_arguments_mutually_exclusive_core22(capsys, mocker): """`--build-for` and `--build-on` are mutually exclusive in the new remote-build.""" mocker.patch.object( sys, @@ -177,8 +200,10 @@ def test_command_new_build_arguments_mutually_exclusive(capsys, mocker): @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm") -def test_command_legacy_build_arguments_not_mutually_exclusive(mocker, mock_run_legacy): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm") +def test_command_legacy_build_arguments_not_mutually_exclusive_core22( + mocker, mock_run_legacy +): """`--build-for` and `--build-on` are not mutually exclusive for legacy.""" mocker.patch.object( sys, @@ -194,9 +219,9 @@ def test_command_legacy_build_arguments_not_mutually_exclusive(mocker, mock_run_ @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm") -def test_command_build_on_warning( - emitter, mocker, mock_run_new_or_fallback_remote_build +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm") +def test_command_build_on_warning_core22( + emitter, mocker, mock_run_core22_or_fallback_remote_build ): """Warn when `--build-on` is passed.""" mocker.patch.object( @@ -206,27 +231,29 @@ def test_command_build_on_warning( cli.run() emitter.assert_message("Use --build-for instead of --build-on") - mock_run_new_or_fallback_remote_build.assert_called_once() + mock_run_core22_or_fallback_remote_build.assert_called_once() @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "fake_sudo", "mock_argv" + "create_snapcraft_yaml", "mock_core22_confirm", "fake_sudo", "mock_argv" ) -def test_remote_build_sudo_warns(emitter, mock_run_new_or_fallback_remote_build): +def test_remote_build_sudo_warns_core22( + emitter, mock_run_core22_or_fallback_remote_build +): """Warn when snapcraft is run with sudo.""" cli.run() emitter.assert_message( "Running with 'sudo' may cause permission errors and is discouraged." ) - mock_run_new_or_fallback_remote_build.assert_called_once() + mock_run_core22_or_fallback_remote_build.assert_called_once() -@pytest.mark.usefixtures("mock_argv", "mock_confirm") -def test_cannot_load_snapcraft_yaml(capsys): +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") +def test_cannot_load_snapcraft_yaml_core22(capsys): """Raise an error if the snapcraft.yaml does not exist.""" cli.run() @@ -241,13 +268,16 @@ def test_cannot_load_snapcraft_yaml(capsys): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build", "mock_argv" + "create_snapcraft_yaml", + "mock_core22_confirm", + "use_core22_remote_build", + "mock_argv", ) -def test_launchpad_timeout_default(mock_remote_builder): +def test_launchpad_timeout_default_core22(mock_core22_remote_builder): """Use the default timeout `0` when `--launchpad-timeout` is not provided.""" cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -261,9 +291,9 @@ def test_launchpad_timeout_default(mock_remote_builder): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_launchpad_timeout(mocker, mock_remote_builder): +def test_launchpad_timeout_core22(mocker, mock_core22_remote_builder): """Pass the `--launchpad-timeout` to the remote builder.""" mocker.patch.object( sys, "argv", ["snapcraft", "remote-build", "--launchpad-timeout", "100"] @@ -271,7 +301,7 @@ def test_launchpad_timeout(mocker, mock_remote_builder): cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -281,25 +311,25 @@ def test_launchpad_timeout(mocker, mock_remote_builder): ) -################################ -# Snapcraft project base tests # -################################ +######################################################### +# Snapcraft project base tests (no effect since core24) # +######################################################### -@pytest.mark.usefixtures("mock_argv", "mock_confirm") +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") @pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES) -def test_get_effective_base( - base, snapcraft_yaml, mock_run_new_or_fallback_remote_build +def test_get_effective_base_core22( + base, snapcraft_yaml, mock_run_core22_or_fallback_remote_build ): """Get the base from a snapcraft.yaml file.""" snapcraft_yaml(base=base) cli.run() - mock_run_new_or_fallback_remote_build.assert_called_once_with(base) + mock_run_core22_or_fallback_remote_build.assert_called_once_with(base) -@pytest.mark.usefixtures("mock_argv", "mock_confirm") +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") @pytest.mark.parametrize( ("base", "build_base"), [ @@ -308,8 +338,8 @@ def test_get_effective_base( ("bare", "core22"), ], ) -def test_get_effective_base_with_build_base( - base, build_base, snapcraft_yaml, mock_run_new_or_fallback_remote_build +def test_get_effective_base_with_build_base_core22( + base, build_base, snapcraft_yaml, mock_run_core22_or_fallback_remote_build ): """The effective base should be the build-base, when provided.""" snapcraft_yaml(**{"base": base, "build-base": build_base}) @@ -317,26 +347,26 @@ def test_get_effective_base_with_build_base( cli.run() if build_base == "devel": - mock_run_new_or_fallback_remote_build.assert_called_once_with(base) + mock_run_core22_or_fallback_remote_build.assert_called_once_with(base) else: - mock_run_new_or_fallback_remote_build.assert_called_once_with(build_base) + mock_run_core22_or_fallback_remote_build.assert_called_once_with(build_base) -@pytest.mark.usefixtures("mock_argv", "mock_confirm") +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") @pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES | ESM_BASES) -def test_get_effective_base_type( - base, snapcraft_yaml, mock_run_new_or_fallback_remote_build +def test_get_effective_base_type_core22( + base, snapcraft_yaml, mock_run_core22_or_fallback_remote_build ): """The effective base should be the name when building a base.""" snapcraft_yaml(**{"base": base, "name": base, "type": "base"}) cli.run() - mock_run_new_or_fallback_remote_build.assert_called_once_with(base) + mock_run_core22_or_fallback_remote_build.assert_called_once_with(base) -@pytest.mark.usefixtures("mock_argv", "mock_confirm") -def test_get_effective_base_unknown(capsys, snapcraft_yaml): +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") +def test_get_effective_base_unknown_core22(capsys, snapcraft_yaml): """Raise an error for unknown bases.""" snapcraft_yaml(base="core10") @@ -346,8 +376,8 @@ def test_get_effective_base_unknown(capsys, snapcraft_yaml): assert "Unknown base 'core10' in 'snap/snapcraft.yaml'." in err -@pytest.mark.usefixtures("mock_argv", "mock_confirm") -def test_get_effective_base_none(capsys, snapcraft_yaml): +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") +def test_get_effective_base_none_core22(capsys, snapcraft_yaml): """Raise an error if there is no base in the snapcraft.yaml.""" snapcraft_yaml() @@ -357,16 +387,16 @@ def test_get_effective_base_none(capsys, snapcraft_yaml): assert "Could not determine base from 'snap/snapcraft.yaml'." in err -@pytest.mark.usefixtures("mock_argv", "mock_confirm") -def test_get_effective_base_core_esm_warning( - emitter, snapcraft_yaml, mock_run_new_or_fallback_remote_build +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") +def test_get_effective_base_core_esm_warning_core22( + emitter, snapcraft_yaml, mock_run_core22_or_fallback_remote_build ): """Warn if core, an ESM base, is used.""" snapcraft_yaml(base="core") cli.run() - mock_run_new_or_fallback_remote_build.assert_called_once_with("core") + mock_run_core22_or_fallback_remote_build.assert_called_once_with("core") emitter.assert_progress( "WARNING: base 'core' was last supported on Snapcraft 4 available on the " "'4.x' channel.", @@ -374,16 +404,16 @@ def test_get_effective_base_core_esm_warning( ) -@pytest.mark.usefixtures("mock_argv", "mock_confirm") -def test_get_effective_base_core18_esm_warning( - emitter, snapcraft_yaml, mock_run_new_or_fallback_remote_build +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm") +def test_get_effective_base_core18_esm_warning_core22( + emitter, snapcraft_yaml, mock_run_core22_or_fallback_remote_build ): """Warn if core18, an ESM base, is used.""" snapcraft_yaml(base="core18") cli.run() - mock_run_new_or_fallback_remote_build.assert_called_once_with("core18") + mock_run_core22_or_fallback_remote_build.assert_called_once_with("core18") emitter.assert_progress( "WARNING: base 'core18' was last supported on Snapcraft 7 available on the " "'7.x' channel.", @@ -399,19 +429,19 @@ def test_get_effective_base_core18_esm_warning( @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES - {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_newer_than_core_22(emitter, mock_run_new_remote_build): - """Bases newer than core22 must use new remote-build.""" +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_core22(emitter, mock_run_core22_remote_build): + """Bases that is core22 must use core22 remote-build.""" cli.run() - mock_run_new_remote_build.assert_called_once() + mock_run_core22_remote_build.assert_called_once() emitter.assert_debug("Running new remote-build because base is newer than core22") @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") def test_run_core22_and_older(emitter, mock_run_legacy): """core22 and older bases can use fallback remote-build.""" cli.run() @@ -426,9 +456,9 @@ def test_run_core22_and_older(emitter, mock_run_legacy): @pytest.mark.parametrize( "envvar", ["force-fallback", "disable-fallback", "badvalue", None] ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") def test_run_envvar_newer_than_core22( - envvar, emitter, mock_run_new_remote_build, monkeypatch + envvar, emitter, mock_run_core22_remote_build, monkeypatch ): """Bases newer than core22 run new remote-build regardless of envvar.""" if envvar: @@ -438,21 +468,23 @@ def test_run_envvar_newer_than_core22( cli.run() - mock_run_new_remote_build.assert_called_once() + mock_run_core22_remote_build.assert_called_once() emitter.assert_debug("Running new remote-build because base is newer than core22") @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_envvar_disable_fallback(emitter, mock_run_new_remote_build, monkeypatch): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_envvar_disable_fallback_core22( + emitter, mock_run_core22_remote_build, monkeypatch +): """core22 and older bases run new remote-build if envvar is `disable-fallback`.""" monkeypatch.setenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", "disable-fallback") cli.run() - mock_run_new_remote_build.assert_called_once() + mock_run_core22_remote_build.assert_called_once() emitter.assert_debug( "Running new remote-build because environment variable " "'SNAPCRAFT_REMOTE_BUILD_STRATEGY' is 'disable-fallback'" @@ -462,8 +494,8 @@ def test_run_envvar_disable_fallback(emitter, mock_run_new_remote_build, monkeyp @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_envvar_force_fallback(emitter, mock_run_legacy, monkeypatch): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_envvar_force_fallback_core22(emitter, mock_run_legacy, monkeypatch): """core22 and older bases run legacy remote-build if envvar is `force-fallback`.""" monkeypatch.setenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", "force-fallback") @@ -479,8 +511,8 @@ def test_run_envvar_force_fallback(emitter, mock_run_legacy, monkeypatch): @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_envvar_force_fallback_unset(emitter, mock_run_legacy, monkeypatch): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_envvar_force_fallback_unset_core22(emitter, mock_run_legacy, monkeypatch): """core22 and older bases run legacy remote-build if envvar is unset.""" monkeypatch.delenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", raising=False) @@ -493,8 +525,8 @@ def test_run_envvar_force_fallback_unset(emitter, mock_run_legacy, monkeypatch): @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_envvar_force_fallback_empty(emitter, mock_run_legacy, monkeypatch): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_envvar_force_fallback_empty_core22(emitter, mock_run_legacy, monkeypatch): """core22 and older bases run legacy remote-build if envvar is empty.""" monkeypatch.setenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", "") @@ -507,8 +539,8 @@ def test_run_envvar_force_fallback_empty(emitter, mock_run_legacy, monkeypatch): @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_envvar_invalid(capsys, emitter, mock_run_legacy, monkeypatch): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_envvar_invalid_core22(capsys, emitter, mock_run_legacy, monkeypatch): """core22 and older bases raise an error if the envvar is invalid.""" monkeypatch.setenv("SNAPCRAFT_REMOTE_BUILD_STRATEGY", "badvalue") @@ -525,15 +557,15 @@ def test_run_envvar_invalid(capsys, emitter, mock_run_legacy, monkeypatch): @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_in_repo(emitter, mock_run_new_remote_build, new_dir): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_in_repo_core22(emitter, mock_run_core22_remote_build, new_dir): """core22 and older bases run new remote-build if in a git repo.""" # initialize a git repo GitRepo(new_dir) cli.run() - mock_run_new_remote_build.assert_called_once() + mock_run_core22_remote_build.assert_called_once() emitter.assert_debug( "Running new remote-build because project is in a git repository" ) @@ -542,8 +574,8 @@ def test_run_in_repo(emitter, mock_run_new_remote_build, new_dir): @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_not_in_repo(emitter, mock_run_legacy): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_not_in_repo_core22(emitter, mock_run_legacy): """core22 and older bases run legacy remote-build if not in a git repo.""" cli.run() @@ -554,9 +586,9 @@ def test_run_not_in_repo(emitter, mock_run_legacy): @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES - {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") def test_run_in_repo_newer_than_core22( - emitter, mock_run_new_remote_build, monkeypatch, new_dir + emitter, mock_run_core22_remote_build, monkeypatch, new_dir ): """Bases newer than core22 run new remote-build regardless of being in a repo.""" # initialize a git repo @@ -564,15 +596,15 @@ def test_run_in_repo_newer_than_core22( cli.run() - mock_run_new_remote_build.assert_called_once() + mock_run_core22_remote_build.assert_called_once() emitter.assert_debug("Running new remote-build because base is newer than core22") @pytest.mark.parametrize( "create_snapcraft_yaml", LEGACY_BASES | {"core22"}, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_confirm", "mock_argv") -def test_run_in_shallow_repo(emitter, mock_run_legacy, new_dir): +@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_core22_confirm", "mock_argv") +def test_run_in_shallow_repo_core22(emitter, mock_run_legacy, new_dir): """core22 and older bases fall back to legacy remote-build if in a shallow git repo.""" root_path = Path(new_dir) git_normal_path = root_path / "normal" @@ -619,9 +651,12 @@ def test_run_in_shallow_repo(emitter, mock_run_legacy, new_dir): "create_snapcraft_yaml", CURRENT_BASES - {"core22"}, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "mock_argv", "use_new_remote_build" + "create_snapcraft_yaml", + "mock_core22_confirm", + "mock_argv", + "use_core22_remote_build", ) -def test_run_in_shallow_repo_unsupported(capsys, new_dir): +def test_run_in_shallow_repo_unsupported_core22(capsys, new_dir): """devel / core24 and newer bases run new remote-build in a shallow git repo.""" root_path = Path(new_dir) git_normal_path = root_path / "normal" @@ -712,16 +747,16 @@ def test_run_in_shallow_repo_unsupported(capsys, new_dir): ), ], ) -@pytest.mark.usefixtures("mock_argv", "mock_confirm", "use_new_remote_build") -def test_determine_architectures_from_snapcraft_yaml( - archs, expected_archs, base, snapcraft_yaml, mock_remote_builder +@pytest.mark.usefixtures("mock_argv", "mock_core22_confirm", "use_core22_remote_build") +def test_determine_architectures_from_snapcraft_yaml_core22( + archs, expected_archs, base, snapcraft_yaml, mock_core22_remote_builder ): """Parse `build-on` architectures from a snapcraft.yaml file.""" snapcraft_yaml(base=base, architectures=archs) cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -735,9 +770,12 @@ def test_determine_architectures_from_snapcraft_yaml( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_argv", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", + "mock_argv", + "mock_core22_confirm", + "use_core22_remote_build", ) -def test_determine_architectures_host_arch(mocker, mock_remote_builder): +def test_determine_architectures_host_arch_core22(mocker, mock_core22_remote_builder): """Use host architecture if not defined in the snapcraft.yaml.""" mocker.patch( "snapcraft.commands.core22.remote.get_host_architecture", return_value="arm64" @@ -745,7 +783,7 @@ def test_determine_architectures_host_arch(mocker, mock_remote_builder): cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -768,10 +806,10 @@ def test_determine_architectures_host_arch(mocker, mock_remote_builder): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_determine_architectures_provided_by_user_duplicate_arguments( - build_flag, archs, expected_archs, mocker, mock_remote_builder +def test_determine_architectures_provided_by_user_duplicate_arguments_core22( + build_flag, archs, expected_archs, mocker, mock_core22_remote_builder ): """Argparse should only consider the last argument provided for build flags.""" mocker.patch.object( @@ -783,7 +821,7 @@ def test_determine_architectures_provided_by_user_duplicate_arguments( cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -811,17 +849,17 @@ def test_determine_architectures_provided_by_user_duplicate_arguments( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_determine_architectures_provided_by_user( - build_flag, archs, expected_archs, mocker, mock_remote_builder +def test_determine_architectures_provided_by_user_core22( + build_flag, archs, expected_archs, mocker, mock_core22_remote_builder ): """Use architectures provided by the user.""" mocker.patch.object(sys, "argv", ["snapcraft", "remote-build", build_flag, archs]) cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -832,8 +870,8 @@ def test_determine_architectures_provided_by_user( @pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES) -@pytest.mark.usefixtures("mock_confirm", "use_new_remote_build") -def test_determine_architectures_error(base, capsys, snapcraft_yaml, mocker): +@pytest.mark.usefixtures("mock_core22_confirm", "use_core22_remote_build") +def test_determine_architectures_error_core22(base, capsys, snapcraft_yaml, mocker): """Error if `--build-for` is provided and archs are in the snapcraft.yaml.""" mocker.patch.object( sys, "argv", ["snapcraft", "remote-build", "--build-for", "amd64"] @@ -860,9 +898,9 @@ def test_determine_architectures_error(base, capsys, snapcraft_yaml, mocker): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_build_id_provided(mocker, mock_remote_builder): +def test_build_id_provided_core22(mocker, mock_core22_remote_builder): """Pass the build id provided as an argument.""" mocker.patch.object( sys, "argv", ["snapcraft", "remote-build", "--build-id", "test-build-id"] @@ -870,7 +908,7 @@ def test_build_id_provided(mocker, mock_remote_builder): cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id="test-build-id", project_name="mytest", @@ -884,14 +922,17 @@ def test_build_id_provided(mocker, mock_remote_builder): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "mock_argv", "use_new_remote_build" + "create_snapcraft_yaml", + "mock_core22_confirm", + "mock_argv", + "use_core22_remote_build", ) -def test_build_id_not_provided(mock_remote_builder): +def test_build_id_not_provided_core22(mock_core22_remote_builder): """Pass `None` for the build id if it is not provided as an argument.""" cli.run() - mock_remote_builder.assert_called_with( + mock_core22_remote_builder.assert_called_with( app_name="snapcraft", build_id=None, project_name="mytest", @@ -902,8 +943,8 @@ def test_build_id_not_provided(mock_remote_builder): @pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES) -@pytest.mark.usefixtures("mock_confirm", "mock_argv", "use_new_remote_build") -def test_build_id_no_project_name_error(base, capsys): +@pytest.mark.usefixtures("mock_core22_confirm", "mock_argv", "use_core22_remote_build") +def test_build_id_no_project_name_error_core22(base, capsys): """Raise an error if there is no name in the snapcraft.yaml file.""" content = { "base": base, @@ -936,15 +977,15 @@ def test_build_id_no_project_name_error(base, capsys): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_status(mocker, mock_remote_builder): +def test_status_core22(mocker, mock_core22_remote_builder): """Print the status when `--status` is provided.""" mocker.patch.object(sys, "argv", ["snapcraft", "remote-build", "--status"]) cli.run() - assert mock_remote_builder.mock_calls[-1] == call().print_status() + assert mock_core22_remote_builder.mock_calls[-1] == call().print_status() @pytest.mark.parametrize( @@ -952,11 +993,11 @@ def test_status(mocker, mock_remote_builder): ) @pytest.mark.usefixtures( "create_snapcraft_yaml", - "mock_confirm", - "mock_remote_builder", - "use_new_remote_build", + "mock_core22_confirm", + "mock_core22_remote_builder", + "use_core22_remote_build", ) -def test_recover_no_build(emitter, mocker): +def test_recover_no_build_core22(emitter, mocker): """Warn if no build is found when `--recover` is provided.""" mocker.patch.object(sys, "argv", ["snapcraft", "remote-build", "--recover"]) @@ -969,16 +1010,16 @@ def test_recover_no_build(emitter, mocker): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", "mock_core22_confirm", "use_core22_remote_build" ) -def test_recover_build(emitter, mocker, mock_remote_builder): +def test_recover_build_core22(emitter, mocker, mock_core22_remote_builder): """Recover a build when `--recover` is provided.""" mocker.patch.object(sys, "argv", ["snapcraft", "remote-build", "--recover"]) - mock_remote_builder.return_value.has_outstanding_build.return_value = True + mock_core22_remote_builder.return_value.has_outstanding_build.return_value = True cli.run() - assert mock_remote_builder.mock_calls[-3:] == [ + assert mock_core22_remote_builder.mock_calls[-3:] == [ call().print_status(), call().monitor_build(), call().clean_build(), @@ -989,15 +1030,20 @@ def test_recover_build(emitter, mocker, mock_remote_builder): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_argv", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", + "mock_argv", + "mock_core22_confirm", + "use_core22_remote_build", ) -def test_recover_build_user_confirms(emitter, mocker, mock_remote_builder): +def test_recover_build_user_confirms_core22( + emitter, mocker, mock_core22_remote_builder +): """Recover a build when a user confirms.""" - mock_remote_builder.return_value.has_outstanding_build.return_value = True + mock_core22_remote_builder.return_value.has_outstanding_build.return_value = True cli.run() - assert mock_remote_builder.mock_calls[-3:] == [ + assert mock_core22_remote_builder.mock_calls[-3:] == [ call().print_status(), call().monitor_build(), call().clean_build(), @@ -1007,19 +1053,21 @@ def test_recover_build_user_confirms(emitter, mocker, mock_remote_builder): @pytest.mark.parametrize( "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) -@pytest.mark.usefixtures("create_snapcraft_yaml", "mock_argv", "use_new_remote_build") -def test_recover_build_user_denies(emitter, mocker, mock_remote_builder): +@pytest.mark.usefixtures( + "create_snapcraft_yaml", "mock_argv", "use_core22_remote_build" +) +def test_recover_build_user_denies_core22(emitter, mocker, mock_core22_remote_builder): """Clean and start a new build when a user denies to recover an existing build.""" mocker.patch( # confirm data upload, deny build recovery "snapcraft.commands.core22.remote.confirm_with_user", side_effect=[True, False], ) - mock_remote_builder.return_value.has_outstanding_build.return_value = True + mock_core22_remote_builder.return_value.has_outstanding_build.return_value = True cli.run() - assert mock_remote_builder.mock_calls[-3:] == [ + assert mock_core22_remote_builder.mock_calls[-3:] == [ call().start_build(), call().monitor_build(), call().clean_build(), @@ -1030,13 +1078,16 @@ def test_recover_build_user_denies(emitter, mocker, mock_remote_builder): "create_snapcraft_yaml", CURRENT_BASES | LEGACY_BASES, indirect=True ) @pytest.mark.usefixtures( - "create_snapcraft_yaml", "mock_argv", "mock_confirm", "use_new_remote_build" + "create_snapcraft_yaml", + "mock_argv", + "mock_core22_confirm", + "use_core22_remote_build", ) -def test_remote_build(emitter, mocker, mock_remote_builder): +def test_remote_build_core22(emitter, mocker, mock_core22_remote_builder): """Clean and start a new build.""" cli.run() - assert mock_remote_builder.mock_calls[-3:] == [ + assert mock_core22_remote_builder.mock_calls[-3:] == [ call().start_build(), call().monitor_build(), call().clean_build(),