prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 718 forks source link

rendering trouble... [including testcase to reproduce the issue] #600

Open markfink opened 6 years ago

markfink commented 6 years ago

@jonathanslenders prompt-toolkit gave me some headaches during testing (https://github.com/jonathanslenders/python-prompt-toolkit/issues/598, https://github.com/jonathanslenders/python-prompt-toolkit/issues/597) so I analysed and found out that indeed it is doing things differently (at least different to bash).

Both testcases use a virtual screen so we can "see" what is going on.

on most recent Arch Linux I get the following results with prompt-toolkit 2:

--------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------
Give me some input:                                                             #
Give me some input: my input...                                                 #
                                                                                #
...

simple_prompt.bash:

#!/bin/bash
printf 'Give me some input: '
read -r opt

simple_prompt.py:

from prompt_toolkit import prompt
answer = prompt('Give me some input: ')

testcases:

# -*- coding: utf-8 -*-
from pexpect import ANSI
import pexpect

from prompt_toolkit import Prompt
from prompt_toolkit.input.vt100 import PipeInput
from prompt_toolkit.output import DummyOutput

def test_simple_app_bash():
    child = pexpect.spawn('./tests/simple_prompt.bash')
    term = ANSI.ANSI()
    child.logfile_read = term

    child.expect('Give me some input: ')

    #child.echo = 1
    child.sendline ('my input...' + '\x0a')
    child.expect ('my input...')

    # get some output
    for c in term.w:
        print(u''.join(c) + '#')
    assert ''.join(term.w[0]).strip() == 'Give me some input: my input...'
    assert ''.join(term.w[1]).strip() == ''

def test_simple_app_python():
    child = pexpect.spawn('python tests/simple_prompt.py')
    term = ANSI.ANSI()
    child.logfile_read = term

    child.expect('Give me some input: ')

    #child.echo = 1
    child.sendline ('my input...' + '\x0a')
    child.expect ('my input...')

    for c in term.w:
        print(u''.join(c) + '#')
    assert False
    assert ''.join(term.w[0]).strip() == 'Give me some input: my input...'
    assert ''.join(term.w[1]).strip() == ''
decentral1se commented 5 years ago

Hi there,

From your example, it looks like test_simple_app_bash is failing?

Also, your python test contains an assert False which is confusing.