diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index 7234a1cebcb..43b4abd8a3c 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -169,13 +169,13 @@ def handle(self) -> int: return 0 log_install = ( - "Installing the current project:" + "{verb} the current project:" f" {self.poetry.package.pretty_name}" f" (<{{tag}}>{self.poetry.package.pretty_version})" ) overwrite = self.io.output.is_decorated() and not self.io.is_debug() self.line("") - self.write(log_install.format(tag="c2")) + self.write(log_install.format(verb="Installing", tag="c2")) if not overwrite: self.line("") @@ -209,7 +209,7 @@ def handle(self) -> int: return 0 if overwrite: - self.overwrite(log_install.format(tag="success")) + self.overwrite(log_install.format(verb="Installed", tag="success")) self.line("") return 0 diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index b9fb149c4ed..81627cb8cab 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -6,6 +6,7 @@ import itertools import json import threading +import warnings from concurrent.futures import ThreadPoolExecutor from concurrent.futures import wait @@ -252,7 +253,7 @@ def _write(self, operation: Operation, line: str) -> None: def _execute_operation(self, operation: Operation) -> None: try: - op_message = self.get_operation_message(operation) + op_message = operation.get_message() if self.supports_fancy_output(): if id(operation) not in self._sections and self._should_write_operation( operation @@ -298,9 +299,10 @@ def _execute_operation(self, operation: Operation) -> None: if not self.supports_fancy_output(): io = self._io else: + operation.error = True message = ( " -" - f" {self.get_operation_message(operation, error=True)}:" + f" {operation.get_message()}:" " Failed" ) self._write(operation, message) @@ -354,9 +356,10 @@ def _execute_operation(self, operation: Operation) -> None: except KeyboardInterrupt: try: + operation.warning = True message = ( " -" - f" {self.get_operation_message(operation, warning=True)}:" + f" {operation.get_message()}:" " Cancelled" ) if not self.supports_fancy_output(): @@ -370,7 +373,7 @@ def _execute_operation(self, operation: Operation) -> None: def _do_execute_operation(self, operation: Operation) -> int: method = operation.job_type - operation_message = self.get_operation_message(operation) + operation_message = operation.get_message() if operation.skipped: if self.supports_fancy_output(): self._write( @@ -393,8 +396,8 @@ def _do_execute_operation(self, operation: Operation) -> int: if result != 0: return result - operation_message = self.get_operation_message(operation, done=True) - message = f" - {operation_message}" + operation.done = True + message = f" - {operation.get_message()}" self._write(operation, message) self._increment_operations_count(operation, True) @@ -431,53 +434,19 @@ def get_operation_message( error: bool = False, warning: bool = False, ) -> str: - base_tag = "fg=default" - operation_color = "c2" - source_operation_color = "c2" - package_color = "c1" - - if error: - operation_color = "error" - elif warning: - operation_color = "warning" - elif done: - operation_color = "success" - - if operation.skipped: - base_tag = "fg=default;options=dark" - operation_color += "_dark" - source_operation_color += "_dark" - package_color += "_dark" - - if isinstance(operation, Install): - return ( - f"<{base_tag}>Installing" - f" <{package_color}>{operation.package.name}" - f" (<{operation_color}>{operation.package.full_pretty_version})" - ) - - if isinstance(operation, Uninstall): - return ( - f"<{base_tag}>Removing" - f" <{package_color}>{operation.package.name}" - f" (<{operation_color}>{operation.package.full_pretty_version})" - ) - - if isinstance(operation, Update): - initial_version = (initial_pkg := operation.initial_package).version - target_version = (target_pkg := operation.target_package).version - update_kind = ( - "Updating" if target_version >= initial_version else "Downgrading" - ) - return ( - f"<{base_tag}>{update_kind}" - f" <{package_color}>{initial_pkg.name} " - f"(<{source_operation_color}>" - f"{initial_pkg.full_pretty_version}" - f" -> <{operation_color}>" - f"{target_pkg.full_pretty_version})" - ) - return "" + warnings.warn( + "'Executor.get_operation_message()' and its boolean parameters " + "are deprecated, please use 'Operation.get_message()' instead.", + DeprecationWarning, + stacklevel=2, + ) + 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 @@ -527,8 +496,8 @@ def _execute_update(self, operation: Install | Update) -> int: return status_code def _execute_uninstall(self, operation: Uninstall) -> int: - op_msg = self.get_operation_message(operation) - message = f" - {op_msg}: Removing..." + op_msg = operation.get_message() + message = f" - {op_msg}: In progress..." self._write(operation, message) return self._remove(operation.package) @@ -553,10 +522,10 @@ def _install(self, operation: Install | Update) -> int: else: archive = self._download(operation) - operation_message = self.get_operation_message(operation) + operation_message = operation.get_message() message = ( f" - {operation_message}:" - " Installing..." + " In progress..." ) self._write(operation, message) @@ -600,7 +569,7 @@ def _prepare_archive( self, operation: Install | Update, *, output_dir: Path | None = None ) -> Path: package = operation.package - operation_message = self.get_operation_message(operation) + operation_message = operation.get_message() message = ( f" - {operation_message}:" @@ -639,7 +608,7 @@ def _prepare_git_archive(self, operation: Install | Update) -> Path: if cached_archive is not None: return cached_archive - operation_message = self.get_operation_message(operation) + operation_message = operation.get_message() message = ( f" - {operation_message}: Cloning..." @@ -682,7 +651,7 @@ def _install_directory_without_wheel_installer( from poetry.pyproject.toml import PyProjectTOML package = operation.package - operation_message = self.get_operation_message(operation) + operation_message = operation.get_message() message = ( f" - {operation_message}:" @@ -773,7 +742,7 @@ def _download_link(self, operation: Install | Update, link: Link) -> Path: if archive.suffix != ".whl": message = ( - f" - {self.get_operation_message(operation)}:" + f" - {operation.get_message()}:" " Preparing..." ) self._write(operation, message) @@ -821,7 +790,7 @@ def _download_archive( downloader = Downloader(url, dest, self._authenticator) wheel_size = downloader.total_size - operation_message = self.get_operation_message(operation) + operation_message = operation.get_message() message = ( f" - {operation_message}: Downloading..." ) diff --git a/src/poetry/installation/installer.py b/src/poetry/installation/installer.py index 7bc9f23520d..e6ddc45b1f0 100644 --- a/src/poetry/installation/installer.py +++ b/src/poetry/installation/installer.py @@ -351,7 +351,7 @@ def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> Non if updated_lock: self._io.write_line("") - self._io.write_line("Writing lock file") + self._io.write_line("Lock file written") def _execute(self, operations: list[Operation]) -> int: return self._executor.execute(operations) diff --git a/src/poetry/installation/operations/install.py b/src/poetry/installation/operations/install.py index 3abb0fd5b19..4f30b4b42ef 100644 --- a/src/poetry/installation/operations/install.py +++ b/src/poetry/installation/operations/install.py @@ -25,9 +25,21 @@ def package(self) -> Package: def job_type(self) -> str: return "install" + @property + def message_verb(self) -> str: + return "Installed" if self.done else "Installing" + + def get_message(self) -> str: + return ( + f"<{self._message_base_tag}>{self.message_verb} " + f"<{self._message_package_color}>{self.package.name}" + f" " + f"(<{self._message_color}>{self.package.full_pretty_version})" + ) + def __str__(self) -> str: return ( - "Installing" + f"{self.message_verb}" f" {self.package.pretty_name} ({self.format_version(self.package)})" ) diff --git a/src/poetry/installation/operations/operation.py b/src/poetry/installation/operations/operation.py index c54ccb4a878..f1140e31b73 100644 --- a/src/poetry/installation/operations/operation.py +++ b/src/poetry/installation/operations/operation.py @@ -5,19 +5,46 @@ if TYPE_CHECKING: + from typing import ClassVar + from poetry.core.packages.package import Package + T = TypeVar("T", bound="Operation") class Operation: + _message_default_color: ClassVar[str] = "c2" + _message_package_color: ClassVar[str] = "c1" + def __init__(self, reason: str | None = None, priority: float = 0) -> None: self._reason = reason + self.error = False + self.warning = False + self.done = False self._skipped = False self._skip_reason: str | None = None self._priority = priority + @property + def _message_base_tag(self) -> str: + return "fg=default" + ";options=dark" * self.skipped + + @property + def _message_color(self) -> str: + color = self._message_default_color + if self.error: + color = "error" + elif self.warning: + color = "warning" + elif self.done: + color = "success" + return color + "_dark" * self.skipped + + def get_message(self) -> str: + return "" + @property def job_type(self) -> str: raise NotImplementedError diff --git a/src/poetry/installation/operations/uninstall.py b/src/poetry/installation/operations/uninstall.py index 0bcb8702c50..1412867fe6c 100644 --- a/src/poetry/installation/operations/uninstall.py +++ b/src/poetry/installation/operations/uninstall.py @@ -28,10 +28,22 @@ def package(self) -> Package: def job_type(self) -> str: return "uninstall" + @property + def message_verb(self) -> str: + return "Removed" if self.done else "Removing" + + def get_message(self) -> str: + return ( + f"<{self._message_base_tag}>{self.message_verb}" + f" <{self._message_package_color}>{self.package.name}" + f"" + f" (<{self._message_color}>{self.package.full_pretty_version})" + ) + def __str__(self) -> str: return ( - "Uninstalling" - f" {self.package.pretty_name} ({self.format_version(self._package)})" + f"{self.message_verb} " + f"{self.package.pretty_name} ({self.format_version(self._package)})" ) def __repr__(self) -> str: diff --git a/src/poetry/installation/operations/update.py b/src/poetry/installation/operations/update.py index e67cc869b37..b9cf2758a26 100644 --- a/src/poetry/installation/operations/update.py +++ b/src/poetry/installation/operations/update.py @@ -6,10 +6,14 @@ if TYPE_CHECKING: + from typing import ClassVar + from poetry.core.packages.package import Package class Update(Operation): + _message_source_operation_color: ClassVar[str] = "c2" + def __init__( self, initial: Package, @@ -38,18 +42,38 @@ def package(self) -> Package: def job_type(self) -> str: return "update" + @property + def message_verb(self) -> str: + initial_version = self.initial_package.version + target_version = self.target_package.version + if target_version >= initial_version: + return "Updated" if self.done else "Updating" + return "Downgraded" if self.done else "Downgrading" + + def get_message(self) -> str: + return ( + f"<{self._message_base_tag}>{self.message_verb}" + f" <{self._message_package_color}>" + f"{self.initial_package.name} " + f"(<{self._message_source_operation_color}>" + f"{self.initial_package.full_pretty_version}" + f" -> <{self._message_color}>" + f"{self.target_package.full_pretty_version})" + ) + def __str__(self) -> str: - init_version = self.format_version(self.initial_package) + initial_version = self.format_version(self.initial_package) target_version = self.format_version(self.target_package) return ( - f"Updating {self.initial_package.pretty_name} ({init_version}) " - f"to {self.target_package.pretty_name} ({target_version})" + f"{self.message_verb} {self.initial_package.pretty_name} " + f"({initial_version}) to {self.target_package.pretty_name} " + f"({target_version})" ) def __repr__(self) -> str: - init_version = self.format_version(self.initial_package) + initial_version = self.format_version(self.initial_package) target_version = self.format_version(self.target_package) return ( - f"" ) diff --git a/tests/console/commands/self/test_add_plugins.py b/tests/console/commands/self/test_add_plugins.py index 427448bfe82..b5af6cb4d4d 100644 --- a/tests/console/commands/self/test_add_plugins.py +++ b/tests/console/commands/self/test_add_plugins.py @@ -59,7 +59,7 @@ def test_add_no_constraint( - Installing poetry-plugin (0.1.0) -Writing lock file +Lock file written """ assert_plugin_add_result(tester, expected, "^0.1.0") @@ -81,7 +81,7 @@ def test_add_with_constraint( - Installing poetry-plugin (0.2.0) -Writing lock file +Lock file written """ assert_plugin_add_result(tester, expected, "^0.2.0") @@ -104,7 +104,7 @@ def test_add_with_git_constraint( - Installing pendulum (2.0.5) - Installing poetry-plugin (0.1.2 9cf87a2) -Writing lock file +Lock file written """ assert_plugin_add_result( @@ -131,7 +131,7 @@ def test_add_with_git_constraint_with_extras( - Installing tomlkit (0.7.0) - Installing poetry-plugin (0.1.2 9cf87a2) -Writing lock file +Lock file written """ constraint: dict[str, str | list[str]] = { @@ -170,7 +170,7 @@ def test_add_with_git_constraint_with_subdirectory( - Installing pendulum (2.0.5) - Installing poetry-plugin (0.1.2 9cf87a2) -Writing lock file +Lock file written """ constraint = { @@ -270,7 +270,7 @@ def test_add_existing_plugin_updates_if_requested( - Updating poetry-plugin (1.2.3 -> 2.3.4) -Writing lock file +Lock file written """ assert_plugin_add_result(tester, expected, "^2.3.4") @@ -307,7 +307,7 @@ def test_adding_a_plugin_can_update_poetry_dependencies_if_needed( - Updating tomlkit (0.7.1 -> 0.7.2) - Installing poetry-plugin (1.2.3) -Writing lock file +Lock file written """ assert_plugin_add_result(tester, expected, "^1.2.3") diff --git a/tests/console/commands/self/test_remove_plugins.py b/tests/console/commands/self/test_remove_plugins.py index be5e44f6130..b07dd87bdad 100644 --- a/tests/console/commands/self/test_remove_plugins.py +++ b/tests/console/commands/self/test_remove_plugins.py @@ -76,7 +76,7 @@ def test_remove_installed_package(tester: CommandTester) -> None: - Removing poetry-plugin (1.2.3) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected diff --git a/tests/console/commands/self/test_update.py b/tests/console/commands/self/test_update.py index 808a7663a06..0978dbfe9e5 100644 --- a/tests/console/commands/self/test_update.py +++ b/tests/console/commands/self/test_update.py @@ -74,7 +74,7 @@ def test_self_update_can_update_from_recommended_installation( - Updating cleo (0.8.2 -> 1.0.0) - Updating poetry ({__version__} -> {new_version}) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected_output diff --git a/tests/console/commands/test_add.py b/tests/console/commands/test_add.py index fb8c4e58188..4343921af67 100644 --- a/tests/console/commands/test_add.py +++ b/tests/console/commands/test_add.py @@ -87,7 +87,7 @@ def test_add_no_constraint( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -142,7 +142,7 @@ def test_add_replace_by_constraint( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected assert isinstance(tester.command, InstallerCommand) @@ -163,7 +163,7 @@ def test_add_replace_by_constraint( - Installing cachy (0.1.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -214,7 +214,7 @@ def test_add_equal_constraint(repo: TestRepository, tester: CommandTester) -> No - Installing cachy (0.1.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -237,7 +237,7 @@ def test_add_greater_constraint(repo: TestRepository, tester: CommandTester) -> - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -272,7 +272,7 @@ def test_add_constraint_with_extras( - Installing msgpack-python (0.5.3) - Installing cachy (0.1.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -303,7 +303,7 @@ def test_add_constraint_dependencies( - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -335,7 +335,7 @@ def test_add_git_constraint( - Installing pendulum (1.4.4) - Installing demo (0.1.2 9cf87a2) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -372,7 +372,7 @@ def test_add_git_constraint_with_poetry( - Installing pendulum (1.4.4) - Installing demo (0.1.2 9cf87a2) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -408,7 +408,7 @@ def test_add_git_constraint_with_extras( - Installing tomlkit (0.5.5) - Installing demo (0.1.2 9cf87a2) -Writing lock file +Lock file written """ assert tester.io.fetch_output().strip() == expected.strip() @@ -450,7 +450,7 @@ def test_add_git_constraint_with_subdirectory( - Installing two (2.0.0 9cf87a2) -Writing lock file +Lock file written """ assert tester.io.fetch_output().strip() == expected.strip() assert isinstance(tester.command, InstallerCommand) @@ -498,7 +498,7 @@ def test_add_git_ssh_constraint( - Installing pendulum (1.4.4) - Installing demo (0.1.2 9cf87a2) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -547,7 +547,7 @@ def test_add_directory_constraint( - Installing pendulum (1.4.4) - Installing demo (0.1.2 {demo_path}) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -591,7 +591,7 @@ def test_add_directory_with_poetry( - Installing pendulum (1.4.4) - Installing demo (0.1.2 {demo_path}) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -624,7 +624,7 @@ def test_add_file_constraint_wheel( - Installing pendulum (1.4.4) - Installing demo (0.1.0 {demo_path}) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -663,7 +663,7 @@ def test_add_file_constraint_sdist( - Installing pendulum (1.4.4) - Installing demo (0.1.0 {demo_path}) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -705,7 +705,7 @@ def test_add_constraint_with_extras_option( - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -748,7 +748,7 @@ def test_add_url_constraint_wheel( - Installing demo\ (0.1.0 https://files.pythonhosted.org/distributions/demo-0.1.0-py2.py3-none-any.whl) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -793,7 +793,7 @@ def test_add_url_constraint_wheel_with_extras( - Installing demo\ (0.1.0 https://files.pythonhosted.org/distributions/demo-0.1.0-py2.py3-none-any.whl) -Writing lock file +Lock file written """ # Order might be different, split into lines and compare the overall output. expected_lines = set(expected.splitlines()) @@ -826,7 +826,7 @@ def test_add_constraint_with_optional( No dependencies to install or update -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -862,7 +862,7 @@ def test_add_constraint_with_python( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -901,7 +901,7 @@ def test_add_constraint_with_platform( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -949,7 +949,7 @@ def test_add_constraint_with_source( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -1010,7 +1010,7 @@ def test_add_to_section_that_does_not_exist_yet( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -1059,7 +1059,7 @@ def test_add_to_dev_section_deprecated( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_error() == warning @@ -1092,7 +1092,7 @@ def test_add_should_not_select_prereleases( - Installing pyyaml (3.13) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -1228,7 +1228,7 @@ def test_add_should_work_when_adding_existing_package_with_latest_constraint( - Installing foo (1.1.2) -Writing lock file +Lock file written """ assert expected in tester.io.fetch_output() @@ -1258,7 +1258,7 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available( - Installing foo (1.2.3b1) -Writing lock file +Lock file written """ assert expected in tester.io.fetch_output() @@ -1281,7 +1281,7 @@ def test_add_prefers_stable_releases( - Installing foo (1.2.3) -Writing lock file +Lock file written """ assert expected in tester.io.fetch_output() @@ -1301,7 +1301,7 @@ def test_add_with_lock( Updating dependencies Resolving dependencies... -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -1328,7 +1328,7 @@ def test_add_to_section_that_does_no_exist_yet( - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -1489,7 +1489,7 @@ def test_add_extras_are_parsed_and_included( - Installing redis (3.4.0) - Installing cachy (0.2.0) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index 2692fa59f88..15b0bf90213 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -407,7 +407,7 @@ def test_install_logs_output_decorated( "\x1b[39;1mInstalling\x1b[39;22m the current project: " "\x1b[36msimple-project\x1b[39m (\x1b[39;1m1.2.3\x1b[39;22m)" "\x1b[1G\x1b[2K" - "\x1b[39;1mInstalling\x1b[39;22m the current project: " + "\x1b[39;1mInstalled\x1b[39;22m the current project: " "\x1b[36msimple-project\x1b[39m (\x1b[32m1.2.3\x1b[39m)" "\n" ) diff --git a/tests/console/commands/test_remove.py b/tests/console/commands/test_remove.py index 6991045f82b..c6331b5b13e 100644 --- a/tests/console/commands/test_remove.py +++ b/tests/console/commands/test_remove.py @@ -337,7 +337,7 @@ def test_remove_performs_uninstall_op( - Removing docker (4.3.1) -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected @@ -357,7 +357,7 @@ def test_remove_with_lock_does_not_perform_uninstall_op( Updating dependencies Resolving dependencies... -Writing lock file +Lock file written """ assert tester.io.fetch_output() == expected diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index e755a03e369..107868db43c 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,6 +418,53 @@ 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): + 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( config: Config, pool: RepositoryPool, @@ -439,8 +487,8 @@ def test_execute_works_with_ansi_output( "\x1b[39;1mPackage operations\x1b[39;22m: \x1b[34m1\x1b[39m install, \x1b[34m0\x1b[39m updates, \x1b[34m0\x1b[39m removals", "\x1b[34;1m-\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mcleo\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m1.0.0a5\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mPending...\x1b[39m", "\x1b[34;1m-\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mcleo\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m1.0.0a5\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mDownloading...\x1b[39m", - "\x1b[34;1m-\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mcleo\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m1.0.0a5\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mInstalling...\x1b[39m", - "\x1b[32;1m-\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mcleo\x1b[39m\x1b[39m (\x1b[39m\x1b[32m1.0.0a5\x1b[39m\x1b[39m)\x1b[39m", # finished + "\x1b[34;1m-\x1b[39;22m \x1b[39mInstalling \x1b[39m\x1b[36mcleo\x1b[39m\x1b[39m (\x1b[39m\x1b[39;1m1.0.0a5\x1b[39;22m\x1b[39m)\x1b[39m: \x1b[34mIn progress...\x1b[39m", + "\x1b[32;1m-\x1b[39;22m \x1b[39mInstalled \x1b[39m\x1b[36mcleo\x1b[39m\x1b[39m (\x1b[39m\x1b[32m1.0.0a5\x1b[39m\x1b[39m)\x1b[39m", # finished ] # fmt: on