From a5856d2b304db37eda3d8062883518fc16692d78 Mon Sep 17 00:00:00 2001 From: Ian Woodard <17186604+IanWoodard@users.noreply.github.com> Date: Mon, 28 Apr 2025 15:13:17 -0700 Subject: [PATCH] fix(toggle): Fixing toggle formatting with enums --- devservices/commands/toggle.py | 12 +++++++----- tests/commands/test_toggle.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/devservices/commands/toggle.py b/devservices/commands/toggle.py index 27d6d5cf..11934ebc 100644 --- a/devservices/commands/toggle.py +++ b/devservices/commands/toggle.py @@ -40,7 +40,7 @@ def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None: parser.add_argument( "runtime", help="Runtime to use for the service", - choices=[ServiceRuntime.CONTAINERIZED, ServiceRuntime.LOCAL], + choices=[runtime.value for runtime in ServiceRuntime], nargs="?", default=None, ) @@ -74,7 +74,7 @@ def toggle(args: Namespace) -> None: desired_runtime = get_opposite_runtime(current_runtime) if current_runtime == desired_runtime: console.warning( - f"{service.name} is already running in {desired_runtime} runtime" + f"{service.name} is already running in {desired_runtime.value} runtime" ) return if desired_runtime == ServiceRuntime.LOCAL: @@ -89,7 +89,9 @@ def toggle(args: Namespace) -> None: final_runtime = state.get_service_runtime(service.name) if final_runtime == desired_runtime: - console.success(f"{service.name} is now running in {desired_runtime} runtime") + console.success( + f"{service.name} is now running in {desired_runtime.value} runtime" + ) def handle_transition_to_local_runtime(service_to_transition: Service) -> None: @@ -105,7 +107,7 @@ def handle_transition_to_local_runtime(service_to_transition: Service) -> None: if service_to_transition.name in active_services: state.update_service_runtime(service_to_transition.name, ServiceRuntime.LOCAL) console.success( - f"{service_to_transition.name} is now running in {ServiceRuntime.LOCAL} runtime" + f"{service_to_transition.name} is now running in {ServiceRuntime.LOCAL.value} runtime" ) return @@ -196,7 +198,7 @@ def restart_dependent_services( console = Console() with Status( on_start=lambda: console.warning( - f"Restarting dependent services to ensure {service_name} is running in a {ServiceRuntime.CONTAINERIZED} runtime" + f"Restarting dependent services to ensure {service_name} is running in a {ServiceRuntime.CONTAINERIZED.value} runtime" ), ) as status: for dependent_service in dependent_services: diff --git a/tests/commands/test_toggle.py b/tests/commands/test_toggle.py index 6758e927..daef602c 100644 --- a/tests/commands/test_toggle.py +++ b/tests/commands/test_toggle.py @@ -125,7 +125,7 @@ def test_toggle_nothing_running( captured = capsys.readouterr() assert ( - f"example-service is now running in {ServiceRuntime.LOCAL} runtime" + f"example-service is now running in {ServiceRuntime.LOCAL.value} runtime" in captured.out.strip() ) @@ -144,7 +144,7 @@ def test_toggle_nothing_running( captured = capsys.readouterr() assert ( - f"example-service is now running in {ServiceRuntime.CONTAINERIZED} runtime" + f"example-service is now running in {ServiceRuntime.CONTAINERIZED.value} runtime" in captured.out.strip() ) @@ -197,7 +197,7 @@ def test_toggle_nothing_running_same_runtime( captured = capsys.readouterr() assert ( - f"example-service is already running in {ServiceRuntime.CONTAINERIZED} runtime" + f"example-service is already running in {ServiceRuntime.CONTAINERIZED.value} runtime" in captured.out.strip() ) @@ -518,7 +518,7 @@ def test_handle_transition_to_local_runtime_currently_running_standalone( captured = capsys.readouterr() assert ( - f"example-service is now running in {ServiceRuntime.LOCAL} runtime" + f"example-service is now running in {ServiceRuntime.LOCAL.value} runtime" in captured.out.strip() ) @@ -920,7 +920,7 @@ def test_restart_dependent_services_single_dependent_service_single_mode( captured = capsys.readouterr() assert ( - f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED} runtime" + f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED.value} runtime" in captured.out.strip() ) assert "Restarting dependent-service in mode default" in captured.out.strip() @@ -958,7 +958,7 @@ def test_restart_dependent_services_single_dependent_service_multiple_modes( captured = capsys.readouterr() assert ( - f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED} runtime" + f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED.value} runtime" in captured.out.strip() ) assert "Restarting dependent-service in mode default" in captured.out.strip() @@ -998,7 +998,7 @@ def test_restart_dependent_services_multiple_dependent_services_single_mode( captured = capsys.readouterr() assert ( - f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED} runtime" + f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED.value} runtime" in captured.out.strip() ) assert "Restarting dependent-service in mode default" in captured.out.strip() @@ -1055,7 +1055,7 @@ def test_restart_dependent_services_multiple_dependent_services_multiple_modes( captured = capsys.readouterr() assert ( - f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED} runtime" + f"Restarting dependent services to ensure example-service is running in a {ServiceRuntime.CONTAINERIZED.value} runtime" in captured.out.strip() ) assert "Restarting dependent-service in mode default" in captured.out.strip()