prompt-toolkit / prompt-toolkit/python-prompt-toolkit

How to unit-test multi-line prompts

Open
#1,776 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

I'm using a mock PipeInput with .send_text to simulate user input. Recently, I've switched to multi-line inputs which can be terminated by either Meta+Enter or Esc then Enter. What string should I pass to .send_text to replicate that?

I've tried the ASCII code for Esc:

mock_input.send_text("First Reply\x1B\nSecond Reply\x1B\n")

But the program still hangs when prompt() is called

Fixture created like this:

@pytest.fixture
def mock_input():
    with create_pipe_input() as pipe_input:
        with create_app_session(input=pipe_input, output=DummyOutput()):
            yield pipe_input

Called like in this in code under test:

    msg = prompt("> ", multiline=True)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the create_pipe_input fixture and the send_text call shown in the issue, then trace how prompt(..., multiline=True) interprets termination input. Confirm the correct sequence for both Meta+Enter and Esc followed by Enter, and add or update a focused unit test demonstrating that prompt() returns instead of hanging.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.