Skip to content

Commit 200be00

Browse files
committed
Skip problematic test on Windows
Also: - Move where pre_prompt is defined so it is near other hook methods - Document pre_prompt hook in Hooks feature docuemntation
1 parent 0d9137d commit 200be00

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

cmd2/cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,6 +2668,9 @@ def _raise_keyboard_interrupt(self) -> None:
26682668
self.poutput() # Ensure new prompt is on a line by itself
26692669
raise KeyboardInterrupt("Got a keyboard interrupt")
26702670

2671+
def pre_prompt(self) -> None:
2672+
"""Ran just before the prompt is displayed (and after the event loop has started)."""
2673+
26712674
def precmd(self, statement: Statement | str) -> Statement:
26722675
"""Ran just before the command is executed by [cmd2.Cmd.onecmd][] and after adding it to history (cmd Hook method).
26732676
@@ -3285,9 +3288,6 @@ def completedefault(self, *_ignored: list[str]) -> list[str]:
32853288
def _suggest_similar_command(self, command: str) -> str | None:
32863289
return suggest_similar(command, self.get_visible_commands())
32873290

3288-
def pre_prompt(self) -> None:
3289-
"""Call this before the prompt is displayed (and after the event loop has started)."""
3290-
32913291
def read_input(
32923292
self,
32933293
prompt: str = '',

docs/features/hooks.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ loop behavior:
8383
When you call [cmd2.Cmd.cmdloop][], the following sequence of events are repeated until the
8484
application exits:
8585

86+
1. Start the `prompt-toolkit` event loop
87+
1. Call [cmd2.Cmd.pre_prompt][] for any behavior that should happen after event loop starts but
88+
before prompt is displayed
8689
1. Output the prompt
8790
1. Accept user input
8891
1. Parse user input into a [cmd2.Statement][] object

tests/test_cmd2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,6 +3571,10 @@ def test_read_input_dynamic_prompt_with_history(base_app, monkeypatch):
35713571
assert result.value == ANSI(base_app.prompt).value
35723572

35733573

3574+
@pytest.mark.skipif(
3575+
sys.platform.startswith('win'),
3576+
reason="Don't have a real Windows console with how we are currently running tests in GitHub Actions",
3577+
)
35743578
def test_pre_prompt_running_loop(base_app):
35753579
# Test that pre_prompt runs with a running event loop.
35763580
import asyncio

0 commit comments

Comments
 (0)