Skip to content

Commit 55ebab5

Browse files
committed
Fix start-live-tail tests
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.
1 parent e54b5ff commit 55ebab5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

awscli/customizations/logs/startlivetail.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ def __init__(
620620
log_events,
621621
session_metadata: LiveTailSessionMetadata,
622622
app_output=None,
623+
app_input=None,
623624
) -> None:
624625
self._log_events = log_events
625626
self._session_metadata = session_metadata
@@ -633,9 +634,9 @@ def __init__(
633634
self._session_metadata,
634635
self._keywords_to_highlight,
635636
)
636-
self._create_ui(app_output)
637+
self._create_ui(app_output, app_input)
637638

638-
def _create_ui(self, app_output):
639+
def _create_ui(self, app_output, app_input):
639640
prompt_buffer = Buffer()
640641
self._prompt_buffer_control = BufferControl(prompt_buffer)
641642
prompt_buffer_window = Window(self._prompt_buffer_control)
@@ -677,6 +678,7 @@ def _create_ui(self, app_output):
677678
key_bindings=self._key_bindings,
678679
refresh_interval=1,
679680
output=app_output,
681+
input=app_input,
680682
)
681683

682684
@property

tests/unit/customizations/logs/test_startlivetail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from prompt_toolkit.buffer import Buffer
1818
from prompt_toolkit.key_binding import KeyPressEvent
1919
from prompt_toolkit.output import DummyOutput
20+
from prompt_toolkit.input import create_pipe_input
2021

2122
from awscli.compat import StringIO
2223
from awscli.customizations.logs.startlivetail import (
@@ -607,7 +608,8 @@ def setUp(self) -> None:
607608
self.log_events = []
608609
self.session_metadata = LiveTailSessionMetadata()
609610
self.ui = InteractiveUI(
610-
self.log_events, self.session_metadata, app_output=DummyOutput()
611+
self.log_events, self.session_metadata, app_output=DummyOutput(),
612+
app_input=create_pipe_input()
611613
)
612614

613615
def test_update_toolbar(self):

0 commit comments

Comments
 (0)