diff --git a/craft_application/services/lifecycle.py b/craft_application/services/lifecycle.py index fd8f82ac..e2797fbb 100644 --- a/craft_application/services/lifecycle.py +++ b/craft_application/services/lifecycle.py @@ -36,41 +36,41 @@ { Step.PULL: types.MappingProxyType( { - ActionType.RUN: "pull", - ActionType.RERUN: "repull", - ActionType.SKIP: "skip pull", - ActionType.UPDATE: "update sources for", + ActionType.RUN: "Pulling", + ActionType.RERUN: "Repulling", + ActionType.SKIP: "Skipping pull for", + ActionType.UPDATE: "Updating sources for", } ), Step.OVERLAY: types.MappingProxyType( { - ActionType.RUN: "overlay", - ActionType.RERUN: "re-overlay", - ActionType.SKIP: "skip overlay", - ActionType.UPDATE: "update overlay for", - ActionType.REAPPLY: "reapply", + ActionType.RUN: "Overlaying", + ActionType.RERUN: "Re-overlaying", + ActionType.SKIP: "Skipping overlay for", + ActionType.UPDATE: "Updating overlay for", + ActionType.REAPPLY: "Reapplying", } ), Step.BUILD: types.MappingProxyType( { - ActionType.RUN: "build", - ActionType.RERUN: "rebuild", - ActionType.SKIP: "skip build", - ActionType.UPDATE: "update build for", + ActionType.RUN: "Building", + ActionType.RERUN: "Rebuilding", + ActionType.SKIP: "Skipping build for", + ActionType.UPDATE: "Updating build for", } ), Step.STAGE: types.MappingProxyType( { - ActionType.RUN: "stage", - ActionType.RERUN: "restage", - ActionType.SKIP: "skip stage", + ActionType.RUN: "Staging", + ActionType.RERUN: "Restaging", + ActionType.SKIP: "Skipping stage for", } ), Step.PRIME: types.MappingProxyType( { - ActionType.RUN: "prime", - ActionType.RERUN: "re-prime", - ActionType.SKIP: "skip prime", + ActionType.RUN: "Priming", + ActionType.RERUN: "Re-priming", + ActionType.SKIP: "Skipping prime for", } ), } @@ -156,12 +156,8 @@ def run(self, step_name: str, part_names: list[str] | None = None) -> None: with self._lcm.action_executor() as aex: for action in actions: message = _get_parts_action_message(action) - emit.progress(f"Executing parts lifecycle: {message}") - with emit.open_stream("Executing action") as stream: + with emit.open_stream(f"{message}") as stream: aex.execute(action, stdout=stream, stderr=stream) - emit.progress(f"Executed: {message}", permanent=True) - - emit.progress("Executed parts lifecycle", permanent=True) except RuntimeError as err: raise RuntimeError(f"Parts processing internal error: {err}") from err except OSError as err: diff --git a/tests/unit/services/test_lifecycle.py b/tests/unit/services/test_lifecycle.py index 6de643d5..a2fb27ac 100644 --- a/tests/unit/services/test_lifecycle.py +++ b/tests/unit/services/test_lifecycle.py @@ -51,23 +51,108 @@ def fake_parts_lifecycle(app_metadata, fake_project, tmp_path): # endregion # region Helper function tests -@pytest.mark.parametrize("step", Step) -@pytest.mark.parametrize("reason", [None, "Because I said so!"]) -def test_get_parts_action_message_run(step: Step, reason: str | None): +@pytest.mark.parametrize( + ("step", "message"), + [ + (Step.PULL, "Pulling my-part"), + (Step.BUILD, "Building my-part"), + (Step.OVERLAY, "Overlaying my-part"), + (Step.STAGE, "Staging my-part"), + (Step.PRIME, "Priming my-part"), + ], +) +def test_get_parts_action_message_run(step: Step, message: str): action = Action( "my-part", step, action_type=ActionType.RUN, - reason=reason, ) actual = lifecycle._get_parts_action_message(action) - pytest_check.is_true(actual.startswith(f"{step.name.lower()} my-part")) - if reason: - pytest_check.is_true(actual.endswith(f"({reason})")) - else: - pytest_check.is_false(actual.endswith(")")) + assert actual == message, "Unexpected %r" % actual + + +@pytest.mark.parametrize( + ("step", "message"), + [ + (Step.PULL, "Repulling my-part"), + (Step.BUILD, "Rebuilding my-part"), + (Step.OVERLAY, "Re-overlaying my-part"), + (Step.STAGE, "Restaging my-part"), + (Step.PRIME, "Re-priming my-part"), + ], +) +def test_get_parts_re_action_message_run(step: Step, message: str): + action = Action( + "my-part", + step, + action_type=ActionType.RERUN, + ) + + actual = lifecycle._get_parts_action_message(action) + + assert actual == message, "Unexpected %r" % actual + + +@pytest.mark.parametrize( + ("step", "message"), + [ + (Step.PULL, "Skipping pull for my-part"), + (Step.BUILD, "Skipping build for my-part"), + (Step.OVERLAY, "Skipping overlay for my-part"), + (Step.STAGE, "Skipping stage for my-part"), + (Step.PRIME, "Skipping prime for my-part"), + ], +) +def test_get_parts_skip_action_message_run(step: Step, message: str): + action = Action( + "my-part", + step, + action_type=ActionType.SKIP, + ) + + actual = lifecycle._get_parts_action_message(action) + + assert actual == message, "Unexpected %r" % actual + + +@pytest.mark.parametrize( + ("step", "message"), + [ + (Step.PULL, "Updating sources for my-part"), + (Step.BUILD, "Updating build for my-part"), + (Step.OVERLAY, "Updating overlay for my-part"), + ], +) +def test_get_parts_update_action_message_run(step: Step, message: str): + action = Action( + "my-part", + step, + action_type=ActionType.UPDATE, + ) + + actual = lifecycle._get_parts_action_message(action) + + assert actual == message, "Unexpected %r" % actual + + +@pytest.mark.parametrize( + ("step", "message"), + [ + (Step.PULL, "Pulling my-part (dirty)"), + (Step.BUILD, "Building my-part (dirty)"), + (Step.OVERLAY, "Overlaying my-part (dirty)"), + (Step.STAGE, "Staging my-part (dirty)"), + (Step.PRIME, "Priming my-part (dirty)"), + ], +) +def get_parts_action_message_with_reason(step: Step, message: str): + action = Action("my-part", step, action_type=ActionType.RUN, reason="dirty") + + actual = lifecycle._get_parts_action_message(action) + + assert actual == message, "Unexpected %r" % actual @pytest.mark.usefixtures("enable_overlay")