Move getting buffer data into interface class

Put the code that instructs vim to write its buffer to a temporary file
and then reads that file into a python string into the VimInterface
class.  This will allow that to be done by code outside of tests.
This commit is contained in:
Aaron Schrab 2012-08-08 19:11:20 -04:00
parent fc22af0d1e
commit 2ab17b6cca

30
test.py
View File

@ -74,6 +74,21 @@ class VimInterface:
self.send(c) self.send(c)
time.sleep(sleeptime) time.sleep(sleeptime)
def get_buffer_data(self):
handle, fn = tempfile.mkstemp(prefix="UltiSnips_Test",suffix=".txt")
os.close(handle)
os.unlink(fn)
self.send(":w! %s\n" % fn)
# Read the output, chop the trailing newline
tries = 50
while tries:
if os.path.exists(fn):
return open(fn,"r").read()[:-1]
time.sleep(.05)
tries -= 1
class VimInterfaceScreen(VimInterface): class VimInterfaceScreen(VimInterface):
def __init__(self, session): def __init__(self, session):
self.session = session self.session = session
@ -266,20 +281,7 @@ class _VimTest(unittest.TestCase):
self._options_off() self._options_off()
handle, fn = tempfile.mkstemp(prefix="UltiSnips_Test",suffix=".txt") self.output = self.vim.get_buffer_data()
os.close(handle)
os.unlink(fn)
self.send(":w! %s\n" % fn)
# Read the output, chop the trailing newline
tries = 50
while tries:
if os.path.exists(fn):
self.output = open(fn,"r").read()[:-1]
break
time.sleep(.05)
tries -= 1
########################################################################### ###########################################################################
# BEGINNING OF TEST # # BEGINNING OF TEST #