def test_parts_lifecycle_run_parts_error(new_dir): lifecycle = PartsLifecycle( {"p1": { "plugin": "dump", "source": "foo" }}, work_dir=new_dir, assets_dir=new_dir, base="core22", parallel_build_count=8, part_names=[], package_repositories=[], adopt_info=None, project_name="test-project", parse_info={}, project_vars={ "version": "1", "grade": "stable" }, target_arch="amd64", ) with pytest.raises(errors.PartsLifecycleError) as raised: lifecycle.run("prime") assert str(raised.value) == ( "Failed to pull source: unable to determine source type of 'foo'.")
def test_parts_lifecycle_run(mocker, parts_data, step_name, new_dir, emitter): mocker.patch("craft_parts.executor.executor.Executor._install_build_snaps") lcm_spy = mocker.spy(craft_parts, "LifecycleManager") lifecycle = PartsLifecycle( parts_data, work_dir=new_dir, assets_dir=new_dir, base="core22", parallel_build_count=8, part_names=[], package_repositories=[], adopt_info=None, project_name="test-project", parse_info={}, project_vars={ "version": "1", "grade": "stable" }, extra_build_snaps=["core22"], target_arch="amd64", ) lifecycle.run(step_name) assert lifecycle.prime_dir == Path(new_dir, "prime") assert lifecycle.prime_dir.is_dir() assert lcm_spy.mock_calls == [ call( {"parts": { "p1": { "plugin": "nil" } }}, application_name="snapcraft", work_dir=ANY, cache_dir=ANY, arch="x86_64", base="core22", ignore_local_sources=["*.snap"], extra_build_snaps=["core22"], parallel_build_count=8, project_name="test-project", project_vars_part_name=None, project_vars={ "version": "1", "grade": "stable" }, ) ] emitter.assert_progress(f"Executing parts lifecycle: {step_name} p1")
def test_parts_lifecycle_run_with_all_architecture(mocker, parts_data, new_dir): """`target_arch=all` should use the host architecture.""" mocker.patch("craft_parts.executor.executor.Executor._install_build_snaps") lcm_spy = mocker.spy(craft_parts, "LifecycleManager") lifecycle = PartsLifecycle( parts_data, work_dir=new_dir, assets_dir=new_dir, base="core22", parallel_build_count=8, part_names=[], package_repositories=[], adopt_info=None, parse_info={}, project_name="test-project", project_vars={ "version": "1", "grade": "stable" }, target_arch="amd64", ) lifecycle.run("prime") assert lcm_spy.mock_calls == [ call( {"parts": { "p1": { "plugin": "nil" } }}, application_name="snapcraft", work_dir=ANY, cache_dir=ANY, arch="x86_64", base="core22", ignore_local_sources=["*.snap"], extra_build_snaps=None, parallel_build_count=8, project_name="test-project", project_vars_part_name=None, project_vars={ "version": "1", "grade": "stable" }, ) ]
def test_parts_lifecycle_run_bad_step(parts_data, new_dir): lifecycle = PartsLifecycle( parts_data, work_dir=new_dir, assets_dir=new_dir, base="core22", parallel_build_count=8, part_names=[], package_repositories=[], adopt_info=None, parse_info={}, project_name="test-project", project_vars={ "version": "1", "grade": "stable" }, ) with pytest.raises(RuntimeError) as raised: lifecycle.run("invalid") assert str(raised.value) == "Invalid target step 'invalid'"
def test_parts_lifecycle_run_internal_error(parts_data, new_dir, mocker): lifecycle = PartsLifecycle( parts_data, work_dir=new_dir, assets_dir=new_dir, base="core22", parallel_build_count=8, part_names=[], package_repositories=[], adopt_info=None, project_name="test-project", parse_info={}, project_vars={ "version": "1", "grade": "stable" }, ) mocker.patch("craft_parts.LifecycleManager.plan", side_effect=RuntimeError("crash")) with pytest.raises(RuntimeError) as raised: lifecycle.run("prime") assert str(raised.value) == "Parts processing internal error: crash"