Skip to content

Commit 7399df1

Browse files
committed
Address PR comments
1 parent cce5450 commit 7399df1

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

awscli/customizations/ecs/expressgateway/display_strategy.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import time
1818

1919
from botocore.exceptions import ClientError
20+
from colorama import Style
2021

2122
from awscli.customizations.ecs.exceptions import MonitoringError
2223
from awscli.customizations.ecs.expressgateway.stream_display import (
@@ -63,13 +64,16 @@ def __init__(self, display, use_color):
6364

6465
def execute_monitoring(self, collector, start_time, timeout_minutes):
6566
"""Execute async monitoring with spinner and keyboard controls."""
66-
final_output, timed_out = asyncio.run(
67-
self._execute_async(collector, start_time, timeout_minutes)
68-
)
69-
if timed_out:
70-
uni_print(final_output + "\nMonitoring timed out!\n")
71-
else:
72-
uni_print(final_output + "\nMonitoring Complete!\n")
67+
try:
68+
final_output, timed_out = asyncio.run(
69+
self._execute_async(collector, start_time, timeout_minutes)
70+
)
71+
if timed_out:
72+
uni_print(final_output + "\nMonitoring timed out!\n")
73+
else:
74+
uni_print(final_output + "\nMonitoring Complete!\n")
75+
finally:
76+
uni_print(Style.RESET_ALL)
7377

7478
async def _execute_async(self, collector, start_time, timeout_minutes):
7579
"""Async execution with dual tasks for data and spinner."""
@@ -233,3 +237,4 @@ def execute_monitoring(self, collector, start_time, timeout_minutes):
233237
self.stream_display.show_error_message(e)
234238
finally:
235239
self.stream_display.show_completion_message()
240+
uni_print(Style.RESET_ALL)

awscli/customizations/ecs/monitorexpressgatewayservice.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
from awscli.customizations.ecs.prompt_toolkit_display import Display
5858
from awscli.customizations.ecs.serviceviewcollector import ServiceViewCollector
5959
from awscli.customizations.utils import uni_print
60-
from awscli.utils import write_exception
6160

6261

6362
class ECSMonitorExpressGatewayService(BasicCommand):
@@ -79,7 +78,7 @@ class ECSMonitorExpressGatewayService(BasicCommand):
7978
"Choose ``--mode INTERACTIVE`` for real-time display with keyboard navigation (requires TTY), "
8079
"or ``--mode TEXT-ONLY`` for text output with timestamps (works without TTY). "
8180
"The monitoring session continues until manually stopped by the user or the specified timeout is reached. "
82-
"In interactive mode, use keyboard shortcuts: up/down to scroll through resources, 'q' to quit. "
81+
"In INTERACTIVE mode, use keyboard shortcuts: up/down to scroll through resources, 'q' to quit. "
8382
"In TEXT-ONLY mode, press Ctrl+C to stop monitoring."
8483
)
8584

@@ -147,7 +146,7 @@ def _run_main(self, parsed_args, parsed_globals):
147146
try:
148147
display_mode = self._determine_display_mode(parsed_args.mode)
149148
except ValueError as e:
150-
write_exception(e, sys.stderr)
149+
uni_print(f"aws: [ERROR]: {str(e)}", sys.stderr)
151150
return 1
152151

153152
try:
@@ -194,7 +193,7 @@ def _determine_display_mode(self, requested_mode):
194193
if requested_mode == 'INTERACTIVE':
195194
if not sys.stdout.isatty():
196195
raise ValueError(
197-
"Error: Interactive mode requires a TTY (terminal). "
196+
"Interactive mode requires a TTY (terminal). "
198197
"Use --mode TEXT-ONLY for non-interactive environments."
199198
)
200199
return 'INTERACTIVE'

tests/functional/ecs/test_monitorexpressgatewayservice.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ def command(mock_session, mock_watcher_class):
4040
def mock_client(mock_session):
4141
"""Fixture that provides a mock ECS client."""
4242
client = Mock()
43-
mock_session.create_client.return_value = client
4443
return client
4544

4645

4746
class TestECSMonitorExpressGatewayService:
48-
def test_init(self, command, mock_session, mock_watcher_class):
47+
def test_init(self, command):
4948
assert command.name == 'monitor-express-gateway-service'
5049
assert command.DESCRIPTION.startswith('Monitors the progress')
5150

@@ -70,6 +69,7 @@ def test_add_arguments(self, command):
7069
def test_run_main_with_text_only_mode(
7170
self, mock_isatty, command, mock_watcher_class, mock_client
7271
):
72+
command._session.create_client.return_value = mock_client
7373
mock_watcher = Mock()
7474
mock_watcher_class.return_value = mock_watcher
7575

@@ -105,6 +105,7 @@ def test_run_main_with_text_only_mode(
105105
def test_run_main_with_interactive_mode(
106106
self, mock_isatty, command, mock_watcher_class, mock_client
107107
):
108+
command._session.create_client.return_value = mock_client
108109
mock_watcher = Mock()
109110
mock_watcher_class.return_value = mock_watcher
110111

@@ -137,6 +138,7 @@ def test_run_main_with_interactive_mode(
137138
def test_run_main_auto_mode_with_tty(
138139
self, mock_isatty, command, mock_watcher_class, mock_client
139140
):
141+
command._session.create_client.return_value = mock_client
140142
mock_watcher = Mock()
141143
mock_watcher_class.return_value = mock_watcher
142144

@@ -163,6 +165,7 @@ def test_run_main_auto_mode_with_tty(
163165
def test_run_main_auto_mode_without_tty(
164166
self, mock_isatty, command, mock_watcher_class, mock_client
165167
):
168+
command._session.create_client.return_value = mock_client
166169
mock_watcher = Mock()
167170
mock_watcher_class.return_value = mock_watcher
168171

@@ -189,6 +192,7 @@ def test_run_main_auto_mode_without_tty(
189192
def test_run_main_with_color_on(
190193
self, mock_isatty, command, mock_watcher_class, mock_client
191194
):
195+
command._session.create_client.return_value = mock_client
192196
mock_watcher = Mock()
193197
mock_watcher_class.return_value = mock_watcher
194198

@@ -220,6 +224,7 @@ def test_run_main_creates_ecs_client(
220224
mock_watcher_class,
221225
mock_client,
222226
):
227+
command._session.create_client.return_value = mock_client
223228
mock_watcher = Mock()
224229
mock_watcher_class.return_value = mock_watcher
225230

@@ -254,6 +259,7 @@ def test_run_main_creates_ecs_client(
254259
def test_run_main_with_default_resource_view(
255260
self, mock_isatty, command, mock_watcher_class, mock_client
256261
):
262+
command._session.create_client.return_value = mock_client
257263
mock_watcher = Mock()
258264
mock_watcher_class.return_value = mock_watcher
259265

tests/unit/customizations/ecs/test_monitorexpressgatewayservice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_interactive_mode_requires_tty(self, mock_isatty, capsys):
104104

105105
captured = capsys.readouterr()
106106
assert "Interactive mode requires a TTY" in captured.err
107+
assert "aws: [ERROR]:" in captured.err
107108
assert result == 1
108109

109110
@patch('sys.stdout.isatty')

tests/unit/customizations/ecs/test_prompt_toolkit_display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestPromptToolkitDisplay:
1313
@pytest.fixture
1414
def display(self):
1515
with create_app_session(output=DummyOutput()):
16-
return Display()
16+
yield Display()
1717

1818
def test_init(self, display):
1919
"""Test Display initialization."""

0 commit comments

Comments
 (0)