Skip to content

Commit

Permalink
refactor: ensure backward compatibility of deprecated `get_operation_…
Browse files Browse the repository at this point in the history
…message()`
  • Loading branch information
bswck committed Aug 22, 2024
1 parent d1964cf commit c3648d9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 38 additions & 1 deletion tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import TypedDict

import pytest

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c3648d9

Please sign in to comment.