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() == ''
@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:
simple_prompt.bash:
simple_prompt.py:
testcases: