From e678480a2a8588979d7aef3bf02f1100a42c6d5c Mon Sep 17 00:00:00 2001 From: Kenneth Daily Date: Thu, 20 Nov 2025 15:41:01 -0800 Subject: [PATCH] Fix start-live-tail tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix addresses failures encountered on some systems when running the startlivetail unit tests through the AWS CLI test runner script at `scripts/ci/run-tests`. According to prompt toolkit documentation: > During the creation of a prompt_toolkit Application, we can specify > what input and output device to be used. By default, these are output > objects that correspond with sys.stdin and sys.stdout. In unit tests > however, we want to replace these. > - For the input, we want a “pipe input”. This is an input device, > in which we can programmatically send some input. It can be created > with create_pipe_input(), and that return either a PosixPipeInput or a > Win32PipeInput depending on the platform. Reference: https://python-prompt-toolkit.readthedocs.io/en/stable/pages/advanced_topics/unit_testing.html This change adds an optional `app_input`` parameter so that the test can be run with `create_pipe_input()` to replace the input for unit testing. --- awscli/customizations/logs/startlivetail.py | 6 ++++-- tests/unit/customizations/logs/test_startlivetail.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/awscli/customizations/logs/startlivetail.py b/awscli/customizations/logs/startlivetail.py index 53cc3789c9c5..0e99bbebb855 100644 --- a/awscli/customizations/logs/startlivetail.py +++ b/awscli/customizations/logs/startlivetail.py @@ -620,6 +620,7 @@ def __init__( log_events, session_metadata: LiveTailSessionMetadata, app_output=None, + app_input=None, ) -> None: self._log_events = log_events self._session_metadata = session_metadata @@ -633,9 +634,9 @@ def __init__( self._session_metadata, self._keywords_to_highlight, ) - self._create_ui(app_output) + self._create_ui(app_output, app_input) - def _create_ui(self, app_output): + def _create_ui(self, app_output, app_input): prompt_buffer = Buffer() self._prompt_buffer_control = BufferControl(prompt_buffer) prompt_buffer_window = Window(self._prompt_buffer_control) @@ -677,6 +678,7 @@ def _create_ui(self, app_output): key_bindings=self._key_bindings, refresh_interval=1, output=app_output, + input=app_input, ) @property diff --git a/tests/unit/customizations/logs/test_startlivetail.py b/tests/unit/customizations/logs/test_startlivetail.py index be9aadad9a08..6ff407eb2055 100644 --- a/tests/unit/customizations/logs/test_startlivetail.py +++ b/tests/unit/customizations/logs/test_startlivetail.py @@ -17,6 +17,7 @@ from prompt_toolkit.buffer import Buffer from prompt_toolkit.key_binding import KeyPressEvent from prompt_toolkit.output import DummyOutput +from prompt_toolkit.input import create_pipe_input from awscli.compat import StringIO from awscli.customizations.logs.startlivetail import ( @@ -607,7 +608,8 @@ def setUp(self) -> None: self.log_events = [] self.session_metadata = LiveTailSessionMetadata() self.ui = InteractiveUI( - self.log_events, self.session_metadata, app_output=DummyOutput() + self.log_events, self.session_metadata, app_output=DummyOutput(), + app_input=create_pipe_input() ) def test_update_toolbar(self):