I have inherited a program made by someone else which makes considerable effort to be "interactive", using the following kind of syntax:
x = input("What is the value of x")
There are dozens of input statements in nested if blocks. To start refactoring this program I need to set up some benchmarks which can cover the whole code and automatically input all combinations of user input.
What is a quick way to get the program to accept user input via a python script?
EDIT
I have tried the windows alternative to pexpect which seems to work OK.
import wexpect
child = wexpect.spawn('python input_script.py')
child.expect('input x')
child.sendline('5')
The test file input_script.py is as follows:
x = input('input x')
print('{} was your input'.format(x))
The caller script seems to run with an exit code of 0 so no errors. However I would like a way to see all the standard output, including the "sent lines". I have tried placing child.before and child.after but I cannot get the entire output to show.
sys.stdinandsys.stdout(andsys.stderrif necessary) withio.StringIOobjects before calling the inherited code.