python - How can I feed keys in to a terminal for unittesting purposes -
i'm working on plug-in vim, , i'd test behaves correctly, under start-up, when users edit files e.t.c.
to this, i'd start terminal, , feed keys in it. i'm thinking of doing python script. there way this?
in pseudo-python might this:
#start terminal. here konsole konsole = os.system('konsole --width=200 --height=150') #start vim in terminal konsole.feed_keys("vim\n") #run vim function tested konsole.feed_keys(":let my_list = myvimfunction()\n") #save return value file system konsole.feed_keys(":writefile(my_list, '/tmp/result')\n") #load result python open('/tmp/result', 'r') myfile: data = myfile.read() #validate result assertequal('expect result', data)
i think should verify core functionality of plugin inside vim, using unit tests. there's wide variety of vim plugins, provide additional mappings or commands, invoked user, , leave behind side effects in buffer, or output, or opened windows. can verified inside vim. there various approaches that, mine runvimtests test framework; plugin page has links several alternatives.
with core functionality covered, there's little left test "interactively". (i mean stuff forgotten debug output, long execution times, display mess-ups.) since you're heavy user of vim , plugin yourself, covers it.
of course, if plugin embeds tightly vim (like "ide xxx"; though frowned upon), may consider external test driver. maybe others contribute pointers general-purpose, terminal-driven test frameworks. i'm sure such exist.
Comments
Post a Comment