How can I feed keys in to a terminal for unittesting purposes
<p>I'm working on a plug-in for Vim, and I'd like to test that it behaves correctly, under start-up, when users edit files e.t.c.</p>

<p>To do this, I'd like to start a terminal, and feed keys in to it.
I'm thinking of doing it all from a python script. Is there a way to do this?</p>

<p>In pseudo-python it might look something like this:</p>

<pre><code>#start a terminal. Here konsole
konsole = os.system('konsole --width=200 --height=150')

#start vim in that terminal
konsole.feed_keys("vim\n")
#run the vim function to be tested
konsole.feed_keys(":let my_list = MyVimFunction()\n")
#save the return value to the file system
konsole.feed_keys(":writefile(my_list, '/tmp/result')\n")

#load result into python
with open('/tmp/result', 'r') as myfile:
    data = myfile.read()

#validate the result
assertEqual('expect result', data)
</code></pre>