diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index dd8f33a3d15..2ffc7198389 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -400,7 +400,13 @@ def get_operation_message( DeprecationWarning, stacklevel=2, ) - return operation.get_message() + new_state = {"done": done, "error": error, "warning": warning} + old_state = {attr: getattr(operation, attr) for attr in new_state} + op_state = vars(operation) + op_state.update(new_state) + message = operation.get_message() + op_state.update(old_state) + return message def _display_summary(self, operations: list[Operation]) -> None: installs = 0 diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index bdebbbc9fef..6e6d6bcc5c1 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -11,6 +11,7 @@ from typing import TYPE_CHECKING from typing import Any from typing import Callable +from typing import TypedDict import pytest @@ -417,15 +418,51 @@ def test_execute_should_show_errors( assert expected in io.fetch_output() +class OperationState(TypedDict, total=False): + done: bool + error: bool + warning: bool + + +@pytest.mark.parametrize( + "operation", + [ + Install(Package("foo", "0.1.0")), + Update(Package("foo", "0.1.0"), Package("foo", "0.2.0")), + Update(Package("foo", "0.2.0"), Package("foo", "0.1.0")), + Uninstall(Package("foo", "0.1.0")), + ], +) +@pytest.mark.parametrize( + "new_state", + [ + OperationState(), + OperationState(done=True), + OperationState(error=True), + OperationState(warning=True), + ], +) def test_get_operation_message_deprecated( config: Config, pool: RepositoryPool, io_decorated: BufferedIO, env: MockEnv, + operation: Operation, + new_state: OperationState, ) -> None: executor = Executor(env, pool, config, io_decorated) with pytest.warns(DeprecationWarning): - executor.get_operation_message(Install(Package("clikit", "0.2.3"))) + msg_legacy_way = executor.get_operation_message(operation, **new_state) + old_state = { + "done": operation.done, + "warning": operation.warning, + "error": operation.error, + } + op_state = vars(operation) + op_state.update(new_state) + msg = operation.get_message() + assert msg_legacy_way == msg + op_state.update(old_state) def test_execute_works_with_ansi_output(